| | 1 | | // Copyright (c) ZeroC, Inc. |
| | 2 | |
|
| | 3 | | using System.Buffers; |
| | 4 | |
|
| | 5 | | namespace IceRpc; |
| | 6 | |
|
| | 7 | | /// <summary>Represents the value of a field that is about to be sent. It's a kind of discriminated union: only one |
| | 8 | | /// of the struct's properties can be set.</summary> |
| | 9 | | public readonly record struct OutgoingFieldValue |
| | 10 | | { |
| | 11 | | /// <summary>Gets the value of this outgoing field.</summary> |
| | 12 | | /// <value>The value of this outgoing field. Defaults to an empty byte sequence.</value> |
| | 13 | | /// <remarks><see cref="ByteSequence" /> is set when the outgoing field value is constructed with <see |
| | 14 | | /// cref="OutgoingFieldValue(ReadOnlySequence{byte})" />.</remarks> |
| 22 | 15 | | public ReadOnlySequence<byte> ByteSequence { get; } |
| | 16 | |
|
| | 17 | | /// <summary>Gets the action used to write the field value. This action is executed when the fields are sent. |
| | 18 | | /// </summary> |
| | 19 | | /// <value>The write action of this outgoing field. Defaults to <see langword="null"/>.</value> |
| 36 | 20 | | public Action<IBufferWriter<byte>>? WriteAction { get; } |
| | 21 | |
|
| | 22 | | /// <summary>Constructs an outgoing field value that holds a byte sequence.</summary> |
| | 23 | | /// <param name="byteSequence">The field encoded value.</param> |
| | 24 | | public OutgoingFieldValue(ReadOnlySequence<byte> byteSequence) |
| 13 | 25 | | { |
| 13 | 26 | | ByteSequence = byteSequence; |
| 13 | 27 | | WriteAction = null; |
| 13 | 28 | | } |
| | 29 | |
|
| | 30 | | /// <summary>Constructs an outgoing field value that holds a write action.</summary> |
| | 31 | | /// <param name="writeAction">The action that writes the field value.</param> |
| | 32 | | public OutgoingFieldValue(Action<IBufferWriter<byte>> writeAction) |
| 28 | 33 | | { |
| 28 | 34 | | ByteSequence = default; |
| 28 | 35 | | WriteAction = writeAction; |
| 28 | 36 | | } |
| | 37 | | } |