pub fn encode(value: i64) -> Vec<u8> ⓘExpand description
Encodes a signed 64-bit integer as LEB128 VarInt.
The encoding uses 7 bits per byte for data, with the most significant bit as a continuation flag (1 = more bytes follow, 0 = last byte).
§Performance
This function includes fast paths for common integer ranges:
- Single-byte encoding for values in range [-64, 63]
- Two-byte encoding for values in range [-8192, 8191]
§Examples
assert_eq!(varint::encode(0), vec![0x00]);
assert_eq!(varint::encode(127), vec![0xFF, 0x00]);
assert_eq!(varint::encode(128), vec![0x80, 0x01]);
assert_eq!(varint::encode(14532), vec![0xC4, 0xF1, 0x00]);