pub fn decode<T: Decoder>(reader: &mut Bytes) -> Result<T>Expand description
Convenience function to decode a value from bytes.
This is equivalent to calling T::decode(reader) but provides a more ergonomic API.
§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);