🦀 Montycat Serialization Derive
montycat_serialization_derive is a procedural macro library for seamless and efficient binary serialization and runtime schema introspection in Rust.
Built on top of serde and rmp-serde, it provides automatic MessagePack-based serialization and deserialization, as well as reflection-like runtime type checking with RuntimeSchema.
✨ Features
- 🧩 RuntimeSchema — inspect struct fields and types at runtime.
- ⚡ BinaryConvert — derive compact, high-speed binary serialization methods automatically.
- 💪 Powered by serde for flexible data representation.
- 📦 Compatible with rmp-serde (MessagePack format) for compact and efficient binary encoding.
- 🔧 Simple integration — add a single derive macro to your structs.
Requirements
This crate relies on the following dependencies:
serde(withderivefeature enabled)rmp-serdefor MessagePack serialization/deserialization
Make sure to include these dependencies in your Cargo.toml.
Installation
Add the crate to your project's dependencies in Cargo.toml:
[]
= "0.1.6"
= { = "1.0", = ["derive"] }
= "1"
Usage BinaryConvert
Import and setup your struct
use ;
use BinaryConvert;
Then serialize and deserialize easily:
Error Handling
Serialization (convert_to_bytes): If serialization fails, an empty Vec is returned. Deserialization (convert_from_bytes): If deserialization fails, the method returns a default instance of the struct. For this to work, the struct must implement the Default trait.
Use convert_to_bytes_populate_option() and convert_from_bytes_populate_option() to populate Option. Use all the unwrapping Rust methods ( ?, unwrap(), is_none(), is_some(), and so on... ) to uncover value or run check.
Notes
The library uses the MessagePack format, making it compact and efficient for binary data storage or transmission. For additional control over serialization, you can use serde attributes (e.g., #[serde(rename = "...")], #[serde(skip)]).
Usage RuntimeSchema Introspection
Use the RuntimeSchema macro to inspect struct metadata at runtime:
use RuntimeSchema;
// Copy-paste dummy trait only if you do not use Montycat engine
Reflection-like utilities in action:
let user = default;
// 2. Get all field names and types
let all_fields = user.field_names_and_types;
// -> [("id", "String"), ("created_at", "u32"), ("username", "String")]
// 3. Get schema parameters (HashMap + Struct name)
let = schema_params;
// -> ({"id": "String", "created_at": "u32", "username": "String"}, "User")
🧠Design Philosophy
Montycat’s derive macros are built to:
- Maximize performance and compactness with binary serialization.
- Provide type-safe runtime reflection for schema-driven systems.
- Serve as the foundation for the Montycat NoSQL database implementing data mesh infrastructure.
See also:
- Montycat Rust Client:
- Explore the full ecosystem and architecture at https://montygovernance.com