Function ssh_format::from_bytes
source · pub fn from_bytes<'a, T>(s: &'a [u8]) -> Result<(T, &'a [u8])>where
T: Deserialize<'a>,
Expand description
Return a deserialized value and trailing bytes.
§Example
Simple Usage:
ⓘ
let serialized = to_bytes(value).unwrap();
// Ignore the size
let (new_value, _trailing_bytes) = from_bytes::<T>(&serialized[4..]).unwrap();
assert_eq!(value, new_value);
Replace T
with type of value
.
More complicated one (sending over socket):
ⓘ
let buffer = // read in 4 bytes;
let (size: u32, _trailing_bytes0 = from_bytes(&buffer).unwrap();
let buffer = // read in `size` bytes;
let (val: <T>, _trailing_bytes) = from_bytes(&buffer).unwrap();
Replace T
with your own type.