msgpackin

Msgpackin pure Rust MessagePack encoding / decoding library.

Msgpackin supports no_std, but requires the alloc crate. If you're looking for no alloc support, see the msgpackin_core crate.

Msgpackin supports serde with the serde feature in either no_std or std mode. If you want std mode, you must also enable the serde_std feature, as a temporary workaround until weak dependency features are stablized.

Roadmap

Features

no_std Example

rust use msgpackin::*; let expect = Value::Map(vec![ ("nil".into(), ().into()), ("bool".into(), true.into()), ("int".into(), (-42_i8).into()), ("bigInt".into(), u64::MAX.into()), ("float".into(), 3.141592653589793_f64.into()), ("str".into(), "hello".into()), ("ext".into(), Value::Ext(-42, b"ext-data".to_vec().into())), ("arr".into(), Value::Arr(vec!["one".into(), "two".into()])), ]); let encoded = expect.to_bytes().unwrap(); let decoded = ValueRef::from_ref(&encoded).unwrap(); assert_eq!(expect, decoded);

std Example

```rust use msgpackin::*; let expect = Value::Map(vec![("foo".into(), "bar".into())]); let mut buf = Vec::new();

{ let writer: Box = Box::new(&mut buf); expect.to_sync(writer).unwrap(); }

let reader: Box = Box::new(buf.asslice()); let decoded = Value::fromsync(reader).unwrap(); assert_eq!(expect, decoded); ```

Async Example

```rust use msgpackin::*; let expect = Value::Map(vec![("foo".into(), "bar".into())]); let mut buf = Vec::new();

{ let writer: Box = Box::new(&mut buf); futures::executor::blockon(async { expect.toasync(writer).await }) .unwrap(); }

let reader: Box = Box::new(buf.asslice()); let decoded = futures::executor::blockon(async { Value::fromasync(reader).await }) .unwrap(); asserteq!(expect, decoded); ```

serde Example

```rust use msgpackin::*;

[derive(Debug, PartialEq, serde::Serialize, serde::Deserialize)]

struct X { pub nil: (), pub bool: bool, pub int: i8, pub bigint: u64, pub float: f64, pub str_: String, pub arr: Vec, }

let expect = X { nil: (), bool: true, int: -42, bigint: u64::MAX, float: 3.141592653589793, str_: "hello".into(), arr: vec!["one".into(), "two".into()], };

let encoded = tobytes(&expect).unwrap(); let decoded: X = fromsync(encoded.asslice()).unwrap(); asserteq!(expect, decoded); ```

License: Apache-2.0