#messagepack #serde #serialization #numeric #numbers #no-std #debugging

no-std messagepack-serde

messagepack for no_std with serde

2 releases

Uses new Rust 2024

new 0.1.2 Mar 11, 2025
0.1.1 Mar 11, 2025

#609 in Encoding

Download history 133/week @ 2025-03-06

133 downloads per month

Apache-2.0 OR MIT

160KB
4.5K SLoC

messagepack-serde

workflow Crates.io Version codecov CodSpeed Badge

messagepack for no_std with serde

Examples

use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct Data<'a> {
    compact: bool,
    schema: u8,
    less: &'a str,
}

let buf: &[u8] = &[
    0x83, 0xa7, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x63, 0x74, 0xc3, 0xa6, 0x73, 0x63, 0x68,
    0x65, 0x6d, 0x61, 0x00, 0xa4, 0x6c, 0x65, 0x73, 0x73, 0xa9, 0x74, 0x68, 0x61, 0x6e,
    0x20, 0x6a, 0x73, 0x6f, 0x6e,
];

let data = messagepack_serde::from_slice::<Data<'_>>(buf).unwrap();
let expected = Data {
    compact: true,
    schema: 0,
    less: "than json",
};
assert_eq!(data, expected);

let mut serialized = [0u8; 33];
let len = messagepack_serde::to_slice(&expected, &mut serialized).unwrap();
assert_eq!(&serialized[..len], buf);

Installation

Add this crate for Cargo.toml. Default support no_std.

messagepack-serde = { version = "0.1" }

Features

  • no_std support

    If you want this crate with std::io::Read or std::io::Write, please add feature std and use messagepack_serde::from_reader or messagepack_serde::to_writer.

  • Flexible Numeric Serialization

    • Provides multiple numeric encoding strategies:
      • Exact: Encodes numeric types exactly as provided without minimization. This is default.
      • Lossless Minimization: Minimizes numeric type size during serialization without any loss of information (e.g., encoding 1_u16 as positive fixint).
      • Aggressive Minimization: Aggressively minimizes numeric values, including converting floats with integer values into integers for the most compact representation.
    • If you want deserialize any numeric value, please use messagepack_serde::value::Number.
  • ext format support

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~0.4–1MB
~24K SLoC