decode

Function decode 

Source
pub fn decode(bytes: &[u8]) -> Result<(i64, usize), BinaryError>
Expand description

Decodes a LEB128 VarInt from a byte slice.

Returns a tuple of (decoded_value, bytes_consumed) on success.

§Performance

This function includes fast paths for common cases:

  • Single-byte values (no continuation bit)
  • Two-byte values

§Errors

Returns BinaryError::InvalidVarInt if:

  • The input is empty
  • The VarInt encoding is invalid (too many bytes)
  • The continuation bit pattern is malformed

§Examples

assert_eq!(varint::decode(&[0x00]).unwrap(), (0, 1));
assert_eq!(varint::decode(&[0xFF, 0x00]).unwrap(), (127, 2));
assert_eq!(varint::decode(&[0x80, 0x01]).unwrap(), (128, 2));
assert_eq!(varint::decode(&[0xC4, 0xF1, 0x00]).unwrap(), (14532, 3));