decode

Function decode 

Source
pub fn decode<T: Decoder>(reader: &mut Bytes) -> Result<T>
Expand description

Convenience function to decode a value from bytes.

This function expects and verifies the encode magic number (0xA55A) at the beginning of the data. It provides schema evolution support through field IDs and type tags.

§Arguments

  • reader - The buffer to read the encoded bytes from.

§Example

use senax_encoder::{encode, decode, Encode, Decode};
use bytes::BytesMut;

#[derive(Encode, Decode, PartialEq, Debug)]
struct MyStruct {
    id: u32,
    name: String,
}

let value = MyStruct { id: 42, name: "hello".to_string() };
let mut buf = encode(&value).unwrap();
let decoded: MyStruct = decode(&mut buf).unwrap();
assert_eq!(value, decoded);