Crate minicbor_ser
source ·Expand description
A simple implementation of serde for minicbor
- serialisation
use serde::Serialize;
#[derive(Debug, Serialize)]
struct TestStruct {
hello: String,
}
let test_struct = TestStruct {
hello: "world".to_string(),
};
let value = to_vec(&test_struct).unwrap();
assert_eq!(
[0xA1u8, 0x65, 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x65, 0x77, 0x6F, 0x72, 0x6C, 0x64],
value.as_slice(),
)
- Deserialization
use serde::Deserialize;
#[derive(Debug, Deserialize, PartialEq)]
struct TestStruct {
hello: String,
}
let data = [0xA1u8, 0x65, 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x65, 0x77, 0x6F, 0x72, 0x6C, 0x64];
let value: TestStruct = from_slice(&data[..]).unwrap();
assert_eq!(
TestStruct {
hello: "world".to_string(),
},
value,
);
Re-exports
pub use minicbor as cbor;
pub use de::from_slice;
pub use de::from_slice_flat;
pub use ser::to_writer;
pub use ser::to_writer_cfg;
pub use ser::to_vec;
pub use ser::to_vec_flat;