RMP - Rust MessagePack
RMP is a pure Rust MessagePack implementation.
Usage
To use rmp, first add this to your Cargo.toml:
[]
= "0.1.0"
Then, add this to your crate root:
extern crate rmp as msgpack;
Features
-
Convenient API
RMP is designed to be lightweight and straightforward. There are low-level API, which gives you full control on data encoding/decoding process and makes no heap allocations. On the other hand there are high-level API, which provides you convenient interface using Rust standard library and compiler reflection, allowing to encode/decode structures using
deriveattribute. -
Clear error handling
RMP's error system guarantees that you never receive an error enum with unreachable variant.
-
Robust and tested
This project is developed using TDD and CI, so any found bugs will be fixed without breaking existing functionality.
Examples
Let's try to encode a tuple of int and string.
extern crate rmp as msgpack;
extern crate rustc_serialize;
use Encodable;
use Encoder;
RMP also allows to automatically serialize/deserialize custom structures using rustc_serialize reflection. To enable this feature, derive RustcEncodable and RustcDecodable attributes as shown in the following example:
extern crate rmp as msgpack;
extern crate rustc_serialize;
use Encodable;
use Encoder;
Limitations and plans
- Owning
Valuevariant and its encoding/decoding functions. - Non-owning
ValueRefvariant, which can be created from[u8],Cursor<[u8]>etc. and borrows data from it, which makes it absolute zero-copy. - Enum serialization/deserialization.