| | 1 | | // Copyright (c) ZeroC, Inc. |
| | 2 | |
|
| | 3 | | using System.Buffers; |
| | 4 | | using System.IO.Pipelines; |
| | 5 | |
|
| | 6 | | namespace IceRpc.Protobuf; |
| | 7 | |
|
| | 8 | | /// <summary>Represents a property bag used to configure the encoding of payloads.</summary> |
| | 9 | | public sealed class ProtobufEncodeOptions |
| | 10 | | { |
| | 11 | | /// <summary>Gets the default instance of <see cref="ProtobufEncodeOptions" />.</summary> |
| 57 | 12 | | public static ProtobufEncodeOptions Default { get; } = new(); |
| | 13 | |
|
| | 14 | | /// <summary>Gets the pipe options that the IceRPC + Protobuf uses when creating pipes. The IceRPC + Protobuf |
| | 15 | | /// integration creates a pipe when encoding a request or response payload, and when encoding an async enumerable |
| | 16 | | /// into a <see cref="PipeReader" />.</summary> |
| 56 | 17 | | public PipeOptions PipeOptions { get; } |
| | 18 | |
|
| | 19 | | /// <summary>Gets the stream flush threshold. When encoding a Protobuf stream (async enumerable), the |
| | 20 | | /// IceRpc + Protobuf encodes the values provided by the source async enumerable into a pipe writer. The |
| | 21 | | /// IceRpc + Protobuf integration flushes this pipe writer when no new value is available synchronously, or when |
| | 22 | | /// it has written StreamFlushThreshold bytes to this pipe writer.</summary> |
| 26 | 23 | | public int StreamFlushThreshold { get; } |
| | 24 | |
|
| | 25 | | /// <summary>Constructs a new instance.</summary> |
| | 26 | | /// <param name="pool">The pool parameter for the constructor of <see cref="System.IO.Pipelines.PipeOptions" />. |
| | 27 | | /// </param> |
| | 28 | | /// <param name="minimumSegmentSize">The minimum segment size for the constructor of |
| | 29 | | /// <see cref="System.IO.Pipelines.PipeOptions" />.</param> |
| | 30 | | /// <param name="streamFlushThreshold">The value of <see cref="StreamFlushThreshold" />. The default value (-1) is |
| | 31 | | /// equivalent to 16 KB.</param> |
| 1 | 32 | | public ProtobufEncodeOptions( |
| 1 | 33 | | MemoryPool<byte>? pool = default, |
| 1 | 34 | | int minimumSegmentSize = -1, |
| 1 | 35 | | int streamFlushThreshold = -1) |
| 1 | 36 | | { |
| | 37 | | // We keep the default readerScheduler (ThreadPool) because pipes created from these PipeOptions are never |
| | 38 | | // ReadAsync concurrently with a FlushAsync/Complete on the pipe writer. The writerScheduler does not matter |
| | 39 | | // since FlushAsync never blocks. |
| 1 | 40 | | PipeOptions = new( |
| 1 | 41 | | pool: pool, |
| 1 | 42 | | minimumSegmentSize: minimumSegmentSize, |
| 1 | 43 | | pauseWriterThreshold: 0, |
| 1 | 44 | | useSynchronizationContext: false); |
| 1 | 45 | | StreamFlushThreshold = streamFlushThreshold == -1 ? 16 * 1024 : streamFlushThreshold; |
| 1 | 46 | | } |
| | 47 | | } |