Table of Contents

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 PipeWriter

The 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 SerializationContext

The serialization context.

cancellationToken CancellationToken

A 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 SerializationContext

The serialization context.

Returns

bool

true if the pipe buffers are reaching their preferred capacity; false otherwise.

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 SerializationContext

The serialization context.

syncWriter MessagePackWriter

The synchronous writer that may have unflushed bytes to consider as well.

Returns

bool

true if the pipe buffers are reaching their preferred capacity; false otherwise.

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 int

The 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 uint

The 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 int

The 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 uint

The 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 TState

State to pass to the writer.

Type Parameters

TState

The type of state that may be given to the writer.