pub fn encode<T: Encoder>(value: &T) -> Result<Bytes>Expand description
Convenience function to encode a value to bytes with magic number.
This function adds the encode magic number (0xA55A) at the beginning of the data and provides schema evolution support through field IDs and type tags.
§Arguments
value- The value to encode.
§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);