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
ExtensionHeaderThe extension header that introduces the timestamp. This extension is expected to carry a TypeCode value of DateTime.
value
DateTimeReceives the timestamp if successful.
tokenSize
intReceives 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
boolReceives the boolean value if successful.
tokenSize
intReceives 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 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
byteReceives the value if successful.
tokenSize
intReceives 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
charReceives the character if successful.
tokenSize
intReceives 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
DateTimeReceives the timestamp if successful.
tokenSize
intReceives 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 the extension header using TryReadExtensionHeader(ReadOnlySpan<byte>, out ExtensionHeader, out int) then the extension itself using TryRead(ReadOnlySpan<byte>, ExtensionHeader, out DateTime, out int).
TryRead(ReadOnlySpan<byte>, out double, out int)
public static MessagePackPrimitives.DecodeResult TryRead(ReadOnlySpan<byte> source, out double value, out int tokenSize)
Parameters
source
ReadOnlySpan<byte>The buffer to read from.
value
doubleReceives the value if successful.
tokenSize
intReceives 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
shortReceives the value if successful.
tokenSize
intReceives 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
intReceives the value if successful.
tokenSize
intReceives 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
longReceives the value if successful.
tokenSize
intReceives 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
sbyteReceives the value if successful.
tokenSize
intReceives 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)
public static MessagePackPrimitives.DecodeResult TryRead(ReadOnlySpan<byte> source, out float value, out int tokenSize)
Parameters
source
ReadOnlySpan<byte>The buffer to read from.
value
floatReceives the value if successful.
tokenSize
intReceives 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
ushortReceives the value if successful.
tokenSize
intReceives 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
uintReceives the value if successful.
tokenSize
intReceives 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
ulongReceives the value if successful.
tokenSize
intReceives 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
uintReceives the number of key-value pairs in the array, if successful.
readTo
SequencePositionReceives 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
uintReceives the number of elements in the array, if successful.
tokenSize
intReceives 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
uintReceives the length of the binary data, if successful.
tokenSize
intReceives 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
ExtensionHeaderReceives the extension header, if successful.
tokenSize
intReceives 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
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
uintReceives the number of key-value pairs in the map, if successful.
readTo
SequencePositionReceives the position of the last byte consumed from
source
.
Returns
- MessagePackPrimitives.DecodeResult
The result classification of the read operation.
Remarks
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
uintReceives the number of key-value pairs in the map, if successful.
tokenSize
intReceives 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
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
intReceives 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
uintReceives the length of the string, if successful.
tokenSize
intReceives 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
boolThe boolean value to write.
bytesWritten
intThe 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 ofbytesWritten
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
byteThe unsigned integer value to write.
bytesWritten
intThe 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 ofbytesWritten
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
charThe character value to write.
bytesWritten
intThe 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 ofbytesWritten
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
DateTimeThe DateTime value to write.
bytesWritten
intThe 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 ofbytesWritten
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
doubleThe double-precision floating-point value to write.
bytesWritten
intThe 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 ofbytesWritten
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
shortThe signed integer value to write.
bytesWritten
intThe 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 ofbytesWritten
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
intThe signed integer value to write.
bytesWritten
intThe 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 ofbytesWritten
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
longThe signed integer value to write.
bytesWritten
intThe 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 ofbytesWritten
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
sbyteThe signed integer value to write.
bytesWritten
intThe 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 ofbytesWritten
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
floatThe single-precision floating-point value to write.
bytesWritten
intThe 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 ofbytesWritten
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
ushortThe unsigned integer value to write.
bytesWritten
intThe 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 ofbytesWritten
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
uintThe unsigned integer value to write.
bytesWritten
intThe 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 ofbytesWritten
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
ulongThe unsigned integer value to write.
bytesWritten
intThe 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 ofbytesWritten
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
uintThe number of elements in the array.
bytesWritten
intThe 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 ofbytesWritten
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
uintThe length of the binary data.
bytesWritten
intThe 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 ofbytesWritten
indicates how many bytes are required to write the binary header successfully.
Remarks
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
ExtensionHeaderThe extension header to write.
bytesWritten
intThe 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 ofbytesWritten
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
shortThe 16-bit signed integer value to write.
bytesWritten
intThe 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 ofbytesWritten
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
intThe 32-bit signed integer value to write.
bytesWritten
intThe 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 ofbytesWritten
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
longThe 64-bit signed integer value to write.
bytesWritten
intThe 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 ofbytesWritten
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
sbyteThe 8-bit signed integer value to write.
bytesWritten
intThe 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 ofbytesWritten
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
uintThe number of key-value pairs in the map.
bytesWritten
intThe 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 ofbytesWritten
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
intThe 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 ofbytesWritten
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
uintThe number of UTF-8 encoded bytes in the string.
bytesWritten
intThe 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 ofbytesWritten
indicates how many bytes are required to write the string header successfully.
Remarks
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
ushortThe 16-bit unsigned integer value to write.
bytesWritten
intThe 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 ofbytesWritten
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
uintThe 32-bit unsigned integer value to write.
bytesWritten
intThe 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 ofbytesWritten
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
ulongThe 64-bit unsigned integer value to write.
bytesWritten
intThe 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 ofbytesWritten
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
byteThe 8-bit unsigned integer value to write.
bytesWritten
intThe 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 ofbytesWritten
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.