leb128fmt

Function decode_sint_slice

Source
pub fn decode_sint_slice<T, const BITS: u32>(
    input: &[u8],
    pos: &mut usize,
) -> Result<T, Error>
where T: Shl<u32, Output = T> + BitOrAssign + From<i8> + From<u8> + SInt,
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_sint_slice::<i32, 32>(&input, &mut pos);
assert_eq!(result, Ok(-113));
assert_eq!(pos, 4);