Function from_bytes

Source
pub fn from_bytes<'a, T>(data: &'a mut [u8]) -> Result<T, Error>
where T: Decodable<'a>,
Expand description

Decodes an SV2-encoded byte slice into the specified data type.

Examples found in repository?
examples/encode_decode.rs (line 115)
102fn main() {
103    let expected = Test {
104        a: 456,
105        b: 9,
106        c: 67_u32.try_into().unwrap(),
107    };
108
109    // `to_bytes` serves as the entry point to the `binary_sv2` crate. It acts as a serializer that
110    // converts the struct into bytes.
111    let mut bytes = to_bytes(expected.clone()).unwrap();
112
113    // `from_bytes` is a deserializer that interprets the bytes and reconstructs the original
114    // struct.
115    let deserialized: Test = from_bytes(&mut bytes[..]).unwrap();
116
117    assert_eq!(deserialized, expected);
118}