pub fn read_varint<B: Buf, T: TryFrom<u64>>(r: &mut B) -> Result<T>
Expand description
Read an epee variable sized number from r
.
use cuprate_epee_encoding::read_varint;
assert_eq!(read_varint::<_, u64>(&mut [252].as_slice()).unwrap(), 63);
assert_eq!(read_varint::<_, u64>(&mut [1, 1].as_slice()).unwrap(), 64);
assert_eq!(read_varint::<_, u64>(&mut [253, 255].as_slice()).unwrap(), 16_383);
assert_eq!(read_varint::<_, u64>(&mut [2, 0, 1, 0].as_slice()).unwrap(), 16_384);
assert_eq!(read_varint::<_, u64>(&mut [254, 255, 255, 255].as_slice()).unwrap(), 1_073_741_823);
assert_eq!(read_varint::<_, u64>(&mut [3, 0, 0, 0, 1, 0, 0, 0].as_slice()).unwrap(), 1_073_741_824);