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
sourceReadOnlySpan<byte>The buffer to read from.
headerExtensionHeaderThe extension header that introduces the timestamp. This extension is expected to carry a TypeCode value of DateTime.
valueDateTimeReceives the timestamp if successful.
tokenSizeintReceives the number of bytes read from the source, or the minimum length of
sourcerequired 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
sourceReadOnlySpan<byte>The buffer to read from.
valueboolReceives the boolean value if successful.
tokenSizeintReceives the number of bytes read from the source, or the minimum length of
sourcerequired 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
sourceReadOnlySpan<byte>The buffer to read from.
valuebyteReceives the value if successful.
tokenSizeintReceives the number of bytes read from the source, or the minimum length of
sourcerequired 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
sourceReadOnlySpan<byte>The buffer to read from.
valuecharReceives the character if successful.
tokenSizeintReceives the number of bytes read from the source, or the minimum length of
sourcerequired 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
sourceReadOnlySpan<byte>The buffer to read from.
valueDateTimeReceives the timestamp if successful.
tokenSizeintReceives the number of bytes read from the source, or the minimum length of
sourcerequired 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
sourceReadOnlySpan<byte>The buffer to read from.
valuedoubleReceives the value if successful.
tokenSizeintReceives the number of bytes read from the source, or the minimum length of
sourcerequired 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
sourceReadOnlySpan<byte>The buffer to read from.
valueshortReceives the value if successful.
tokenSizeintReceives the number of bytes read from the source, or the minimum length of
sourcerequired 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
sourceReadOnlySpan<byte>The buffer to read from.
valueintReceives the value if successful.
tokenSizeintReceives the number of bytes read from the source, or the minimum length of
sourcerequired 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
sourceReadOnlySpan<byte>The buffer to read from.
valuelongReceives the value if successful.
tokenSizeintReceives the number of bytes read from the source, or the minimum length of
sourcerequired 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
sourceReadOnlySpan<byte>The buffer to read from.
valuesbyteReceives the value if successful.
tokenSizeintReceives the number of bytes read from the source, or the minimum length of
sourcerequired 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
sourceReadOnlySpan<byte>The buffer to read from.
valuefloatReceives the value if successful.
tokenSizeintReceives the number of bytes read from the source, or the minimum length of
sourcerequired 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
sourceReadOnlySpan<byte>The buffer to read from.
valueushortReceives the value if successful.
tokenSizeintReceives the number of bytes read from the source, or the minimum length of
sourcerequired 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
sourceReadOnlySpan<byte>The buffer to read from.
valueuintReceives the value if successful.
tokenSizeintReceives the number of bytes read from the source, or the minimum length of
sourcerequired 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
sourceReadOnlySpan<byte>The buffer to read from.
valueulongReceives the value if successful.
tokenSizeintReceives the number of bytes read from the source, or the minimum length of
sourcerequired 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
sourceReadOnlySequence<byte>The buffer to read from.
countuintReceives the number of key-value pairs in the array, if successful.
readToSequencePositionReceives 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
sourceReadOnlySpan<byte>The buffer to read from.
countuintReceives the number of elements in the array, if successful.
tokenSizeintReceives the number of bytes read from the source, or the minimum length of
sourcerequired 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
sourceReadOnlySpan<byte>The buffer to read from.
lengthuintReceives the length of the binary data, if successful.
tokenSizeintReceives the number of bytes read from the source, or the minimum length of
sourcerequired 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
sourceReadOnlySpan<byte>The buffer to read from.
extensionHeaderExtensionHeaderReceives the extension header, if successful.
tokenSizeintReceives the number of bytes read from the source, or the minimum length of
sourcerequired 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
sourceReadOnlySequence<byte>The buffer to read from.
countuintReceives the number of key-value pairs in the map, if successful.
readToSequencePositionReceives 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
sourceReadOnlySpan<byte>The buffer to read from.
countuintReceives the number of key-value pairs in the map, if successful.
tokenSizeintReceives the number of bytes read from the source, or the minimum length of
sourcerequired 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
sourceReadOnlySpan<byte>The buffer to read from.
tokenSizeintReceives the number of bytes read from the source, or the minimum length of
sourcerequired 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
sourceReadOnlySpan<byte>The buffer to read from.
lengthuintReceives the length of the string, if successful.
tokenSizeintReceives the number of bytes read from the source, or the minimum length of
sourcerequired 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
destinationSpan<byte>The buffer to write to. This should be at least 1 byte in length to ensure success.
valueboolThe boolean value to write.
bytesWrittenintThe number of bytes required to write the value, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the value written; otherwise, false. When false, the value ofbytesWrittenindicates 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
destinationSpan<byte>The buffer to write to. This should be at least 2 bytes in length to ensure success with any value for
value.valuebyteThe unsigned integer value to write.
bytesWrittenintThe number of bytes required to write the value, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the value written; otherwise, false. When false, the value ofbytesWrittenindicates 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
destinationSpan<byte>The buffer to write to. This should be at least 3 bytes in length to ensure success.
valuecharThe character value to write.
bytesWrittenintThe number of bytes required to write the value, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the value written; otherwise, false. When false, the value ofbytesWrittenindicates 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
destinationSpan<byte>The buffer to write to. This should be at least 315 bytes in length to ensure success.
valueDateTimeThe DateTime value to write. This must not have Kind set to Unspecified.
bytesWrittenintThe number of bytes required to write the value, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the value written; otherwise, false. When false, the value ofbytesWrittenindicates 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.
Exceptions
- ArgumentException
Thrown if
valuehas a Kind set to Unspecified.
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
destinationSpan<byte>The buffer to write to. This should be at least 9 bytes in length to ensure success.
valuedoubleThe double-precision floating-point value to write.
bytesWrittenintThe number of bytes required to write the value, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the value written; otherwise, false. When false, the value ofbytesWrittenindicates 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
destinationSpan<byte>The buffer to write to. This should be at least 3 bytes in length to ensure success with any value for
value.valueshortThe signed integer value to write.
bytesWrittenintThe number of bytes required to write the value, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the value written; otherwise, false. When false, the value ofbytesWrittenindicates 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
destinationSpan<byte>The buffer to write to. This should be at least 5 bytes in length to ensure success with any value for
value.valueintThe signed integer value to write.
bytesWrittenintThe number of bytes required to write the value, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the value written; otherwise, false. When false, the value ofbytesWrittenindicates 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
destinationSpan<byte>The buffer to write to. This should be at least 9 bytes in length to ensure success with any value for
value.valuelongThe signed integer value to write.
bytesWrittenintThe number of bytes required to write the value, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the value written; otherwise, false. When false, the value ofbytesWrittenindicates 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
destinationSpan<byte>The buffer to write to. This should be at least 2 bytes in length to ensure success with any value for
value.valuesbyteThe signed integer value to write.
bytesWrittenintThe number of bytes required to write the value, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the value written; otherwise, false. When false, the value ofbytesWrittenindicates 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
destinationSpan<byte>The buffer to write to. This should be at least 5 bytes in length to ensure success.
valuefloatThe single-precision floating-point value to write.
bytesWrittenintThe number of bytes required to write the value, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the value written; otherwise, false. When false, the value ofbytesWrittenindicates 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
destinationSpan<byte>The buffer to write to. This should be at least 3 bytes in length to ensure success with any value for
value.valueushortThe unsigned integer value to write.
bytesWrittenintThe number of bytes required to write the value, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the value written; otherwise, false. When false, the value ofbytesWrittenindicates 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
destinationSpan<byte>The buffer to write to. This should be at least 5 bytes in length to ensure success with any value for
value.valueuintThe unsigned integer value to write.
bytesWrittenintThe number of bytes required to write the value, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the value written; otherwise, false. When false, the value ofbytesWrittenindicates 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
destinationSpan<byte>The buffer to write to. This should be at least 9 bytes in length to ensure success with any value for
value.valueulongThe unsigned integer value to write.
bytesWrittenintThe number of bytes required to write the value, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the value written; otherwise, false. When false, the value ofbytesWrittenindicates 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
destinationSpan<byte>The buffer to write to. This should be at least 5 bytes in length to ensure success with any value for
count.countuintThe number of elements in the array.
bytesWrittenintThe number of bytes required to write the array header, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the array header written; otherwise, false. When false, the value ofbytesWrittenindicates 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
destinationSpan<byte>The buffer to write to. This should be at least 5 bytes in length to ensure success.
lengthuintThe length of the binary data.
bytesWrittenintThe number of bytes required to write the binary header, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the binary header written; otherwise, false. When false, the value ofbytesWrittenindicates 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
destinationSpan<byte>The buffer to write to. This should be at least 6 bytes in length to ensure success.
extensionHeaderExtensionHeaderThe extension header to write.
bytesWrittenintThe number of bytes required to write the binary header, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the binary header written; otherwise, false. When false, the value ofbytesWrittenindicates 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
destinationSpan<byte>The buffer to write to. This should be at least 3 bytes in length to ensure success.
valueshortThe 16-bit signed integer value to write.
bytesWrittenintThe number of bytes required to write the value, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the value written; otherwise, false. When false, the value ofbytesWrittenindicates 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
destinationSpan<byte>The buffer to write to. This should be at least 5 bytes in length to ensure success.
valueintThe 32-bit signed integer value to write.
bytesWrittenintThe number of bytes required to write the value, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the value written; otherwise, false. When false, the value ofbytesWrittenindicates 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
destinationSpan<byte>The buffer to write to. This should be at least 9 bytes in length to ensure success.
valuelongThe 64-bit signed integer value to write.
bytesWrittenintThe number of bytes required to write the value, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the value written; otherwise, false. When false, the value ofbytesWrittenindicates 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
destinationSpan<byte>The buffer to write to. This should be at least 2 bytes in length.
valuesbyteThe 8-bit signed integer value to write.
bytesWrittenintThe number of bytes required to write the value, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the value written; otherwise, false. When false, the value ofbytesWrittenindicates 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
destinationSpan<byte>The buffer to write to. This should be at least 5 bytes in length to ensure success with any value for
count.countuintThe number of key-value pairs in the map.
bytesWrittenintThe number of bytes required to write the map header, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the map header written; otherwise, false. When false, the value ofbytesWrittenindicates 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
destinationSpan<byte>The buffer to write to. This should be at least 1 byte in length to ensure success.
bytesWrittenintThe number of bytes required to write the value, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the value written; otherwise, false. When false, the value ofbytesWrittenis 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
destinationSpan<byte>The buffer to write to. This should be at least 5 bytes in length to ensure success.
byteCountuintThe number of UTF-8 encoded bytes in the string.
bytesWrittenintThe number of bytes required to write the string header, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the string header written; otherwise, false. When false, the value ofbytesWrittenindicates 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
destinationSpan<byte>The buffer to write to. This should be at least 3 bytes in length.
valueushortThe 16-bit unsigned integer value to write.
bytesWrittenintThe number of bytes required to write the value, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the value written; otherwise, false. When false, the value ofbytesWrittenindicates 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
destinationSpan<byte>The buffer to write to. This should be at least 5 bytes in length.
valueuintThe 32-bit unsigned integer value to write.
bytesWrittenintThe number of bytes required to write the value, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the value written; otherwise, false. When false, the value ofbytesWrittenindicates 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
destinationSpan<byte>The buffer to write to. This should be at least 9 bytes in length.
valueulongThe 64-bit unsigned integer value to write.
bytesWrittenintThe number of bytes required to write the value, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the value written; otherwise, false. When false, the value ofbytesWrittenindicates 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
destinationSpan<byte>The buffer to write to. This should be at least 2 bytes in length.
valuebyteThe 8-bit unsigned integer value to write.
bytesWrittenintThe number of bytes required to write the value, whether successful or not.
Returns
- bool
true if
destinationwas large enough and the value written; otherwise, false. When false, the value ofbytesWrittenindicates 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.