MessagePack-CSharp is a high-performance binary serializer for .NET that converts C# objects to and from the compact MessagePack format. It uses compile-time source generation to produce AOT-safe formatters and resolvers, eliminating runtime reflection and enabling ahead-of-time compilation scenarios. The serializer encodes object fields as integer indices instead of string keys, producing compact binary output with deterministic field ordering, and provides stack-allocated reader and writer structs for direct encoding and decoding of MessagePack primitives without heap allocations.
The library distinguishes itself through its LZ4 block compression pipeline, which reduces binary size while maintaining high throughput, and its priority-chained resolver composition that allows combining multiple formatter resolvers in a fixed order for fallback and override of serialization logic. It supports version-tolerant deserialization by ignoring unknown keys and applying default values, and can embed full .NET type names into the binary blob for polymorphic serialization of interface-typed or abstract-typed objects. A stream-boundary-aware reader detects consecutive MessagePack structures from a single stream, enabling multiplexed or chunked data processing.
The serializer handles a broad range of data scenarios, including conversion between MessagePack and JSON for debugging and interoperability, serialization of Unity-specific structs like Vector3 and Quaternion, and dynamic or untyped data handling through union attributes. It provides compile-time validation via analyzers to detect incorrect attribute usage, and supports custom IMessagePackFormatter implementations for types requiring special handling. String interning during deserialization reuses repeated string objects to lower memory usage for repetitive data.