Table of Contents

Class MessagePackPrimitives

Namespace
Nerdbank.MessagePack
Assembly
Nerdbank.MessagePack.dll

Primitive msgpack encoding/decoding methods.

public static class MessagePackPrimitives
Inheritance
MessagePackPrimitives
Inherited Members

Methods

TryRead(ReadOnlySpan<byte>, ExtensionHeader, out DateTime, out int)

Tries to read a DateTime from the specified buffer.

public static MessagePackPrimitives.DecodeResult TryRead(ReadOnlySpan<byte> source, ExtensionHeader header, out DateTime value, out int tokenSize)

Parameters

source ReadOnlySpan<byte>

The buffer to read from.

header ExtensionHeader

The extension header that introduces the timestamp. This extension is expected to carry a TypeCode value of DateTime.

value DateTime

Receives the timestamp if successful.

tokenSize int

Receives the number of bytes read from the source, or the minimum length of source required to read the data.

Returns

MessagePackPrimitives.DecodeResult

The result classification of the read operation.

TryRead(ReadOnlySpan<byte>, out bool, out int)

Tries to read a boolean value from the specified buffer.

public static MessagePackPrimitives.DecodeResult TryRead(ReadOnlySpan<byte> source, out bool value, out int tokenSize)

Parameters

source ReadOnlySpan<byte>

The buffer to read from.

value bool

Receives the boolean value if successful.

tokenSize int

Receives the number of bytes read from the source, or the minimum length of source required to read the data.

Returns

MessagePackPrimitives.DecodeResult

The result classification of the read operation.

Remarks

Reads a True or False value from the buffer.

TryRead(ReadOnlySpan<byte>, out byte, out int)

Tries to read an byte value from: Some value between MinNegativeFixInt and MaxNegativeFixInt, Some value between MinFixInt and MaxFixInt, or any of the other MsgPack integer types.

public static MessagePackPrimitives.DecodeResult TryRead(ReadOnlySpan<byte> source, out byte value, out int tokenSize)

Parameters

source ReadOnlySpan<byte>

The buffer to read from.

value byte

Receives the value if successful.

tokenSize int

Receives the number of bytes read from the source, or the minimum length of source required to read the data.

Returns

MessagePackPrimitives.DecodeResult

The value.

Exceptions

OverflowException

Thrown when the value exceeds what can be stored in the returned type.

TryRead(ReadOnlySpan<byte>, out char, out int)

Tries to read a singly encoded character from the specified buffer.

public static MessagePackPrimitives.DecodeResult TryRead(ReadOnlySpan<byte> source, out char value, out int tokenSize)

Parameters

source ReadOnlySpan<byte>

The buffer to read from.

value char

Receives the character if successful.

tokenSize int

Receives the number of bytes read from the source, or the minimum length of source required to read the data.

Returns

MessagePackPrimitives.DecodeResult

The result classification of the read operation.

Remarks

Reads a ushort value from the buffer and interprets it as a char.

TryRead(ReadOnlySpan<byte>, out DateTime, out int)

Tries to read a DateTime from the specified buffer.

public static MessagePackPrimitives.DecodeResult TryRead(ReadOnlySpan<byte> source, out DateTime value, out int tokenSize)

Parameters

source ReadOnlySpan<byte>

The buffer to read from.

value DateTime

Receives the timestamp if successful.

tokenSize int

Receives the number of bytes read from the source, or the minimum length of source required to read the data.

Returns

MessagePackPrimitives.DecodeResult

The result classification of the read operation.

Remarks

TryRead(ReadOnlySpan<byte>, out double, out int)

Tries to read an double value from a Float64 or Float32 or any of the integer types.

public static MessagePackPrimitives.DecodeResult TryRead(ReadOnlySpan<byte> source, out double value, out int tokenSize)

Parameters

source ReadOnlySpan<byte>

The buffer to read from.

value double

Receives the value if successful.

tokenSize int

Receives the number of bytes read from the source, or the minimum length of source required to read the data.

Returns

MessagePackPrimitives.DecodeResult

The value.

Exceptions

OverflowException

Thrown when the value exceeds what can be stored in the returned type.

TryRead(ReadOnlySpan<byte>, out short, out int)

Tries to read an short value from: Some value between MinNegativeFixInt and MaxNegativeFixInt, Some value between MinFixInt and MaxFixInt, or any of the other MsgPack integer types.

public static MessagePackPrimitives.DecodeResult TryRead(ReadOnlySpan<byte> source, out short value, out int tokenSize)

Parameters

source ReadOnlySpan<byte>

The buffer to read from.

value short

Receives the value if successful.

tokenSize int

Receives the number of bytes read from the source, or the minimum length of source required to read the data.

Returns

MessagePackPrimitives.DecodeResult

The value.

Exceptions

OverflowException

Thrown when the value exceeds what can be stored in the returned type.

TryRead(ReadOnlySpan<byte>, out int, out int)

Tries to read an int value from: Some value between MinNegativeFixInt and MaxNegativeFixInt, Some value between MinFixInt and MaxFixInt, or any of the other MsgPack integer types.

public static MessagePackPrimitives.DecodeResult TryRead(ReadOnlySpan<byte> source, out int value, out int tokenSize)

Parameters

source ReadOnlySpan<byte>

The buffer to read from.

value int

Receives the value if successful.

tokenSize int

Receives the number of bytes read from the source, or the minimum length of source required to read the data.

Returns

MessagePackPrimitives.DecodeResult

The value.

Exceptions

OverflowException

Thrown when the value exceeds what can be stored in the returned type.

TryRead(ReadOnlySpan<byte>, out long, out int)

Tries to read an long value from: Some value between MinNegativeFixInt and MaxNegativeFixInt, Some value between MinFixInt and MaxFixInt, or any of the other MsgPack integer types.

public static MessagePackPrimitives.DecodeResult TryRead(ReadOnlySpan<byte> source, out long value, out int tokenSize)

Parameters

source ReadOnlySpan<byte>

The buffer to read from.

value long

Receives the value if successful.

tokenSize int

Receives the number of bytes read from the source, or the minimum length of source required to read the data.

Returns

MessagePackPrimitives.DecodeResult

The value.

Exceptions

OverflowException

Thrown when the value exceeds what can be stored in the returned type.

TryRead(ReadOnlySpan<byte>, out sbyte, out int)

Tries to read an sbyte value from: Some value between MinNegativeFixInt and MaxNegativeFixInt, Some value between MinFixInt and MaxFixInt, or any of the other MsgPack integer types.

public static MessagePackPrimitives.DecodeResult TryRead(ReadOnlySpan<byte> source, out sbyte value, out int tokenSize)

Parameters

source ReadOnlySpan<byte>

The buffer to read from.

value sbyte

Receives the value if successful.

tokenSize int

Receives the number of bytes read from the source, or the minimum length of source required to read the data.

Returns

MessagePackPrimitives.DecodeResult

The value.

Exceptions

OverflowException

Thrown when the value exceeds what can be stored in the returned type.

TryRead(ReadOnlySpan<byte>, out float, out int)

Tries to read an float value from a Float64 or Float32 or any of the integer types.

public static MessagePackPrimitives.DecodeResult TryRead(ReadOnlySpan<byte> source, out float value, out int tokenSize)

Parameters

source ReadOnlySpan<byte>

The buffer to read from.

value float

Receives the value if successful.

tokenSize int

Receives the number of bytes read from the source, or the minimum length of source required to read the data.

Returns

MessagePackPrimitives.DecodeResult

The value.

Exceptions

OverflowException

Thrown when the value exceeds what can be stored in the returned type.

TryRead(ReadOnlySpan<byte>, out ushort, out int)

Tries to read an ushort value from: Some value between MinNegativeFixInt and MaxNegativeFixInt, Some value between MinFixInt and MaxFixInt, or any of the other MsgPack integer types.

public static MessagePackPrimitives.DecodeResult TryRead(ReadOnlySpan<byte> source, out ushort value, out int tokenSize)

Parameters

source ReadOnlySpan<byte>

The buffer to read from.

value ushort

Receives the value if successful.

tokenSize int

Receives the number of bytes read from the source, or the minimum length of source required to read the data.

Returns

MessagePackPrimitives.DecodeResult

The value.

Exceptions

OverflowException

Thrown when the value exceeds what can be stored in the returned type.

TryRead(ReadOnlySpan<byte>, out uint, out int)

Tries to read an uint value from: Some value between MinNegativeFixInt and MaxNegativeFixInt, Some value between MinFixInt and MaxFixInt, or any of the other MsgPack integer types.

public static MessagePackPrimitives.DecodeResult TryRead(ReadOnlySpan<byte> source, out uint value, out int tokenSize)

Parameters

source ReadOnlySpan<byte>

The buffer to read from.

value uint

Receives the value if successful.

tokenSize int

Receives the number of bytes read from the source, or the minimum length of source required to read the data.

Returns

MessagePackPrimitives.DecodeResult

The value.

Exceptions

OverflowException

Thrown when the value exceeds what can be stored in the returned type.

TryRead(ReadOnlySpan<byte>, out ulong, out int)

Tries to read an ulong value from: Some value between MinNegativeFixInt and MaxNegativeFixInt, Some value between MinFixInt and MaxFixInt, or any of the other MsgPack integer types.

public static MessagePackPrimitives.DecodeResult TryRead(ReadOnlySpan<byte> source, out ulong value, out int tokenSize)

Parameters

source ReadOnlySpan<byte>

The buffer to read from.

value ulong

Receives the value if successful.

tokenSize int

Receives the number of bytes read from the source, or the minimum length of source required to read the data.

Returns

MessagePackPrimitives.DecodeResult

The value.

Exceptions

OverflowException

Thrown when the value exceeds what can be stored in the returned type.

TryReadArrayHeader(ReadOnlySequence<byte>, out uint, out SequencePosition)

Tries to read the header of a array from the specified buffer.

public static MessagePackPrimitives.DecodeResult TryReadArrayHeader(ReadOnlySequence<byte> source, out uint count, out SequencePosition readTo)

Parameters

source ReadOnlySequence<byte>

The buffer to read from.

count uint

Receives the number of key-value pairs in the array, if successful.

readTo SequencePosition

Receives the position of the last byte consumed from source.

Returns

MessagePackPrimitives.DecodeResult

The result classification of the read operation.

Remarks

Reads a array header from Array16, Array32, or some built-in code between MinFixArray and MaxFixArray.

TryReadArrayHeader(ReadOnlySpan<byte>, out uint, out int)

Tries to read the header of an array from the specified buffer.

public static MessagePackPrimitives.DecodeResult TryReadArrayHeader(ReadOnlySpan<byte> source, out uint count, out int tokenSize)

Parameters

source ReadOnlySpan<byte>

The buffer to read from.

count uint

Receives the number of elements in the array, if successful.

tokenSize int

Receives the number of bytes read from the source, or the minimum length of source required to read the data.

Returns

MessagePackPrimitives.DecodeResult

The result classification of the read operation.

Remarks

Reads an array header from Array16, Array32, or some built-in code between MinFixArray and MaxFixArray.

TryReadBinHeader(ReadOnlySpan<byte>, out uint, out int)

Tries to read the header of a binary data segment from the specified buffer.

public static MessagePackPrimitives.DecodeResult TryReadBinHeader(ReadOnlySpan<byte> source, out uint length, out int tokenSize)

Parameters

source ReadOnlySpan<byte>

The buffer to read from.

length uint

Receives the length of the binary data, if successful.

tokenSize int

Receives the number of bytes read from the source, or the minimum length of source required to read the data.

Returns

MessagePackPrimitives.DecodeResult

The result classification of the read operation.

Remarks

Reads a binary data header from Bin8, Bin16, or Bin32.

Note that in the original msgpack spec, there were no binary data headers, so binary data was introduced using string headers. This should be read using TryReadStringHeader(ReadOnlySpan<byte>, out uint, out int).

TryReadExtensionHeader(ReadOnlySpan<byte>, out ExtensionHeader, out int)

Tries to read the header of an extension from the specified buffer.

public static MessagePackPrimitives.DecodeResult TryReadExtensionHeader(ReadOnlySpan<byte> source, out ExtensionHeader extensionHeader, out int tokenSize)

Parameters

source ReadOnlySpan<byte>

The buffer to read from.

extensionHeader ExtensionHeader

Receives the extension header, if successful.

tokenSize int

Receives the number of bytes read from the source, or the minimum length of source required to read the data.

Returns

MessagePackPrimitives.DecodeResult

The result classification of the read operation.

Remarks

Reads an extension header from FixExt1, FixExt2, FixExt4, FixExt8, FixExt16, Ext8, Ext16, or Ext32.

TryReadMapHeader(ReadOnlySequence<byte>, out uint, out SequencePosition)

Tries to read the header of a map from the specified buffer.

public static MessagePackPrimitives.DecodeResult TryReadMapHeader(ReadOnlySequence<byte> source, out uint count, out SequencePosition readTo)

Parameters

source ReadOnlySequence<byte>

The buffer to read from.

count uint

Receives the number of key-value pairs in the map, if successful.

readTo SequencePosition

Receives the position of the last byte consumed from source.

Returns

MessagePackPrimitives.DecodeResult

The result classification of the read operation.

Remarks

Reads a map header from Map16, Map32, or some built-in code between MinFixMap and MaxFixMap.

TryReadMapHeader(ReadOnlySpan<byte>, out uint, out int)

Tries to read the header of a map from the specified buffer.

public static MessagePackPrimitives.DecodeResult TryReadMapHeader(ReadOnlySpan<byte> source, out uint count, out int tokenSize)

Parameters

source ReadOnlySpan<byte>

The buffer to read from.

count uint

Receives the number of key-value pairs in the map, if successful.

tokenSize int

Receives the number of bytes read from the source, or the minimum length of source required to read the data.

Returns

MessagePackPrimitives.DecodeResult

The result classification of the read operation.

Remarks

Reads a map header from Map16, Map32, or some built-in code between MinFixMap and MaxFixMap.

TryReadNil(ReadOnlySpan<byte>, out int)

Tries to read a nil value from the specified buffer.

public static MessagePackPrimitives.DecodeResult TryReadNil(ReadOnlySpan<byte> source, out int tokenSize)

Parameters

source ReadOnlySpan<byte>

The buffer to read from.

tokenSize int

Receives the number of bytes read from the source, or the minimum length of source required to read the data.

Returns

MessagePackPrimitives.DecodeResult

The result classification of the read operation.

Remarks

Reads a Nil value from the buffer.

TryReadStringHeader(ReadOnlySpan<byte>, out uint, out int)

Tries to read the header of a string from the specified buffer.

public static MessagePackPrimitives.DecodeResult TryReadStringHeader(ReadOnlySpan<byte> source, out uint length, out int tokenSize)

Parameters

source ReadOnlySpan<byte>

The buffer to read from.

length uint

Receives the length of the string, if successful.

tokenSize int

Receives the number of bytes read from the source, or the minimum length of source required to read the data.

Returns

MessagePackPrimitives.DecodeResult

The result classification of the read operation.

Remarks

Reads a string header from Str8, Str16, Str32, or any value between MinFixStr and MaxFixStr.

Note that in the original msgpack spec, there were no binary data headers, so binary data was introduced using string headers.

TryWrite(Span<byte>, bool, out int)

Writes a boolean value to the specified buffer, if the buffer is large enough.

public static bool TryWrite(Span<byte> destination, bool value, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 1 byte in length to ensure success.

value bool

The boolean value to write.

bytesWritten int

The number of bytes required to write the value, whether successful or not.

Returns

bool

true if destination was large enough and the value written; otherwise, false. When false, the value of bytesWritten indicates how many bytes are required to write the value successfully.

TryWrite(Span<byte>, byte, out int)

Writes an unsigned integer value to the specified buffer, if the buffer is large enough.

public static bool TryWrite(Span<byte> destination, byte value, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 2 bytes in length to ensure success with any value for value.

value byte

The unsigned integer value to write.

bytesWritten int

The number of bytes required to write the value, whether successful or not.

Returns

bool

true if destination was large enough and the value written; otherwise, false. When false, the value of bytesWritten indicates how many bytes are required to write the value successfully.

Remarks

The smallest possible representation is used for the value, which may be as few as 1 byte. In addition to the built-in 1-byte code when within specific MessagePack-supported ranges, any of the following encodings may also be used: UInt8.

TryWrite(Span<byte>, char, out int)

Writes a character value to the specified buffer, if the buffer is large enough.

public static bool TryWrite(Span<byte> destination, char value, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 3 bytes in length to ensure success.

value char

The character value to write.

bytesWritten int

The number of bytes required to write the value, whether successful or not.

Returns

bool

true if destination was large enough and the value written; otherwise, false. When false, the value of bytesWritten indicates how many bytes are required to write the value successfully.

Remarks

A character is encoded as a 16-bit unsigned integer, in its most compact form.

TryWrite(Span<byte>, DateTime, out int)

Writes a DateTime value to the specified buffer, if the buffer is large enough.

public static bool TryWrite(Span<byte> destination, DateTime value, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 315 bytes in length to ensure success.

value DateTime

The DateTime value to write.

bytesWritten int

The number of bytes required to write the value, whether successful or not.

Returns

bool

true if destination was large enough and the value written; otherwise, false. When false, the value of bytesWritten indicates how many bytes are required to write the value successfully.

Remarks

The value is encoded as an extension type with a type code of DateTime.

TryWrite(Span<byte>, double, out int)

Writes a double-precision floating-point value to the specified buffer, if the buffer is large enough.

public static bool TryWrite(Span<byte> destination, double value, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 9 bytes in length to ensure success.

value double

The double-precision floating-point value to write.

bytesWritten int

The number of bytes required to write the value, whether successful or not.

Returns

bool

true if destination was large enough and the value written; otherwise, false. When false, the value of bytesWritten indicates how many bytes are required to write the value successfully.

Remarks

The Float64 encoding is always used.

TryWrite(Span<byte>, short, out int)

Writes a signed integer value to the specified buffer, if the buffer is large enough.

public static bool TryWrite(Span<byte> destination, short value, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 3 bytes in length to ensure success with any value for value.

value short

The signed integer value to write.

bytesWritten int

The number of bytes required to write the value, whether successful or not.

Returns

bool

true if destination was large enough and the value written; otherwise, false. When false, the value of bytesWritten indicates how many bytes are required to write the value successfully.

Remarks

The smallest possible representation is used for the value, which may be as few as 1 byte. In addition to the built-in 1-byte code when within specific MessagePack-supported ranges, any of the following encodings may also be used: UInt8, UInt16, Int8, Int16.

TryWrite(Span<byte>, int, out int)

Writes a signed integer value to the specified buffer, if the buffer is large enough.

public static bool TryWrite(Span<byte> destination, int value, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 5 bytes in length to ensure success with any value for value.

value int

The signed integer value to write.

bytesWritten int

The number of bytes required to write the value, whether successful or not.

Returns

bool

true if destination was large enough and the value written; otherwise, false. When false, the value of bytesWritten indicates how many bytes are required to write the value successfully.

Remarks

The smallest possible representation is used for the value, which may be as few as 1 byte. In addition to the built-in 1-byte code when within specific MessagePack-supported ranges, any of the following encodings may also be used: UInt8, UInt16, UInt32, Int8, Int16, Int32.

TryWrite(Span<byte>, long, out int)

Writes a signed integer value to the specified buffer, if the buffer is large enough.

public static bool TryWrite(Span<byte> destination, long value, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 9 bytes in length to ensure success with any value for value.

value long

The signed integer value to write.

bytesWritten int

The number of bytes required to write the value, whether successful or not.

Returns

bool

true if destination was large enough and the value written; otherwise, false. When false, the value of bytesWritten indicates how many bytes are required to write the value successfully.

Remarks

The smallest possible representation is used for the value, which may be as few as 1 byte. In addition to the built-in 1-byte code when within specific MessagePack-supported ranges, any of the following encodings may also be used: UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64.

TryWrite(Span<byte>, sbyte, out int)

Writes a signed integer value to the specified buffer, if the buffer is large enough.

public static bool TryWrite(Span<byte> destination, sbyte value, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 2 bytes in length to ensure success with any value for value.

value sbyte

The signed integer value to write.

bytesWritten int

The number of bytes required to write the value, whether successful or not.

Returns

bool

true if destination was large enough and the value written; otherwise, false. When false, the value of bytesWritten indicates how many bytes are required to write the value successfully.

Remarks

The smallest possible representation is used for the value, which may be as few as 1 byte. In addition to the built-in 1-byte code when within specific MessagePack-supported ranges, any of the following encodings may also be used: UInt8, Int8.

TryWrite(Span<byte>, float, out int)

Writes a single-precision floating-point value to the specified buffer, if the buffer is large enough.

public static bool TryWrite(Span<byte> destination, float value, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 5 bytes in length to ensure success.

value float

The single-precision floating-point value to write.

bytesWritten int

The number of bytes required to write the value, whether successful or not.

Returns

bool

true if destination was large enough and the value written; otherwise, false. When false, the value of bytesWritten indicates how many bytes are required to write the value successfully.

Remarks

The Float32 encoding is always used.

TryWrite(Span<byte>, ushort, out int)

Writes an unsigned integer value to the specified buffer, if the buffer is large enough.

public static bool TryWrite(Span<byte> destination, ushort value, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 3 bytes in length to ensure success with any value for value.

value ushort

The unsigned integer value to write.

bytesWritten int

The number of bytes required to write the value, whether successful or not.

Returns

bool

true if destination was large enough and the value written; otherwise, false. When false, the value of bytesWritten indicates how many bytes are required to write the value successfully.

Remarks

The smallest possible representation is used for the value, which may be as few as 1 byte. In addition to the built-in 1-byte code when within specific MessagePack-supported ranges, any of the following encodings may also be used: UInt8, UInt16.

TryWrite(Span<byte>, uint, out int)

Writes an unsigned integer value to the specified buffer, if the buffer is large enough.

public static bool TryWrite(Span<byte> destination, uint value, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 5 bytes in length to ensure success with any value for value.

value uint

The unsigned integer value to write.

bytesWritten int

The number of bytes required to write the value, whether successful or not.

Returns

bool

true if destination was large enough and the value written; otherwise, false. When false, the value of bytesWritten indicates how many bytes are required to write the value successfully.

Remarks

The smallest possible representation is used for the value, which may be as few as 1 byte. In addition to the built-in 1-byte code when within specific MessagePack-supported ranges, any of the following encodings may also be used: UInt8, UInt16, UInt32.

TryWrite(Span<byte>, ulong, out int)

Writes an unsigned integer value to the specified buffer, if the buffer is large enough.

public static bool TryWrite(Span<byte> destination, ulong value, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 9 bytes in length to ensure success with any value for value.

value ulong

The unsigned integer value to write.

bytesWritten int

The number of bytes required to write the value, whether successful or not.

Returns

bool

true if destination was large enough and the value written; otherwise, false. When false, the value of bytesWritten indicates how many bytes are required to write the value successfully.

Remarks

The smallest possible representation is used for the value, which may be as few as 1 byte. In addition to the built-in 1-byte code when within specific MessagePack-supported ranges, any of the following encodings may also be used: UInt8, UInt16, UInt32, UInt64.

TryWriteArrayHeader(Span<byte>, uint, out int)

Writes the array header to the specified buffer, if the buffer is large enough.

public static bool TryWriteArrayHeader(Span<byte> destination, uint count, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 5 bytes in length to ensure success with any value for count.

count uint

The number of elements in the array.

bytesWritten int

The number of bytes required to write the array header, whether successful or not.

Returns

bool

true if destination was large enough and the array header written; otherwise, false. When false, the value of bytesWritten indicates how many bytes are required to write the array header successfully.

Remarks

Writes the length of the next array to be written in the most compact form of MinFixArray, Array16, or Array32.

TryWriteBinHeader(Span<byte>, uint, out int)

Writes the binary header to the specified buffer, if the buffer is large enough.

public static bool TryWriteBinHeader(Span<byte> destination, uint length, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 5 bytes in length to ensure success.

length uint

The length of the binary data.

bytesWritten int

The number of bytes required to write the binary header, whether successful or not.

Returns

bool

true if destination was large enough and the binary header written; otherwise, false. When false, the value of bytesWritten indicates how many bytes are required to write the binary header successfully.

Remarks

Writes the length of the binary data in the most compact form of Bin8, Bin16, or Bin32.

TryWriteExtensionHeader(Span<byte>, ExtensionHeader, out int)

Writes an extension header to the specified buffer, if the buffer is large enough.

public static bool TryWriteExtensionHeader(Span<byte> destination, ExtensionHeader extensionHeader, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 6 bytes in length to ensure success.

extensionHeader ExtensionHeader

The extension header to write.

bytesWritten int

The number of bytes required to write the binary header, whether successful or not.

Returns

bool

true if destination was large enough and the binary header written; otherwise, false. When false, the value of bytesWritten indicates how many bytes are required to write the binary header successfully.

Remarks

Writes the header of the extension data using the most compact form of FixExt1, FixExt2, FixExt4, FixExt8, Ext8, Ext16, or Ext32.

TryWriteInt16(Span<byte>, short, out int)

Writes a 16-bit signed integer value to the specified buffer, if the buffer is large enough.

public static bool TryWriteInt16(Span<byte> destination, short value, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 3 bytes in length to ensure success.

value short

The 16-bit signed integer value to write.

bytesWritten int

The number of bytes required to write the value, whether successful or not.

Returns

bool

true if destination was large enough and the value written; otherwise, false. When false, the value of bytesWritten indicates how many bytes are required to write the value successfully.

Remarks

The Int16 encoding is always used, even if the value could be encoded in fewer bytes.

TryWriteInt32(Span<byte>, int, out int)

Writes a 32-bit signed integer value to the specified buffer, if the buffer is large enough.

public static bool TryWriteInt32(Span<byte> destination, int value, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 5 bytes in length to ensure success.

value int

The 32-bit signed integer value to write.

bytesWritten int

The number of bytes required to write the value, whether successful or not.

Returns

bool

true if destination was large enough and the value written; otherwise, false. When false, the value of bytesWritten indicates how many bytes are required to write the value successfully.

Remarks

The Int32 encoding is always used, even if the value could be encoded in fewer bytes.

TryWriteInt64(Span<byte>, long, out int)

Writes a 64-bit signed integer value to the specified buffer, if the buffer is large enough.

public static bool TryWriteInt64(Span<byte> destination, long value, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 9 bytes in length to ensure success.

value long

The 64-bit signed integer value to write.

bytesWritten int

The number of bytes required to write the value, whether successful or not.

Returns

bool

true if destination was large enough and the value written; otherwise, false. When false, the value of bytesWritten indicates how many bytes are required to write the value successfully.

Remarks

The Int64 encoding is always used, even if the value could be encoded in fewer bytes.

TryWriteInt8(Span<byte>, sbyte, out int)

Writes an 8-bit signed integer value to the specified buffer, if the buffer is large enough.

public static bool TryWriteInt8(Span<byte> destination, sbyte value, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 2 bytes in length.

value sbyte

The 8-bit signed integer value to write.

bytesWritten int

The number of bytes required to write the value, whether successful or not.

Returns

bool

true if destination was large enough and the value written; otherwise, false. When false, the value of bytesWritten indicates how many bytes are required to write the value successfully.

Remarks

The Int8 encoding is always used, even if the value could be encoded in fewer bytes.

TryWriteMapHeader(Span<byte>, uint, out int)

Writes the map header to the specified buffer, if the buffer is large enough.

public static bool TryWriteMapHeader(Span<byte> destination, uint count, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 5 bytes in length to ensure success with any value for count.

count uint

The number of key-value pairs in the map.

bytesWritten int

The number of bytes required to write the map header, whether successful or not.

Returns

bool

true if destination was large enough and the map header written; otherwise, false. When false, the value of bytesWritten indicates how many bytes are required to write the map header successfully.

Remarks

Writes the length of the next map to be written in the most compact form of MinFixMap, Map16, or Map32.

TryWriteNil(Span<byte>, out int)

Write a nil value to the specified buffer, if the buffer is large enough.

public static bool TryWriteNil(Span<byte> destination, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 1 byte in length to ensure success.

bytesWritten int

The number of bytes required to write the value, whether successful or not.

Returns

bool

true if destination was large enough and the value written; otherwise, false. When false, the value of bytesWritten is indicates how many bytes are required to write the value successfully.

TryWriteStringHeader(Span<byte>, uint, out int)

Writes the header for a UTF-8 encoded string to the specified buffer, if the buffer is large enough.

public static bool TryWriteStringHeader(Span<byte> destination, uint byteCount, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 5 bytes in length to ensure success.

byteCount uint

The number of UTF-8 encoded bytes in the string.

bytesWritten int

The number of bytes required to write the string header, whether successful or not.

Returns

bool

true if destination was large enough and the string header written; otherwise, false. When false, the value of bytesWritten indicates how many bytes are required to write the string header successfully.

Remarks

Writes the length of the string in the most compact form of MinFixStr, Str8, Str16, or Str32.

TryWriteUInt16(Span<byte>, ushort, out int)

Writes an 16-bit unsigned integer value to the specified buffer, if the buffer is large enough.

public static bool TryWriteUInt16(Span<byte> destination, ushort value, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 3 bytes in length.

value ushort

The 16-bit unsigned integer value to write.

bytesWritten int

The number of bytes required to write the value, whether successful or not.

Returns

bool

true if destination was large enough and the value written; otherwise, false. When false, the value of bytesWritten indicates how many bytes are required to write the value successfully.

Remarks

The UInt16 encoding is always used, even if the value could be encoded in fewer bytes.

TryWriteUInt32(Span<byte>, uint, out int)

Writes a 32-bit unsigned integer value to the specified buffer, if the buffer is large enough.

public static bool TryWriteUInt32(Span<byte> destination, uint value, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 5 bytes in length.

value uint

The 32-bit unsigned integer value to write.

bytesWritten int

The number of bytes required to write the value, whether successful or not.

Returns

bool

true if destination was large enough and the value written; otherwise, false. When false, the value of bytesWritten indicates how many bytes are required to write the value successfully.

Remarks

The UInt32 encoding is always used, even if the value could be encoded in fewer bytes.

TryWriteUInt64(Span<byte>, ulong, out int)

Writes a 64-bit unsigned integer value to the specified buffer, if the buffer is large enough.

public static bool TryWriteUInt64(Span<byte> destination, ulong value, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 9 bytes in length.

value ulong

The 64-bit unsigned integer value to write.

bytesWritten int

The number of bytes required to write the value, whether successful or not.

Returns

bool

true if destination was large enough and the value written; otherwise, false. When false, the value of bytesWritten indicates how many bytes are required to write the value successfully.

Remarks

The UInt64 encoding is always used, even if the value could be encoded in fewer bytes.

TryWriteUInt8(Span<byte>, byte, out int)

Writes an 8-bit unsigned integer value to the specified buffer, if the buffer is large enough.

public static bool TryWriteUInt8(Span<byte> destination, byte value, out int bytesWritten)

Parameters

destination Span<byte>

The buffer to write to. This should be at least 2 bytes in length.

value byte

The 8-bit unsigned integer value to write.

bytesWritten int

The number of bytes required to write the value, whether successful or not.

Returns

bool

true if destination was large enough and the value written; otherwise, false. When false, the value of bytesWritten indicates how many bytes are required to write the value successfully.

Remarks

The UInt8 encoding is always used, even if the value could be encoded in fewer bytes.