[][src]Trait esl01_vlqencoding::VLQEncode

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

Required methods

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]);
Loading content...

Implementors

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

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

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

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

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

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

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

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

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

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

Loading content...