MessagePack
Utility methods for intrinsic bit-twiddling operations.
The methods use hardware intrinsics when available on the underlying platform,
otherwise they use optimized software fallbacks.
Rotates the specified value left by the specified number of bits.
Similar in behavior to the x86 instruction ROL.
The value to rotate.
The number of bits to rotate by.
Any value outside the range [0..31] is treated as congruent mod 32.
The rotated value.
Provides general helpers for creating collections (including dictionaries).
The concrete type of collection to create.
The type of equality comparer that we would hope to pass into the collection's constructor.
The delegate that will create the collection, if the typical (int count, IEqualityComparer{T} equalityComparer) constructor was found.
Initializes static members of the class.
Initializes a delegate that is optimized to create a collection of a given size and using the given equality comparer, if possible.
Initializes a new instance of the collection.
The number of elements the collection should be prepared to receive.
The equality comparer to initialize the collection with.
The newly initialized collection.
Use of the and are a best effort.
If we can't find a constructor on the collection in the expected shape, we'll just instantiate the collection with its default constructor.
Serialize by .NET native DateTime binary format.
This formatter can serialize any value whose static type is
for which another resolver can provide a formatter for the runtime type.
Its deserialization is limited to forwarding all calls to the .
A base interface for so that all generic implementations
can be detected by a common base type.
The contract for serialization of some specific type.
The type to be serialized or deserialized.
Serializes a value.
The writer to use when serializing the value.
The value to be serialized.
The serialization settings to use, including the resolver to use to obtain formatters for types that make up the composite type .
Deserializes a value.
The reader to deserialize from.
The serialization settings to use, including the resolver to use to obtain formatters for types that make up the composite type .
The deserialized value.
Serializes a array as a bin type.
Deserializes a bin type or an array of byte-sized integers into a array.
Serializes any instance of by its value.
The class itself or a derived type.
A formatter that interns strings on deserialization.
Force serialize object as typeless.
For `object` field that holds derived from `object` value, ex: var arr = new object[] { 1, "a", new Model() };.
The singleton instance that can be used.
Does not support deserializing of anonymous types
Type should be covered by preceeding resolvers in complex/standard resolver.
Unsafe binary Guid formatter. this is only allowed on LittleEndian environment.
Unsafe binary Decimal formatter. this is only allows on LittleEndian environment.
This code is used by dynamically generated code as well as AOT generated code,
and thus must be public for the "C# generated and compiled into saved assembly" scenario.
This is used by dynamically generated code. It can be made internal after we enable our dynamic assemblies to access internals.
But that trick may require net46, so maybe we should leave this as public.
Helpers for generated code.
This code is used by dynamically generated code as well as AOT generated code,
and thus must be public for the "C# generated and compiled into saved assembly" scenario.
Gets the messagepack encoding for a given string.
The string to encode.
The messagepack encoding for , including messagepack header and UTF-8 bytes.
Gets a single containing all bytes in a given .
An array may be allocated if the bytes are not already contiguous in memory.
The sequence to get a span for.
The span.
Reads a string as a contiguous span of UTF-8 encoded characters.
An array may be allocated if the string is not already contiguous in memory.
The reader to use.
The span of UTF-8 encoded characters.
Creates a array for a given sequence, or if the optional sequence is itself .
The sequence.
The byte array or .
Get MethodInfo from Expression for Static(with result) method.
Get MethodInfo from Expression for Static(void) method.
Get MethodInfo from Expression for Instance(with result) method.
Get MethodInfo from Expression for Instance(void) method.
Get MethodInfo from Expression for Instance(with result) method.
Provides optimized generation code and helpers.
Loads the local variable at a specific index onto the evaluation stack.
Pops the current value from the top of the evaluation stack and stores it in a the local variable list at a specified index.
Loads the address of the local variable at a specific index onto the evaluation statck.
Pushes a supplied value of type int32 onto the evaluation stack as an int32.
Helper for Pop op.
for var i = 0, i ..., i++.
A dictionary where is the key, and a configurable type
that is thread-safe to read and write, allowing concurrent reads and exclusive writes.
The type of value stored in the dictionary.
Helps match parameters when searching a method when the parameter is a generic type.
Keep this list in sync with ShouldUseFormatterResolverHelper.PrimitiveTypes.
Gets a value indicating whether the property can only be set by an object initializer, a constructor, or another `init` member.
Gets or sets a value indicating whether this member is explicitly opted in with an attribute.
Gets a value indicating whether a dynamic resolver can write to this property,
going beyond by also considering CLR bugs.
Gets a value indicating whether this member is a property with an property setter
and is declared on a generic class.
A bug in
blocks its ability to invoke property init accessors when in a generic class.
Identifies the unsupported scenario of an
property accessor within a generic class.
A primitive types reader for the MessagePack format.
The MessagePack spec..
Thrown when reading methods fail due to invalid data.
Thrown by reading methods when there are not enough bytes to read the required value.
Reads an value from:
Some value between and ,
Some value between and ,
or any of the other MsgPack integer types.
The value.
Thrown when the value exceeds what can be stored in the returned type.
Reads an value from:
Some value between and ,
Some value between and ,
or any of the other MsgPack integer types.
The value.
Thrown when the value exceeds what can be stored in the returned type.
Reads an value from:
Some value between and ,
Some value between and ,
or any of the other MsgPack integer types.
The value.
Thrown when the value exceeds what can be stored in the returned type.
Reads an value from:
Some value between and ,
Some value between and ,
or any of the other MsgPack integer types.
The value.
Thrown when the value exceeds what can be stored in the returned type.
Reads an value from:
Some value between and ,
Some value between and ,
or any of the other MsgPack integer types.
The value.
Thrown when the value exceeds what can be stored in the returned type.
Reads an value from:
Some value between and ,
Some value between and ,
or any of the other MsgPack integer types.
The value.
Thrown when the value exceeds what can be stored in the returned type.
Reads an value from:
Some value between and ,
Some value between and ,
or any of the other MsgPack integer types.
The value.
Thrown when the value exceeds what can be stored in the returned type.
Reads an value from:
Some value between and ,
Some value between and ,
or any of the other MsgPack integer types.
The value.
Thrown when the value exceeds what can be stored in the returned type.
The reader over the sequence.
Initializes a new instance of the struct.
The buffer to read from.
Initializes a new instance of the struct.
The sequence to read from.
Gets or sets the cancellation token for this deserialization operation.
Gets or sets the present depth of the object graph being deserialized.
Gets the originally supplied to the constructor.
Gets the current position of the reader within .
Gets the number of bytes consumed by the reader.
Gets a value indicating whether the reader is at the end of the sequence.
Gets a value indicating whether the reader position is pointing at a nil value.
Thrown if the end of the sequence provided to the constructor is reached before the expected end of the data.
Gets the next message pack type to be read.
Gets the type of the next MessagePack block.
Thrown if the end of the sequence provided to the constructor is reached before the expected end of the data.
See for valid message pack codes and ranges.
Initializes a new instance of the struct,
with the same settings as this one, but with its own buffer to read from.
The sequence to read from.
The new reader.
Creates a new at this reader's current position.
The two readers may then be used independently without impacting each other.
A new .
Since this is a struct, copying it completely is as simple as returning itself
from a property that isn't a "ref return" property.
Advances the reader to the next MessagePack primitive to be read.
The entire primitive is skipped, including content of maps or arrays, or any other type with payloads.
To get the raw MessagePack sequence that was skipped, use instead.
Advances the reader to the next MessagePack primitive to be read.
if the entire structure beginning at the current is found in the ; otherwise.
The entire primitive is skipped, including content of maps or arrays, or any other type with payloads.
To get the raw MessagePack sequence that was skipped, use instead.
WARNING: when false is returned, the position of the reader is undefined.
Reads a value.
A nil value.
Reads nil if it is the next token.
if the next token was nil; otherwise.
Thrown if the end of the sequence provided to the constructor is reached before the expected end of the data.
Reads a sequence of bytes without any decoding.
The number of bytes to read.
The sequence of bytes read.
Reads the next MessagePack primitive.
The raw MessagePack sequence.
The entire primitive is read, including content of maps or arrays, or any other type with payloads.
Read an array header from
,
, or
some built-in code between and .
Thrown if the header cannot be read in the bytes left in the
or if it is clear that there are insufficient bytes remaining after the header to include all the elements the header claims to be there.
Thrown if a code other than an array header is encountered.
Reads an array header from
,
, or
some built-in code between and
if there is sufficient buffer to read it.
Receives the number of elements in the array if the entire array header could be read.
if there was sufficient buffer and an array header was found; if the buffer incompletely describes an array header.
Thrown if a code other than an array header is encountered.
When this method returns the position of the reader is left in an undefined position.
The caller is expected to recreate the reader (presumably with a longer sequence to read from) before continuing.
Read a map header from
,
, or
some built-in code between and .
The number of key=value pairs in the map.
Thrown if the header cannot be read in the bytes left in the
or if it is clear that there are insufficient bytes remaining after the header to include all the elements the header claims to be there.
Thrown if a code other than an map header is encountered.
Reads a map header from
,
, or
some built-in code between and
if there is sufficient buffer to read it.
Receives the number of key=value pairs in the map if the entire map header can be read.
if there was sufficient buffer and a map header was found; if the buffer incompletely describes an map header.
Thrown if a code other than an map header is encountered.
When this method returns the position of the reader is left in an undefined position.
The caller is expected to recreate the reader (presumably with a longer sequence to read from) before continuing.
Reads a boolean value from either a or .
The value.
Reads a from any of:
,
,
or anything between and .
A character.
Reads an value from any value encoded with:
,
,
,
,
,
,
,
,
,
or some value between and ,
or some value between and .
The value.
Reads an value from any value encoded with:
,
,
,
,
,
,
,
,
,
,
or some value between and ,
or some value between and .
The value.
Reads a from a value encoded with
,
, or
.
Expects extension type code .
The value.
Reads a from a value encoded with
,
,
.
Expects extension type code .
The extension header that was already read.
The value.
Reads a span of bytes, whose length is determined by a header of one of these types:
,
,
,
or to support OldSpec compatibility:
,
,
or something between and .
A sequence of bytes, or if the read token is .
The data is a slice from the original sequence passed to this reader's constructor.
Reads a string of bytes, whose length is determined by a header of one of these types:
,
,
,
or a code between and .
The sequence of bytes, or if the read token is .
The data is a slice from the original sequence passed to this reader's constructor.
Reads a string of bytes, whose length is determined by a header of one of these types:
,
,
,
or a code between and .
Receives the span to the string.
if the string is contiguous in memory such that it could be set as a single span.
if the read token is or the string is not in a contiguous span.
Callers should generally be prepared for a result and failover to calling
which can represent a result and handle strings that are not contiguous in memory.
Reads a string, whose length is determined by a header of one of these types:
,
,
,
or a code between and .
A string, or if the current msgpack token is .
Reads an extension format header, based on one of these codes:
,
,
,
,
,
,
, or
.
The extension header.
Thrown if the header cannot be read in the bytes left in the
or if it is clear that there are insufficient bytes remaining after the header to include all the bytes the header claims to be there.
Thrown if a code other than an extension format header is encountered.
Reads an extension format header, based on one of these codes:
,
,
,
,
,
,
, or
if there is sufficient buffer to read it.
Receives the extension header if the remaining bytes in the fully describe the header.
The number of key=value pairs in the map.
Thrown if a code other than an extension format header is encountered.
When this method returns the position of the reader is left in an undefined position.
The caller is expected to recreate the reader (presumably with a longer sequence to read from) before continuing.
Reads an extension format header and data, based on one of these codes:
,
,
,
,
,
,
, or
.
The extension format.
The data is a slice from the original sequence passed to this reader's constructor.
Throws an exception indicating that there aren't enough bytes remaining in the buffer to store
the promised data.
Throws an exception indicating that there aren't enough bytes remaining in the buffer to store
the promised data.
Throws an explaining an unexpected code was encountered.
The code that was encountered.
Nothing. This method always throws.
Throws if a condition is false.
A boolean value.
Thrown if is .
Gets the length of the next string.
Receives the length of the next string, if there were enough bytes to read it.
if there were enough bytes to read the length of the next string; otherwise.
Gets the length of the next string.
The length of the next string.
Reads a string assuming that it is spread across multiple spans in the .
The length of the string to be decoded, in bytes.
The decoded string.
High-Level API of MessagePack for C#.
A convenience wrapper around that assumes all generic type arguments are
causing the type of top-level objects to be recorded in the MessagePack stream and thus deserialized to the original type automatically.
Gets or sets the default set of options to use when not explicitly specified for a method call.
The default value is .
This is an AppDomain or process-wide setting.
If you're writing a library, you should NOT set or rely on this property but should instead pass
in (or the required options) explicitly to every method call
to guarantee appropriate behavior in any application.
If you are an app author, realize that setting this property impacts the entire application so it should only be
set once, and before any use of occurs.
Gets or sets the default set of options to use when not explicitly specified for a method call.
The default value is .
This is an AppDomain or process-wide setting.
If you're writing a library, you should NOT set or rely on this property but should instead pass
in (or the required options) explicitly to every method call
to guarantee appropriate behavior in any application.
If you are an app author, realize that setting this property impacts the entire application so it should only be
set once, and before any use of occurs.
A thread-local, recyclable array that may be used for short bursts of code.
Serializes a given value with the specified buffer writer.
The buffer writer to serialize with.
The value to serialize.
The options. Use to use default options.
A cancellation token.
Thrown when any error occurs during serialization.
Serializes a given value with the specified buffer writer.
The buffer writer to serialize with.
The value to serialize.
The options. Use to use default options.
Thrown when any error occurs during serialization.
Serializes a given value with the specified buffer writer.
The value to serialize.
The options. Use to use default options.
A cancellation token.
A byte array with the serialized value.
Thrown when any error occurs during serialization.
Serializes a given value to the specified stream.
The stream to serialize to.
The value to serialize.
The options. Use to use default options.
A cancellation token.
Thrown when any error occurs during serialization.
Serializes a given value to the specified stream.
The stream to serialize to.
The value to serialize.
The options. Use to use default options.
A cancellation token.
A task that completes with the result of the async serialization operation.
Thrown when any error occurs during serialization.
Deserializes a value of a given type from a sequence of bytes.
The type of value to deserialize.
The sequence to deserialize from.
The options. Use to use default options.
A cancellation token.
The deserialized value.
Thrown when any error occurs during deserialization.
Deserializes a value of a given type from a sequence of bytes.
The type of value to deserialize.
The reader to deserialize from.
The options. Use to use default options.
The deserialized value.
Thrown when any error occurs during deserialization.
Deserializes a value of a given type from a sequence of bytes.
The type of value to deserialize.
The buffer to deserialize from.
The options. Use to use default options.
A cancellation token.
The deserialized value.
Thrown when any error occurs during deserialization.
Deserializes a value of a given type from a sequence of bytes.
The type of value to deserialize.
The memory to deserialize from.
The number of bytes read.
A cancellation token.
The deserialized value.
Thrown when any error occurs during deserialization.
Deserializes a value of a given type from a sequence of bytes.
The type of value to deserialize.
The memory to deserialize from.
The options. Use to use default options.
The number of bytes read.
A cancellation token.
The deserialized value.
Thrown when any error occurs during deserialization.
Deserializes the entire content of a .
The type of value to deserialize.
The stream to deserialize from.
The entire stream will be read, and the first msgpack token deserialized will be returned.
If is true on the stream, its position will be set to just after the last deserialized byte.
The options. Use to use default options.
A cancellation token.
The deserialized value.
Thrown when any error occurs during deserialization.
If multiple top-level msgpack data structures are expected on the stream, use instead.
Deserializes the entire content of a .
The type of value to deserialize.
The stream to deserialize from.
The entire stream will be read, and the first msgpack token deserialized will be returned.
If is true on the stream, its position will be set to just after the last deserialized byte.
The options. Use to use default options.
A cancellation token.
The deserialized value.
Thrown when any error occurs during deserialization.
If multiple top-level msgpack data structures are expected on the stream, use instead.
Performs LZ4 compression or decompression.
The input for the operation.
The buffer to write the result of the operation.
The LZ4 codec transformation.
The number of bytes written to the .
Serialize an object to JSON string.
Thrown if an error occurs during serialization.
Serialize an object to JSON string.
Thrown if an error occurs during serialization.
Convert a message-pack binary to a JSON string.
Thrown if an error occurs while reading the messagepack data or writing out the JSON.
Convert a message-pack binary to a JSON string.
Thrown if an error occurs while reading the messagepack data or writing out the JSON.
Convert a message-pack binary to a JSON string.
Thrown if an error occurs while reading the messagepack data or writing out the JSON.
Translates the given JSON to MessagePack.
Translates the given JSON to MessagePack.
Translates the given JSON to MessagePack.
Helper method used by reflection.
Helper method used by reflection.
Reads one or more messagepack data structures from a .
This class is *not* thread-safe. Do not call more than one member at once and be sure any call completes (including asynchronous tasks)
before calling the next one.
Reads the next messagepack array header.
A cancellation token.
A task whose result is the length of the next array from the stream.
Any extra bytes read (between the last complete message and the end of the stream) will be available via the property.
Reads the next messagepack array and produces each element individually.
A cancellation token.
A task whose result is the next whole data structure from the stream, or if the stream ends.
The returned sequence is valid until this is disposed or
until this method is called again, whichever comes first.
When is the result of the returned task,
any extra bytes read (between the last complete message and the end of the stream) will be available via the property.
Reads an array header from if there are enough bytes to do so.
Receives the length of the array, if its header could be read.
if the array header was found and complete; if there were insufficient bytes to read the header.
Thrown if the next msgpack structure is not an array header.
Reads the next messagepack map header.
A cancellation token.
A task whose result is the size of the next map from the stream.
Any extra bytes read (between the last complete message and the end of the stream) will be available via the property.
Reads a map header from if there are enough bytes to do so.
Receives the size of the map, if its header could be read.
if the map header was found and complete; if there were insufficient bytes to read the header.
Thrown if the next msgpack structure is not a map header.
Initializes a new instance of the class.
The stream to read from. This stream will be disposed of when this is disposed.
Initializes a new instance of the class.
The stream to read from.
If true, leaves the stream open after this is disposed; otherwise, false.
Initializes a new instance of the class.
The stream to read from.
If true, leaves the stream open after this is disposed; otherwise, false.
The pool to rent a object from.
Gets any bytes that have been read since the last complete message returned from .
Gets the sequence that we read data from the into.
Reads the next whole (top-level) messagepack data structure.
A cancellation token.
A task whose result is the next whole data structure from the stream, or if the stream ends.
The returned sequence is valid until this is disposed or
until this method is called again, whichever comes first.
When is the result of the returned task,
any extra bytes read (between the last complete message and the end of the stream) will be available via the property.
Arranges for the next read operation to start by reading from the underlying
instead of any data buffered from a previous read.
This is appropriate if the underlying has been repositioned such that
any previously buffered data is no longer applicable to what the caller wants to read.
Disposes of managed and unmanaged resources.
if this instance is being disposed; if it is being finalized.
Recycle memory from a previously returned message.
Read more data from the stream into the buffer.
A cancellation token.
if more data was read; if the end of the stream had already been reached.
Checks whether the content in include a complete messagepack structure.
Receives the sequence of the first complete data structure found, if any.
if a complete data structure was found; otherwise.
A fast access struct that wraps .
The underlying .
The result of the last call to , less any bytes already "consumed" with .
Backing field for the property.
The result of the last call to , less any bytes already "consumed" with .
The number of uncommitted bytes (all the calls to since the last call to ).
The total number of bytes written with this writer.
Backing field for the property.
Initializes a new instance of the struct.
The to be wrapped.
Initializes a new instance of the struct.
The pool from which to draw an if required..
An array to start with so we can avoid accessing the if possible.
Gets the result of the last call to .
Gets the total number of bytes written with this writer.
Gets the underlying this instance.
Calls on the underlying writer
with the number of uncommitted bytes.
Used to indicate that part of the buffer has been written to.
The number of bytes written to.
Copies the caller's buffer into this writer and calls with the length of the source buffer.
The buffer to copy in.
Acquires a new buffer if necessary to ensure that some given number of bytes can be written to a single buffer.
The number of bytes that must be allocated in a single buffer.
Gets the span to the bytes written if they were never committed to the underlying buffer writer.
Gets a fresh span to write to, with an optional minimum size.
The minimum size for the next requested buffer.
Copies the caller's buffer into this writer, potentially across multiple buffers from the underlying writer.
The buffer to copy into this writer.
Allows querying for a formatter for serializing or deserializing a particular .
Gets an instance that can serialize or deserialize some type .
The type of value to be serialized or deserialized.
A formatter, if this resolver supplies one for type ; otherwise .
Unsafe LZ4 codec.
Memory usage formula : N->2^N Bytes (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB; etc.)
Increasing memory usage improves compression ratio
Reduced memory usage can improve speed, due to cache effect
Default value is 14, for 16KB, which nicely fits into Intel x86 L1 cache.
Decreasing this value will make the algorithm skip faster data segments considered "incompressible"
This may decrease compression ratio dramatically, but will be faster on incompressible data
Increasing this value will make the algorithm search more before declaring a segment "incompressible"
This could improve compression a bit, but will be slower on incompressible data
The default value (6) is recommended.
Gets maximum the length of the output.
Length of the input.
Maximum number of bytes needed for compressed buffer.
Encodes the specified input.
The input.
The output.
Number of bytes written.
Decodes the specified input.
The input.
The output.
Number of bytes written.
Copies block of memory.
The source.
The destination.
The length (in bytes).
Copies block of memory.
The source.
The destination.
The length (in bytes).
https://github.com/msgpack/msgpack/blob/master/spec.md#serialization-type-to-format-conversion.
The core type codes as defined by msgpack.
Checks whether a given messagepack code represents an integer that might include a sign (i.e. might be a negative number).
The messagepack code.
A boolean value.
The officially defined messagepack extension type codes.
Identifies the various compression schemes which might be applied at the msgpack level.
No compression is applied at the msgpack level.
Compresses an entire msgpack sequence as a single lz4 block format.
This is the simple compression that achieves best compression ratio,
at the cost of copying the entire sequence when necessary to get contiguous memory.
Uses msgpack type code ext99 and is compatible with v1 of this library.
See also ThisLibraryExtensionTypeCodes.Lz4Block.
Compresses an entire msgpack sequence as a array of lz4 block format.
This is compressed/decompressed in chunks that do not consume LOH,
but the compression ratio is slightly sacrificed.
Uses msgpack type code ext98 in array.
See also ThisLibraryExtensionTypeCodes.Lz4BlockArray.
Extensions for .
Settings related to security, particularly relevant when deserializing data from untrusted sources.
Gets an instance preconfigured with settings that omit all protections. Useful for deserializing fully-trusted and valid msgpack sequences.
Gets an instance preconfigured with protections applied with reasonable settings for deserializing untrusted msgpack sequences.
Initializes a new instance of the class
with properties copied from a provided template.
The template to copy from.
Gets a value indicating whether data to be deserialized is untrusted and thus should not be allowed to create
dictionaries or other hash-based collections unless the hashed type has a hash collision resistant implementation available.
This can mitigate some denial of service attacks when deserializing untrusted code.
The value is for and for .
Gets the maximum depth of an object graph that may be deserialized.
This value can be reduced to avoid a stack overflow that would crash the process when deserializing a msgpack sequence designed to cause deep recursion.
A very short callstack on a thread with 1MB of total stack space might deserialize ~2000 nested arrays before crashing due to a stack overflow.
Since stack space occupied may vary by the kind of object deserialized, a conservative value for this property to defend against stack overflow attacks might be 500.
Gets a copy of these options with the property set to a new value.
The new value for the property.
The new instance; or the original if the value is unchanged.
Gets a copy of these options with the property set to a new value.
The new value for the property.
The new instance; or the original if the value is unchanged.
Gets an that is suitable to use with a hash-based collection.
The type of key that will be hashed in the collection.
The to use.
When is active, this will be a collision resistant instance which may reject certain key types.
When is not active, this will be .
Gets an that is suitable to use with a hash-based collection.
The to use.
When is active, this will be a collision resistant instance which may reject certain key types.
When is not active, this will be .
Returns a hash collision resistant equality comparer.
The type of key that will be hashed in the collection.
A hash collision resistant equality comparer.
Checks the depth of the deserializing graph and increments it by 1.
The reader that is involved in deserialization.
Callers should decrement after exiting that edge in the graph.
Thrown if is already at or exceeds .
Rather than wrap the body of every method,
this should wrap *calls* to these methods. They need not appear in pure "thunk" methods that simply delegate the deserialization to another formatter.
In this way, we can avoid repeatedly incrementing and decrementing the counter when deserializing each element of a collection.
Returns a hash collision resistant equality comparer.
A hash collision resistant equality comparer.
Creates a new instance that is a copy of this one.
Derived types should override this method to instantiate their own derived type.
A hash collision resistant implementation of .
The type of key that will be hashed.
A special hash-resistent equality comparer that defers picking the actual implementation
till it can check the runtime type of each value to be hashed.
An exception thrown during serializing an object graph or deserializing a messagepack sequence.
Initializes a new instance of the class.
Initializes a new instance of the class.
The exception message.
Initializes a new instance of the class.
The exception message.
The inner exception.
Initializes a new instance of the class.
Serialization info.
Serialization context.
An immutable description of options for running the .
A collection of known dangerous types that are not expected in a typical MessagePack stream,
and thus are rejected by the default implementation of .
Gets a good default set of options that uses the and no compression.
Initializes a new instance of the class.
Initializes a new instance of the class
with members initialized from an existing instance.
The options to copy from.
Gets the resolver to use for complex types.
An instance of . Never .
Thrown if an attempt is made to set this property to .
Gets the compression scheme to apply to serialized sequences.
When set to something other than ,
deserialization can still work on uncompressed sequences,
and serialization may not compress if msgpack sequences are short enough that compression would not likely be advantageous.
Gets the length a serialized msgpack result must equal or exceed before is applied.
The default value is 64.
When compression is not applied due to a short serialized result, deserialization will still succeed
even if is set to something other than .
Gets the size of contiguous memory blocks in bytes that may be allocated for buffering purposes.
The default value is 1MB.
Larger values may perform a bit faster, but may result in adding a runtime perf tax due to using the
Large Object Heap.
Gets a value indicating whether to serialize with set to some value
causing messagepack spec compliance to be explicitly set to the old or new format.
A null value means the 's default or previous setting will be used.
A non-null value will be applied to the property for the duration of a
serialization and then reverted to its prior setting.
Reading always supports both new and old spec.
Gets a value indicating whether serialization should omit assembly version, culture and public key token metadata when using the typeless formatter.
The default value is .
Gets a value indicating whether deserialization may instantiate types from an assembly with a different version if a matching version cannot be found.
The default value is .
Gets the security-related options for deserializing messagepack sequences.
The default value is to use .
Gets a thread-safe pool of reusable objects.
The default value is the instance.
Gets a type given a string representation of the type.
The name of the type to load. This is typically the but may use the assembly's simple name.
The loaded type or if no matching type could be found.
Checks whether a given type may be deserialized.
The type to be instantiated.
Thrown if the is not allowed to be deserialized.
This method provides a means for an important security mitigation when using the Typeless formatter to prevent untrusted messagepack from
deserializing objects that may be harmful if instantiated, disposed or finalized.
The default implementation throws for only a few known dangerous types.
Applications that deserialize from untrusted sources should override this method and throw if the type is not among the expected set.
Gets a copy of these options with the property set to a new value.
The new value for the .
The new instance; or the original if the value is unchanged.
Gets a copy of these options with the property set to a new value.
The new value for the property.
The new instance; or the original if the value is unchanged.
Gets a copy of these options with the property set to a new value.
The new value for the property. Must be a positive integer.
The new instance; or the original if the value is unchanged.
Gets a copy of these options with the property set to a new value.
The new value for the property. Must be at least 256.
The new instance; or the original if the value is unchanged.
Gets a copy of these options with the property set to a new value.
The new value for the .
The new instance; or the original if the value is unchanged.
Gets a copy of these options with the property set to a new value.
The new value for the property.
The new instance; or the original if the value is unchanged.
Gets a copy of these options with the property set to a new value.
The new value for the property.
The new instance; or the original if the value is unchanged.
Gets a copy of these options with the property set to a new value.
The new value for the property.
The new instance; or the original if the value is unchanged.
Gets a copy of these options with the property set to a new value.
The new value for the property.
The new instance.
Creates a clone of this instance with the same properties set.
The cloned instance. Guaranteed to be a new instance.
Thrown if this instance is a derived type that doesn't override this method.
A primitive types writer for the MessagePack format.
The MessagePack spec..
The writer to use.
Initializes a new instance of the struct.
The writer to use.
Initializes a new instance of the struct.
The pool from which to draw an if required..
An array to start with so we can avoid accessing the if possible.
Gets or sets the cancellation token for this serialization operation.
Gets or sets a value indicating whether to write in old spec compatibility mode.
Initializes a new instance of the struct,
with the same settings as this one, but with its own buffer writer.
The writer to use for the new instance.
The new writer.
Ensures everything previously written has been flushed to the underlying .
Writes a value.
Copies bytes directly into the message pack writer.
The span of bytes to copy from.
Copies bytes directly into the message pack writer.
The span of bytes to copy from.
Write the length of the next array to be written in the most compact form of
,
, or
.
The number of elements that will be written in the array.
Write the length of the next array to be written in the most compact form of
,
, or
.
The number of elements that will be written in the array.
Write the length of the next map to be written in the most compact form of
,
, or
.
The number of key=value pairs that will be written in the map.
Write the length of the next map to be written in the most compact form of
,
, or
.
The number of key=value pairs that will be written in the map.
Writes a value using a 1-byte code when possible, otherwise as .
The value.
Writes a value using .
The value.
Writes an 8-bit value using a 1-byte code when possible, otherwise as .
The value.
Writes an 8-bit value using .
The value.
Writes a value using a 1-byte code when possible, otherwise as or .
The value.
Writes a value using .
The value.
Writes a using a built-in 1-byte code when within specific MessagePack-supported ranges,
or the most compact of
,
,
, or
.
The value to write.
Writes a using .
The value to write.
Writes an using a built-in 1-byte code when within specific MessagePack-supported ranges,
or the most compact of
,
, or
.
The value to write.
Writes an using .
The value to write.
Writes an using a built-in 1-byte code when within specific MessagePack-supported ranges,
or the most compact of
,
,
,
,
,
.
The value to write.
Writes an using .
The value to write.
Writes an using a built-in 1-byte code when within specific MessagePack-supported ranges,
or the most compact of
,
,
,
,
,
.
The value to write.
Writes an using .
The value to write.
Writes an using a built-in 1-byte code when within specific MessagePack-supported ranges,
or the most compact of
,
,
,
,
,
,
,
.
The value to write.
Writes a using .
The value to write.
Writes a value using either or .
The value.
Writes a value using a 1-byte code when possible, otherwise as or .
The value.
Writes a value.
The value.
Writes a value.
The value.
Writes a using the message code .
The value to write.
Thrown when is true because the old spec does not define a format.
Writes a [], prefixed with a length encoded as the smallest fitting from:
,
,
,
or if is .
The array of bytes to write. May be .
Writes a span of bytes, prefixed with a length encoded as the smallest fitting from:
,
, or
.
The span of bytes to write.
When is , the msgpack code used is , or instead.
Writes a sequence of bytes, prefixed with a length encoded as the smallest fitting from:
,
, or
.
The span of bytes to write.
When is , the msgpack code used is , or instead.
Writes the header that precedes a raw binary sequence with a length encoded as the smallest fitting from:
,
, or
.
The length of bytes that will be written next.
The caller should use or
after calling this method to actually write the content.
Alternatively a single call to or will take care of the header and content in one call.
When is , the msgpack code used is , or instead.
Writes out an array of bytes that (may) represent a UTF-8 encoded string, prefixed with the length using one of these message codes:
,
,
, or
.
The bytes to write.
Writes out an array of bytes that (may) represent a UTF-8 encoded string, prefixed with the length using one of these message codes:
,
,
, or
.
The bytes to write.
Writes out the header that may precede a UTF-8 encoded string, prefixed with the length using one of these message codes:
,
,
, or
.
The number of bytes in the string that will follow this header.
The caller should use or
after calling this method to actually write the content.
Alternatively a single call to or will take care of the header and content in one call.
Writes out a , prefixed with the length using one of these message codes:
,
,
,
,
or if the is .
The value to write. May be null.
Writes out a , prefixed with the length using one of these message codes:
,
,
,
.
The value to write.
Writes the extension format header, using the smallest one of these codes:
,
,
,
,
,
,
, or
.
The extension header.
Writes an extension format, using the smallest one of these codes:
,
,
,
,
,
,
, or
.
The extension data.
Gets memory where raw messagepack data can be written.
The size of the memory block required.
The span of memory to write to. This *may* exceed .
After initializing the resulting memory, always follow up with a call to .
This is similar in purpose to
but provides uninitialized memory for the caller to write to instead of copying initialized memory from elsewhere.
Commits memory previously returned from as initialized.
The number of bytes initialized with messagepack data from the previously returned span.
Writes a 16-bit integer in big endian format.
The integer.
Writes a 32-bit integer in big endian format.
The integer.
Writes a 64-bit integer in big endian format.
The integer.
Estimates the length of the header required for a given string.
The length of the string to be written, in characters.
Receives the guaranteed length of the returned buffer.
Receives the offset within the returned buffer to write the encoded string to.
A reference to the first byte in the buffer.
Finalizes an encoding of a string.
A pointer obtained from a prior call to .
The offset obtained from a prior call to .
The number of bytes used to actually encode the string.
Get the number of bytes required to encode a value in msgpack.
The value to encode.
The byte length; One of 1, 2, 3, 5 or 9 bytes.
Get the number of bytes required to encode a value in msgpack.
The value to encode.
The byte length; One of 1, 2, 3, 5 or 9 bytes.
Special behavior for running on the mono runtime.
Gets a value indicating whether the mono runtime is executing this code.
A lock that we enter on mono when generating dynamic types.
The method to call within the expression of a using statement whose block surrounds all Ref.Emit code.
The value to be disposed of to exit the Ref.Emit lock.
This is a no-op except when running on Mono.
Mono's implementation of Ref.Emit is not thread-safe so we have to lock around all use of it
when using that runtime.
Get formatter from .
The singleton instance that can be used.
The singleton instance that can be used.
A base class for classes that want to cache their responses for perf reasons.
The cache of types to their formatters.
Looks up a formatter for a type that has not been previously cached.
The type to be formatted.
The formatter to use, or if none found.
Represents a collection of formatters and resolvers acting as one.
This class is not thread-safe for mutations. It is thread-safe when not being written to.
Initializes a new instance of an with the specified formatters and sub-resolvers.
A list of instances of to prefer (above the ).
The formatters are searched in the order given, so if two formatters support serializing the same type, the first one is used.
May not be null, but may be .
A list of resolvers to use for serializing types for which does not include a formatter.
The resolvers are searched in the order given, so if two resolvers support serializing the same type, the first one is used.
May not be null, but may be .
An instance of .
Initializes a new instance of the class.
The singleton instance that can be used.
A instance with this formatter pre-configured.
EnumResolver by dynamic code generation, serialized underlying type.
The singleton instance that can be used.
The singleton instance that can be used.
ObjectResolver by dynamic code generation.
The singleton instance that can be used.
A instance with this formatter pre-configured.
ObjectResolver by dynamic code generation, allow private member.
ObjectResolver by dynamic code generation, no needs MessagePackObject attribute and serialized key as string.
ObjectResolver by dynamic code generation, no needs MessagePackObject attribute and serialized key as string, allow private member.
UnionResolver by dynamic code generation.
The singleton instance that can be used.
A instance with this formatter pre-configured.
A resolver for use when deserializing MessagePack data where the schema is not known at compile-time
such that strong-types can be instantiated.
Instead, is used wherever a MessagePack map is encountered.
The resolver to use to deserialize into C#'s dynamic keyword.
This resolver includes more than just the .
A set of options that includes the
and puts the deserializer into mode.
The singleton instance that can be used.
A instance with this formatter pre-configured.
The singleton instance that can be used.
The singleton instance that can be used.
The singleton instance that can be used.
A instance with this formatter pre-configured.
Default composited resolver, builtin -> attribute -> dynamic enum -> dynamic generic -> dynamic union -> dynamic object -> primitive.
The singleton instance that can be used.
A instance with this formatter pre-configured.
The singleton instance that can be used.
A instance with this formatter pre-configured.
The singleton instance that can be used.
A instance with this formatter pre-configured.
The singleton instance that can be used.
A instance with this formatter pre-configured.
Singleton version of , which can register a collection of formatters and resolvers to a single instance.
Initializes a singleton instance with the specified formatters.
This method can only call before use StaticCompositeResolver.Instance.GetFormatter.
If call twice in the Register methods, registered formatters and resolvers will be overridden.
A list of instances of .
The formatters are searched in the order given, so if two formatters support serializing the same type, the first one is used.
Initializes a singleton instance with the specified formatters and sub-resolvers.
This method can only call before use StaticCompositeResolver.Instance.GetFormatter.
If call twice in the Register methods, registered formatters and resolvers will be overridden.
A list of resolvers to use for serializing types.
The resolvers are searched in the order given, so if two resolvers support serializing the same type, the first one is used.
Initializes a singleton instance with the specified formatters and sub-resolvers.
This method can only call before use StaticCompositeResolver.Instance.GetFormatter.
If call twice in the Register methods, registered formatters and resolvers will be overridden.
A list of instances of .
The formatters are searched in the order given, so if two formatters support serializing the same type, the first one is used.
A list of resolvers to use for serializing types for which does not include a formatter.
The resolvers are searched in the order given, so if two resolvers support serializing the same type, the first one is used.
Gets an instance that can serialize or deserialize some type .
The type of value to be serialized or deserialized.
A formatter, if this resolver supplies one for type ; otherwise .
Embeds the full name of .NET types for typed fields/collection items
Preserves .NET timezone.
The singleton instance that can be used.
A instance with this formatter pre-configured.
A *private* list of resolvers. If we ever want to expose any of these (so the user can adjust settings, etc.)
then we must make this an instance collection instead of a static collection so that each consumer can have their own settings.
Used for `object` fields/collections, ex: var arr = new object[] { 1, "a", new Model() };
The runtime type of value in object field, should be covered by one of resolvers in complex/standard resolver.
should be placed before DynamicObjectTypeFallbackResolver and in resolvers list.
Deserializer uses Namespace.TypeName, AssemblyName to get runtime type in destination app, so that combination must be present in destination app.
Serialized binary is valid MessagePack binary used ext-format and custom typecode(100).
Inside ext - assembly qualified type name, and serialized object.
The singleton instance that can be used.
A instance with this formatter pre-configured.
A thread-safe, alloc-free reusable object pool.
A thread-safe pool of reusable objects.
The value to use for .
Individual users that want a different value for this can modify the setting on the rented
or by supplying their own .
We use 32KB so that when LZ4Codec.MaximumOutputLength is used on this length it does not require a
buffer that would require the Large Object Heap.
The array pool which we share with all objects created by this instance.
Initializes a new instance of the class.
We use a that allows every processor to be involved in messagepack serialization concurrently,
plus one nested serialization per processor (since LZ4 and sometimes other nested serializations may exist).
Initializes a new instance of the class.
The maximum size to allow the pool to grow.
We allow 100 arrays to be shared (instead of the default 50) and reduce the max array length from the default 1MB to something more reasonable for our expected use.
Initializes a new instance of the class.
The maximum size to allow the pool to grow.
Array pool that will be used.
Gets an instance of
This is taken from the recycled pool if one is available; otherwise a new one is created.
The rental tracker that provides access to the object as well as a means to return it.
Gets the recyclable object.
Returns the recyclable object to the pool.
The instance is cleaned first, if a clean delegate was provided.
It is dropped instead of being returned to the pool if the pool is already at its maximum size.
A value indicating whether we're using (as opposed to .
Backing for the entire sequence when we're not using .
The position at the start of the .
The position at the end of the .
Backing for the entire sequence when we're not using .
A value indicating whether there is unread data remaining.
The total number of elements in the sequence.
Initializes a new instance of the struct
over the given .
Initializes a new instance of the struct
over the given .
Gets a value indicating whether there is no more data in the .
Gets the underlying for the reader.
Gets the current position in the .
Gets the current segment in the as a span.
Gets the index in the .
Gets the unread portion of the .
Gets the total number of 's processed by the reader.
Gets remaining 's in the reader's .
Gets count of in the reader's .
Peeks at the next value without advancing the reader.
The next value or default if at the end.
False if at the end of the reader.
Read the next value and advance the reader.
The next value or default if at the end.
False if at the end of the reader.
Move the reader back the specified number of items.
Get the next segment with available data, if any.
Move the reader ahead the specified number of items.
Unchecked helper to avoid unnecessary checks where you know count is valid.
Only call this helper if you know that you are advancing in the current span
with valid count and there is no need to fetch the next one.
Move the reader ahead the specified number of items
if there are enough elements remaining in the sequence.
if there were enough elements to advance; otherwise .
Copies data from the current to the given span.
Destination to copy to.
True if there is enough data to copy to the .
Try to read the given type out of the buffer if possible. Warning: this is dangerous to use with arbitrary
structs- see remarks for full details.
IMPORTANT: The read is a straight copy of bits. If a struct depends on specific state of its members to
behave correctly this can lead to exceptions, etc. If reading endian specific integers, use the explicit
overloads such as .
True if successful. will be default if failed (due to lack of space).
Reads an from the next position in the sequence.
The reader to read from.
Receives the value read.
if there was another byte in the sequence; otherwise.
Reads an as big endian.
False if there wasn't enough data for an .
Reads an as big endian.
False if there wasn't enough data for an .
Reads an as big endian.
False if there wasn't enough data for an .
Reads an as big endian.
False if there wasn't enough data for an .
Reads an as big endian.
False if there wasn't enough data for an .
Reads an as big endian.
False if there wasn't enough data for an .
Reads a as big endian.
False if there wasn't enough data for a .
Reads a as big endian.
False if there wasn't enough data for a .
Reads from the stream into a memory buffer.
The stream to read from.
The buffer to read directly into.
The number of bytes actually read.
Reads from the stream into a memory buffer.
The stream to read from.
The buffer to read directly into.
A cancellation token.
The number of bytes actually read.
This method shamelessly copied from the .NET Core 2.1 Stream class: https://github.com/dotnet/coreclr/blob/a113b1c803783c9d64f1f0e946ff9a853e3bc140/src/System.Private.CoreLib/shared/System/IO/Stream.cs#L366-L391.
Writes a span to the stream.
The stream to write to.
The buffer to write.
Writes a span to the stream.
The stream to write to.
The buffer to write.
A cancellation token.
The extension type codes that this library defines for just this library.
For Unity's UnsafeBlitFormatter.
For Unity's UnsafeBlitFormatter.
For Unity's UnsafeBlitFormatter.
For Unity's UnsafeBlitFormatter.
For Unity's UnsafeBlitFormatter.
For Unity's UnsafeBlitFormatter.
For Unity's UnsafeBlitFormatter.
For Unity's UnsafeBlitFormatter.
For Unity's UnsafeBlitFormatter.
For Unity's UnsafeBlitFormatter.
The LZ4 array block compression extension.
The LZ4 single block compression extension.
For the .
Internal utilities and extension methods for various external types.
A value indicating whether we're running on mono.
Gets an enumerator that does not allocate for each entry,
and that doesn't produce the nullable ref annotation warning about unboxing a possibly null value.
Manages a sequence of elements, readily castable as a .
The type of element stored by the sequence.
Instance members are not thread-safe.
Initializes a new instance of the class
that uses a private for recycling arrays.
Initializes a new instance of the class.
The pool to use for recycling backing arrays.
Initializes a new instance of the class.
The pool to use for recycling backing arrays.
Gets or sets the minimum length for any array allocated as a segment in the sequence.
Any non-positive value allows the pool to determine the length of the array.
The default value is 0.
Each time or is called,
previously allocated memory is used if it is large enough to satisfy the length demand.
If new memory must be allocated, the argument to one of these methods typically dictate
the length of array to allocate. When the caller uses very small values (just enough for its immediate need)
but the high level scenario can predict that a large amount of memory will be ultimately required,
it can be advisable to set this property to a value such that just a few larger arrays are allocated
instead of many small ones.
The in use may itself have a minimum array length as well,
in which case the higher of the two minimums dictate the minimum array size that will be allocated.
If is , this value may be automatically increased as the length of a sequence grows.
Gets or sets a value indicating whether the should be
intelligently increased as the length of the sequence grows.
This can help prevent long sequences made up of many very small arrays.
Gets this sequence expressed as a .
A read only sequence representing the data in this object.
Gets the length of the sequence.
Gets the value to display in a debugger datatip.
Expresses this sequence as a .
The sequence to convert.
Removes all elements from the sequence from its beginning to the specified position,
considering that data to have been fully processed.
The position of the first element that has not yet been processed.
This is typically after reading all elements from that instance.
Advances the sequence to include the specified number of elements initialized into memory
returned by a prior call to .
The number of elements written into memory.
Gets writable memory that can be initialized and added to the sequence via a subsequent call to .
The size of the memory required, or 0 to just get a convenient (non-empty) buffer.
The requested memory.
Gets writable memory that can be initialized and added to the sequence via a subsequent call to .
The size of the memory required, or 0 to just get a convenient (non-empty) buffer.
The requested memory.
Adds an existing memory location to this sequence without copying.
The memory to add.
This *may* leave significant slack space in a previously allocated block if calls to
follow calls to or .
Clears the entire sequence, recycles associated memory into pools,
and resets this instance for reuse.
This invalidates any previously produced by this instance.
Clears the entire sequence and recycles associated memory into pools.
This invalidates any previously produced by this instance.
A value indicating whether the element may contain references (and thus must be cleared).
Gets the backing array, when using an instead of a .
Gets the position within where the data starts.
This may be nonzero as a result of calling .
Gets the position within where the data ends.
Gets the tail of memory that has not yet been committed.
Gets the tail of memory that has not yet been committed.
Gets the tracker for the underlying array for this segment, which can be used to recycle the array when we're disposed of.
Will be if using an array pool, in which case the memory is held by .
Gets the full memory owned by the .
Gets the number of elements that are committed in this segment.
Gets the amount of writable bytes in this segment.
It is the amount of bytes between and .
Gets or sets the next segment in the singly linked list of segments.
Gets a value indicating whether this segment refers to memory that came from outside and that we cannot write to nor recycle.
Assigns this (recyclable) segment a new area in memory.
The memory and a means to recycle it.
Assigns this (recyclable) segment a new area in memory.
An array drawn from an .
Assigns this (recyclable) segment a new area in memory.
A memory block obtained from outside, that we do not own and should not recycle.
Clears all fields in preparation to recycle this instance.
Adds a new segment after this one.
The next segment in the linked list.
Commits more elements as written in this segment.
The number of elements written.
Removes some elements from the start of this segment.
The number of elements to ignore from the start of the underlying array.
Throws an if a condition does not evaluate to true.
Throws an if a condition does not evaluate to true.
Nothing. This method always throws.
Throws an exception if the specified parameter's value is null.
The type of the parameter.
The value of the argument.
The name of the parameter to include in any thrown exception.
The value of the parameter.
Thrown if is .
Throws an ArgumentException if a condition does not evaluate to true.
Throws an ArgumentException if a condition does not evaluate to true.
Throws an ArgumentException if a condition does not evaluate to true.
Throws an ArgumentException if a condition does not evaluate to true.
Common runtime checks that throw exceptions upon failure.
Throws an if a condition is false.