pub fn from_bytes<T: Decode>(bytes: &[u8]) -> Result<T, DecodeError>Expand description
Decodes a T from bytes.
let item = cyclone_runtime::from_bytes::<Item>(&[0x2A, 0x00, 0x00, 0x00])?;
assert_eq!(item.id, 42);§Errors
Any DecodeError the decode produces.
§Trailing bytes
Bytes left over after the value are not an error here - this helper decodes one value and returns it. A stream that should end exactly at the value (RFC-0002 §9) needs the check made explicitly:
let mut reader = Reader::new(&bytes);
let item = Item::decode(&mut reader)?;
assert!(reader.is_empty(), "trailing bytes: the two ends disagree about the schema");The same route applies when decoding untrusted input, which wants
Reader::with_limits rather than the permissive default this helper uses.