pub fn decode<N>(buffer: &[u8]) -> Result<(N, usize), Error>Expand description
Decodes an unsigned integer from a given buffer, returning the integer and the amount of bytes read.
Note that this implementation protects against memory attacks by limiting the number of
processed bytes to the number of bytes needed to represent the max value of N.
If you want to be more strict, please limit the buffer length.
The unsigned-varint spec recommends a limit of 9 Bytes.
ยงExample
let (num, read) = decode::<u16>(&[0x80, 0x80, 0x01, 0xFF]).unwrap();
assert_eq!(num, 0x4000);
assert_eq!(read, 3);