# messagepack-csharp/messagepack-csharp

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/messagepack-csharp-messagepack-csharp).**

6,607 stars · 754 forks · C# · other

## Links

- GitHub: https://github.com/MessagePack-CSharp/MessagePack-CSharp
- awesome-repositories: https://awesome-repositories.com/repository/messagepack-csharp-messagepack-csharp.md

## Topics

`c-sharp` `lz4` `messagepack` `msgpack` `serialization` `serializer` `unity` `xamarin`

## Description

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.

## Tags

### Data & Databases

- [MessagePack Serializers](https://awesome-repositories.com/f/data-databases/high-performance-binary-serialization/messagepack-serializers.md) — Provides high-performance MessagePack binary serialization for .NET objects with customizable resolvers.
- [Version-Tolerant Deserializers](https://awesome-repositories.com/f/data-databases/binary-data-accessors/binary-deserialization/version-tolerant-deserializers.md) — Deserializes binary data with missing or extra fields by ignoring unknown keys and applying defaults.
- [Type-Embedded Binary Codecs](https://awesome-repositories.com/f/data-databases/binary-data-formats/binary-type-codecs/type-embedded-binary-codecs.md) — Embeds full .NET type names into serialized blobs for type-argument-free deserialization. ([source](https://cdn.jsdelivr.net/gh/messagepack-csharp/messagepack-csharp@master/README.md))
- [Binary-to-JSON Converters](https://awesome-repositories.com/f/data-databases/custom-type-converters/json-converters/binary-to-json-converters.md) — Transforms MessagePack binary data into human-readable JSON and back for debugging and interoperability.
- [Data Format Interoperability](https://awesome-repositories.com/f/data-databases/data-format-interoperability.md) — Converts between MessagePack binary and JSON for debugging and interoperability.
- [LZ4 Compression Pipelines](https://awesome-repositories.com/f/data-databases/data-serialization-compression/lz4-compression-pipelines.md) — Applies LZ4 block compression during serialization to reduce binary size with high throughput.
- [Dynamic Serialization](https://awesome-repositories.com/f/data-databases/data-serialization-formats/json-serialization/json-message-serializers/json-protobuf-mapping/dynamic-serialization.md) — Serializes and deserializes objects without predefined schemas via union attributes. ([source](https://cdn.jsdelivr.net/gh/messagepack-csharp/messagepack-csharp@master/README.md))
- [Custom Type Serializers](https://awesome-repositories.com/f/data-databases/data-type-managers/dynamic-type-managers/custom-type-serializers.md) — Allows writing custom IMessagePackFormatter implementations for types needing special handling. ([source](https://cdn.jsdelivr.net/gh/messagepack-csharp/messagepack-csharp@master/README.md))
- [Polymorphic Type Serializers](https://awesome-repositories.com/f/data-databases/data-type-managers/dynamic-type-managers/custom-type-serializers/polymorphic-type-serializers.md) — Embeds .NET type names or uses union attributes to serialize and deserialize polymorphic objects.
- [Type-Embedded Polymorphism](https://awesome-repositories.com/f/data-databases/document-processing-platforms/hierarchy-mapping/polymorphic-type-mapping/type-embedded-polymorphism.md) — Embeds .NET type names in binary for polymorphic deserialization without explicit type arguments.
- [Stream Message Boundary Preservation](https://awesome-repositories.com/f/data-databases/message-ordering-management-systems/stream-message-boundary-preservation.md) — Reads consecutive MessagePack structures from a single stream by detecting boundaries.

### Networking & Communication

- [Primitive Type Encoding](https://awesome-repositories.com/f/networking-communication/binary-data-encoding/primitive-type-encoding.md) — Provides low-level reader and writer structs for direct zero-allocation MessagePack primitive encoding. ([source](https://cdn.jsdelivr.net/gh/messagepack-csharp/messagepack-csharp@master/README.md))

### Programming Languages & Runtimes

- [Object Deserialization](https://awesome-repositories.com/f/programming-languages-runtimes/object-deserialization.md) — Reconstructs C# objects from MessagePack binary with support for immutable types and records. ([source](https://cdn.jsdelivr.net/gh/messagepack-csharp/messagepack-csharp@master/README.md))
- [Object Serialization](https://awesome-repositories.com/f/programming-languages-runtimes/object-serialization.md) — Converts annotated C# classes and structs into compact MessagePack binary using index or string keys. ([source](https://cdn.jsdelivr.net/gh/messagepack-csharp/messagepack-csharp@master/README.md))
- [High-Speed Block Compression](https://awesome-repositories.com/f/programming-languages-runtimes/data-compression-and-decompression/high-speed-block-compression.md) — Applies LZ4 block compression as a serialization layer to reduce binary size.
- [LZ4 Compression Pipelines](https://awesome-repositories.com/f/programming-languages-runtimes/data-compression-and-decompression/high-speed-block-compression/lz4-compression-pipelines.md) — Applies LZ4 block compression during serialization to reduce binary size with high throughput.

### Software Engineering & Architecture

- [Resolver Composition](https://awesome-repositories.com/f/software-engineering-architecture/annotation-driven-configuration/serialization-control/resolver-composition.md) — Combines multiple formatter resolvers in priority order to control type serialization behavior. ([source](https://cdn.jsdelivr.net/gh/messagepack-csharp/messagepack-csharp@master/README.md))
- [Compile-Time Code Generation](https://awesome-repositories.com/f/software-engineering-architecture/compile-time-code-generation.md) — Generates AOT-safe formatters and resolvers at compile time using Roslyn source generators.
- [AOT-Safe Serialization Generators](https://awesome-repositories.com/f/software-engineering-architecture/compile-time-code-generation/aot-safe-serialization-generators.md) — Generates compile-time formatters and resolvers for AOT-safe serialization, eliminating runtime reflection.
- [Zero-Allocation Readers](https://awesome-repositories.com/f/software-engineering-architecture/zero-overhead-abstractions/zero-allocation-awaitables/zero-allocation-readers.md) — Provides stack-allocated reader and writer structs for zero-allocation primitive encoding.
- [Dynamic Object Serializers](https://awesome-repositories.com/f/software-engineering-architecture/type-safe-data-handling/dynamic-object-serializers.md) — Serializes and deserializes objects without predefined schemas, including anonymous and interface-typed objects.

### Web Development

- [Priority-Chained Resolvers](https://awesome-repositories.com/f/web-development/graphql-apis/field-resolvers/resolver-overrides/priority-chained-resolvers.md) — Combines multiple formatter resolvers in priority order for fallback and override of serialization logic.
- [Integer Key Encoders](https://awesome-repositories.com/f/web-development/object-key-serialization/integer-key-encoders.md) — Encodes object fields as integer indices for compact binary output with deterministic ordering.
- [Unity Struct Serializers](https://awesome-repositories.com/f/web-development/cross-platform-development/game-development-frameworks/unity-game-frameworks/unity-struct-serializers.md) — Serializes Unity structs like Vector3 and Quaternion using built-in resolvers for server-client communication. ([source](https://cdn.jsdelivr.net/gh/messagepack-csharp/messagepack-csharp@master/README.md))
- [Custom Serialization Logic](https://awesome-repositories.com/f/web-development/request-body-handling/custom-serialization-logic.md) — Supports custom IMessagePackFormatter implementations for types needing special serialization logic.
