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.
from_ref
no_std
serde supportstd::io::{Read, Write}
support in std
modefutures-io
or tokio
features-1
))std
- enabled by default, pulls in the rust std library, enabling
encoding and decoding via std::io::{Read, Write}
traitsserde
- enables serialization / deserialization through the serde
cratefutures-io
- enables async encoding and decoding through the futures
io::{AsyncRead, AsyncWrite}
traitstokio
- enables async encoding and decoding through the tokio
io::{AsyncRead, AsyncWrite}
traitsno_std
Examplerust
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
let reader: Box
```rust use msgpackin::*; let expect = Value::Map(vec![("foo".into(), "bar".into())]); let mut buf = Vec::new();
{
let writer: Box
let reader: Box
serde
Example```rust use msgpackin::*;
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