pub fn decode_uint_slice<T, const BITS: u32>(
input: &[u8],
pos: &mut usize,
) -> Result<T, Error>
Expand description
Decodes an unsigned integer from a slice of bytes and starting at a given position.
§Errors
Returns an error if the value is not properly encoded or if more bytes are needed to decode the value.
§Panics
Panics if the size in bits of the returned type is less than the size of the value in bits.
For instance, if 33 bits are being decoded, then the returned type must be at least a u64
.
let input = [0x42, 0x8F, 0xFF, 0x7F, 0xFF];
let mut pos = 1;
let result = leb128fmt::decode_uint_slice::<u32, 32>(&input, &mut pos);
assert_eq!(result, Ok(2097039));
assert_eq!(pos, 4);