pub trait VLQEncode<T> {
    fn write_vlq(&mut self, value: T) -> Result<()>;
}

Required Methods§

Encode an integer to a VLQ byte array and write it directly to a stream.

Examples
use vlqencoding::VLQEncode;
let mut v = vec![];

let x = 120u8;
v.write_vlq(x).expect("writing an encoded u8 to a vec should work");
assert_eq!(v, vec![120]);

let x = 22742734291u64;
v.write_vlq(x).expect("writing an encoded u64 to a vec should work");

assert_eq!(v, vec![120, 211, 171, 202, 220, 84]);

Signed integers are encoded via zig-zag:

use vlqencoding::VLQEncode;
let mut v = vec![];

let x = -3i8;
v.write_vlq(x).expect("writing an encoded i8 to a vec should work");
assert_eq!(v, vec![5]);

let x = 1000i16;
v.write_vlq(x).expect("writing an encoded i16 to a vec should work");
assert_eq!(v, vec![5, 208, 15]);

Implementors§