Debian Codegraph @

/

debian rust-rmp-serde 1.3.1-1debian librust-rmp-serde-dev debian librust-rmp-serde+default-dev debian librust-rmp-serde-1-dev debian librust-rmp-serde-1+default-dev debian librust-rmp-serde-1.3-dev debian librust-rmp-serde-1.3+default-dev debian librust-rmp-serde-1.3.1-dev debian librust-rmp-serde-1.3.1+default-dev cargo rmp-serde 1.3.1 debianjsonmakefilemarkdownrustrustrust-c-abishelltoml 29 files · 1274 symbols
View dependency graph

Depends on

  • dh-cargo (dh-sequence-cargo)
  • rust-rmp (librust-rmp-0.8+default-dev)
  • cargo, debhelper-compat, librust-serde-1+default-dev, libstd-rust-dev, rustc
README (full)

MessagePack + Serde

This crate connects Rust MessagePack library with serde providing an ability to easily serialize and deserialize both Rust built-in types, the standard library and custom data structures.

Motivating example

let buf = rmp_serde::to_vec(&(42, "the Answer")).unwrap();

assert_eq!(
    vec![0x92, 0x2a, 0xaa, 0x74, 0x68, 0x65, 0x20, 0x41, 0x6e, 0x73, 0x77, 0x65, 0x72],
    buf
);

assert_eq!((42, "the Answer"), rmp_serde::from_slice(&buf).unwrap());

Type-based Serialization and Deserialization

Serde provides a mechanism for low boilerplate serialization & deserialization of values to and from MessagePack via the serialization API.

To be able to serialize a piece of data, it must implement the serde::Serialize trait. To be able to deserialize a piece of data, it must implement the serde::Deserialize trait. Serde provides an annotation to automatically generate the code for these traits: #[derive(Serialize, Deserialize)].

Examples

use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use rmp_serde::{Deserializer, Serializer};

#[derive(Debug, PartialEq, Deserialize, Serialize)]
struct Human {
    age: u32,
    name: String,
}

fn main() {
    let mut buf = Vec::new();
    let val = Human {
        age: 42,
        name: "John".into(),
    };

    val.serialize(&mut Serializer::new(&mut buf)).unwrap();
}

Efficient storage of &[u8] types

MessagePack can efficiently store binary data. However, Serde's standard derived implementations do not use binary representations by default. Serde prefers to represent types like &[u8; N] or Vec<u8> as arrays of objects of arbitrary/unknown type, and not as slices of bytes. This creates about a 50% overhead in storage size.

Wrap your data in serde_bytes to store blobs quickly and efficiently. Alternatively, configure an override in rmp_serde to force use of byte slices.

dir benches/
dir debian/
dir src/
dir tests/
file .cargo_vcs_info.json
file CHANGELOG.md
file Cargo.lock
file Cargo.toml
file Cargo.toml.orig
file LICENSE
file README.md