Table of Contents

Struct MsgPackEncoder

Namespace
ShapeShift.MsgPack
Assembly
ShapeShift.MsgPack.dll

Writes MessagePack tokens to an IBufferWriter<T>.

public ref struct MsgPackEncoder : IEncoder
Implements
Inherited Members

Constructors

MsgPackEncoder(IBufferWriter<byte>)

Writes MessagePack tokens to an IBufferWriter<T>.

public MsgPackEncoder(IBufferWriter<byte> output)

Parameters

output IBufferWriter<byte>

The destination buffer.

Properties

Output

Gets the destination buffer.

public IBufferWriter<byte> Output { get; }

Property Value

IBufferWriter<byte>

Methods

WriteArrayHeader(int)

Writes a MessagePack array header, after which exactly count values must be written.

public void WriteArrayHeader(int count)

Parameters

count int

The number of elements the array will contain.

Remarks

This is a low-level building block for custom converters that need to emit a MessagePack structure the format-neutral IEncoder members do not describe.

WriteEndMap()

Writes the end of the innermost open map.

public void WriteEndMap()

WriteEndVector()

Writes the end of the innermost open vector.

public void WriteEndVector()

WriteExtension(sbyte, scoped ReadOnlySpan<byte>)

Writes a MessagePack extension value, choosing the most compact of the fixext, ext8, ext16, and ext32 forms.

public void WriteExtension(sbyte typeCode, scoped ReadOnlySpan<byte> payload)

Parameters

typeCode sbyte

The extension type code. Codes 0-127 are application specific; negative codes are reserved by the MessagePack specification. See MsgPackExtensionCodes for the codes ShapeShift itself reserves, which custom converters should avoid.

payload ReadOnlySpan<byte>

The extension's payload.

WriteMapHeader(int)

Writes a MessagePack map header, after which exactly count key/value pairs must be written.

public void WriteMapHeader(int count)

Parameters

count int

The number of entries the map will contain.

Remarks

This is a low-level building block for custom converters that need to emit a MessagePack structure the format-neutral IEncoder members do not describe.

WriteNull()

Writes an explicit null.

public void WriteNull()

WritePropertyName(scoped ReadOnlySpan<char>)

Writes the name of the map entry whose value comes next.

public void WritePropertyName(scoped ReadOnlySpan<char> name)

Parameters

name ReadOnlySpan<char>

The property name.

Remarks

Valid only directly inside a map. Many formats encode a key differently from a string value, so this is a distinct operation rather than a call to WriteValue(scoped ReadOnlySpan<char>).

WriteRaw(scoped ReadOnlySpan<byte>)

Copies already-encoded MessagePack bytes to the output verbatim.

public void WriteRaw(scoped ReadOnlySpan<byte> messagePack)

Parameters

messagePack ReadOnlySpan<byte>

One or more complete, well-formed MessagePack values.

Remarks

The caller is responsible for the bytes being valid MessagePack and for their count matching whatever container header preceded them; this method does not validate them.

WriteStartMap(int?)

Writes the beginning of a map.

public void WriteStartMap(int? propertyCount)

Parameters

propertyCount int?

The number of entries that will follow, when the caller knows it; otherwise null. A length-prefixed format uses it; a format that writes an explicit end token may ignore it, but must then also ignore it consistently so its decoder never reports a count it did not write.

WriteStartVector(int?)

Writes the beginning of a vector.

public void WriteStartVector(int? itemCount)

Parameters

itemCount int?

The number of elements that will follow, when the caller knows it; otherwise null.

WriteValue(bool)

Writes a Boolean.

public void WriteValue(bool value)

Parameters

value bool

The value to write.

WriteValue(DateTime)

Writes a date and time.

public void WriteValue(DateTime value)

Parameters

value DateTime

The value to write.

Remarks

The representation must preserve whatever the format's decoder promises to read back, including the DateTimeKind if the round trip is to be faithful.

WriteValue(decimal)

Writes an exact decimal number.

public void WriteValue(decimal value)

Parameters

value decimal

The value to write.

Remarks

Binary floating point cannot hold a decimal exactly. A format without a native decimal type should carry its text so that both the digits and the scale survive.

WriteValue(double)

Writes a double-precision floating-point number.

public void WriteValue(double value)

Parameters

value double

The value to write.

WriteValue(Half)

Writes a half-precision floating-point number.

public void WriteValue(Half value)

Parameters

value Half

The value to write.

WriteValue(Int128)

Writes a signed 128-bit integer.

public void WriteValue(Int128 value)

Parameters

value Int128

The value to write.

Remarks

Few formats have a native 128-bit type. Choose a documented, interoperable encoding (such as decimal text) rather than one that narrows the value.

WriteValue(long)

Writes a signed 64-bit integer.

public void WriteValue(long value)

Parameters

value long

The value to write.

Remarks

A format is free to choose the narrowest representation that holds the value, provided its decoder widens it back losslessly.

WriteValue(BigInteger)

Writes an arbitrarily large integer.

public void WriteValue(BigInteger value)

Parameters

value BigInteger

The value to write.

WriteValue(scoped ReadOnlySpan<byte>)

Writes a binary value.

public void WriteValue(scoped ReadOnlySpan<byte> value)

Parameters

value ReadOnlySpan<byte>

The bytes to write.

Exceptions

NotSupportedException

Thrown when the format has no binary representation.

WriteValue(scoped ReadOnlySpan<char>)

Writes text without requiring the caller to materialize a string.

public void WriteValue(scoped ReadOnlySpan<char> value)

Parameters

value ReadOnlySpan<char>

The text to write.

Remarks

This is the allocation-free path converters prefer; implement it directly rather than by forwarding to WriteValue(string).

WriteValue(float)

Writes a single-precision floating-point number.

public void WriteValue(float value)

Parameters

value float

The value to write.

WriteValue(string)

Writes a string.

public void WriteValue(string value)

Parameters

value string

The value to write.

WriteValue(TimeSpan)

Writes a duration.

public void WriteValue(TimeSpan value)

Parameters

value TimeSpan

The value to write.

WriteValue(UInt128)

Writes an unsigned 128-bit integer.

public void WriteValue(UInt128 value)

Parameters

value UInt128

The value to write.

WriteValue(ulong)

Writes an unsigned 64-bit integer.

public void WriteValue(ulong value)

Parameters

value ulong

The value to write.