pub fn unpack<T: Unpacker>(reader: &mut Bytes) -> Result<T>Expand description
Convenience function to unpack a value from bytes.
This function expects and verifies the pack magic number (0xDADA) at the beginning of the data. The packed format is compact but not schema-evolution-friendly.
§Arguments
reader- The buffer to read the packed bytes from.
§Example
use senax_encoder::{pack, unpack, Pack, Unpack};
use bytes::BytesMut;
#[derive(Pack, Unpack, PartialEq, Debug)]
struct MyStruct {
id: u32,
name: String,
}
let value = MyStruct { id: 42, name: "hello".to_string() };
let mut buf = pack(&value).unwrap();
let decoded: MyStruct = unpack(&mut buf).unwrap();
assert_eq!(value, decoded);