Expand description
§messagepack-serde
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_stdsupportIf you want this crate with
std::io::Readorstd::io::Write, please add featurestdand usemessagepack_serde::from_readerormessagepack_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.
- Provides multiple numeric encoding strategies:
-
extformat support
§License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
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.
Re-exports§
pub use de::from_slice;pub use ser::to_slice;pub use ser::to_slice_with_config;pub use de::from_reader;stdpub use ser::to_vec;allocpub use ser::to_writer;stdpub use ser::to_writer_with_config;stdpub use value::Value;allocpub use value::ValueRef;alloc