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
pipeWriterPipeWriterThe 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 ReturnWriter(ref MessagePackWriter) before discarding the writer.
Flush()
Ensures everything previously written has been flushed to the underlying IBufferWriter<T>.
public void Flush()
FlushIfAppropriateAsync(SerializationContext)
Flushes the pipe if the buffer is getting full.
public ValueTask FlushIfAppropriateAsync(SerializationContext context)
Parameters
contextSerializationContextThe serialization context.
Returns
- ValueTask
A task to await before writing further.
IsTimeToFlush(in SerializationContext)
Gets a value indicating whether it is time to flush the pipe.
public bool IsTimeToFlush(in SerializationContext context)
Parameters
contextSerializationContextThe serialization context.
Returns
IsTimeToFlush(in SerializationContext, in MessagePackWriter)
Gets a value indicating whether it is time to flush the pipe.
public bool IsTimeToFlush(in SerializationContext context, in MessagePackWriter syncWriter)
Parameters
contextSerializationContextThe serialization context.
syncWriterMessagePackWriterThe synchronous writer that may have unflushed bytes to consider as well.
Returns
ReturnWriter(ref MessagePackWriter)
Applies the bytes written with a writer previously obtained from CreateWriter() back to this object.
public void ReturnWriter(ref MessagePackWriter writer)
Parameters
writerMessagePackWriterThe writer to return. It should not be used after this.
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
countintThe 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
countuintThe 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
countintThe 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
countuintThe number of key=value pairs that will be written in the map.
WriteNil()
Writes a Nil value.
public void WriteNil()
WriteRaw(ReadOnlySequence<byte>)
Copies msgpack bytes directly into the message pack writer.
public void WriteRaw(ReadOnlySequence<byte> bytes)
Parameters
bytesReadOnlySequence<byte>
Remarks
This method is for copy valid msgpack structures directly to the output buffer. Arbitrary binary blobs may only be written using this method directly following a call to WriteBinHeader(int). Otherwise use Write(scoped ReadOnlySpan<byte>) to write arbitrary binary blobs.
WriteRaw(ReadOnlySpan<byte>)
Copies msgpack bytes directly into the message pack writer.
public void WriteRaw(ReadOnlySpan<byte> bytes)
Parameters
bytesReadOnlySpan<byte>
Remarks
This method is for copy valid msgpack structures directly to the output buffer. Arbitrary binary blobs may only be written using this method directly following a call to WriteBinHeader(int). Otherwise use Write(scoped ReadOnlySpan<byte>) to write arbitrary binary blobs.
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
writerMessagePackAsyncWriter.SyncWriter<TState>The delegate to invoke to do the synchronous writing.
stateTStateState to pass to the writer.
Type Parameters
TStateThe type of state that may be given to the writer.