VLQEncode

Trait VLQEncode 

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

Required Methods§

Source

fn write_vlq(&mut self, value: T) -> Result<()>

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§

Source§

impl<W: Write + ?Sized> VLQEncode<i8> for W

Source§

impl<W: Write + ?Sized> VLQEncode<i16> for W

Source§

impl<W: Write + ?Sized> VLQEncode<i32> for W

Source§

impl<W: Write + ?Sized> VLQEncode<i64> for W

Source§

impl<W: Write + ?Sized> VLQEncode<isize> for W

Source§

impl<W: Write + ?Sized> VLQEncode<u8> for W

Source§

impl<W: Write + ?Sized> VLQEncode<u16> for W

Source§

impl<W: Write + ?Sized> VLQEncode<u32> for W

Source§

impl<W: Write + ?Sized> VLQEncode<u64> for W

Source§

impl<W: Write + ?Sized> VLQEncode<usize> for W