cuprate_epee_encoding

Function read_varint

Source
pub fn read_varint<B: Buf>(r: &mut B) -> Result<u64>
Expand description

Read an epee variable sized number from r.

use cuprate_epee_encoding::read_varint;

assert_eq!(read_varint(&mut [252].as_slice()).unwrap(), 63);
assert_eq!(read_varint(&mut [1, 1].as_slice()).unwrap(), 64);
assert_eq!(read_varint(&mut [253, 255].as_slice()).unwrap(), 16_383);
assert_eq!(read_varint(&mut [2, 0, 1, 0].as_slice()).unwrap(), 16_384);
assert_eq!(read_varint(&mut [254, 255, 255, 255].as_slice()).unwrap(), 1_073_741_823);
assert_eq!(read_varint(&mut [3, 0, 0, 0, 1, 0, 0, 0].as_slice()).unwrap(), 1_073_741_824);