Class MessagePackAsyncWriter
- Namespace
- Nerdbank.MessagePack
- Assembly
- Nerdbank.MessagePack.dll
A primitive types writer for the MessagePack format that writes to a PipeWriter.
public class MessagePackAsyncWriter
- Inheritance
-
MessagePackAsyncWriter
- Inherited Members
Remarks
This is an async capable and slower alternative to MessagePackWriter with fewer methods, making the sync version more generally useful. It is useful when implementing the async virtual methods on MessagePackConverter<T>.
The MessagePack spec..Constructors
MessagePackAsyncWriter(PipeWriter)
A primitive types writer for the MessagePack format that writes to a PipeWriter.
public MessagePackAsyncWriter(PipeWriter pipeWriter)
Parameters
pipeWriter
PipeWriterThe pipe writer to encode to.
Remarks
This is an async capable and slower alternative to MessagePackWriter with fewer methods, making the sync version more generally useful. It is useful when implementing the async virtual methods on MessagePackConverter<T>.
The MessagePack spec..Methods
CreateWriter()
Gets the fully-capable, synchronous writer.
public MessagePackWriter CreateWriter()
Returns
- MessagePackWriter
The writer.
Remarks
The caller must take care to call Flush() before discarding the writer.
Flush()
Ensures everything previously written has been flushed to the underlying IBufferWriter<T>.
public void Flush()
FlushIfAppropriateAsync(SerializationContext, CancellationToken)
Flushes the pipe if the buffer is getting full.
public ValueTask FlushIfAppropriateAsync(SerializationContext context, CancellationToken cancellationToken)
Parameters
context
SerializationContextThe serialization context.
cancellationToken
CancellationTokenA cancellation token.
Returns
- ValueTask
A task to await before writing further.
IsTimeToFlush(SerializationContext)
Gets a value indicating whether it is time to flush the pipe.
public bool IsTimeToFlush(SerializationContext context)
Parameters
context
SerializationContextThe serialization context.
Returns
IsTimeToFlush(SerializationContext, in MessagePackWriter)
Gets a value indicating whether it is time to flush the pipe.
public bool IsTimeToFlush(SerializationContext context, in MessagePackWriter syncWriter)
Parameters
context
SerializationContextThe serialization context.
syncWriter
MessagePackWriterThe synchronous writer that may have unflushed bytes to consider as well.
Returns
WriteArrayHeader(int)
Write the length of the next array to be written in the most compact form of MinFixArray, Array16, or Array32.
public void WriteArrayHeader(int count)
Parameters
count
intThe number of elements that will be written in the array.
WriteArrayHeader(uint)
Write the length of the next array to be written in the most compact form of MinFixArray, Array16, or Array32.
public void WriteArrayHeader(uint count)
Parameters
count
uintThe number of elements that will be written in the array.
WriteMapHeader(int)
Write the length of the next map to be written in the most compact form of MinFixMap, Map16, or Map32.
public void WriteMapHeader(int count)
Parameters
count
intThe number of key=value pairs that will be written in the map.
WriteMapHeader(uint)
Write the length of the next map to be written in the most compact form of MinFixMap, Map16, or Map32.
public void WriteMapHeader(uint count)
Parameters
count
uintThe number of key=value pairs that will be written in the map.
WriteNil()
Writes a Nil value.
public void WriteNil()
WriteRaw(ReadOnlySequence<byte>)
Copies bytes directly into the message pack writer.
public void WriteRaw(ReadOnlySequence<byte> bytes)
Parameters
bytes
ReadOnlySequence<byte>
WriteRaw(ReadOnlySpan<byte>)
Copies bytes directly into the message pack writer.
public void WriteRaw(ReadOnlySpan<byte> bytes)
Parameters
bytes
ReadOnlySpan<byte>
Write<TState>(SyncWriter<TState>, TState)
Creates a sync writer for purposes of serializing a message.
public void Write<TState>(MessagePackAsyncWriter.SyncWriter<TState> writer, TState state)
Parameters
writer
MessagePackAsyncWriter.SyncWriter<TState>The delegate to invoke to do the synchronous writing.
state
TStateState to pass to the writer.
Type Parameters
TState
The type of state that may be given to the writer.