Crate vu64

source · []
Expand description

The variable length integer encoding of u64. This is a simple and fast encoder/decoder.

format pattern

PrefixPrecisionTotal Bytes
0xxxxxxx7 bits1 byte
10xxxxxx14 bits2 bytes
110xxxxx21 bits3 bytes
1110xxxx28 bits4 bytes
11110xxx35 bits5 bytes
111110xx42 bits6 bytes
1111110x49 bits7 bytes
1111111056 bits8 bytes
1111111164 bits9 bytes

This format is a like vint64, but 0x00 is represented by 0x00.

Examples

Encode

use vu64::encode;

assert_eq!(encode(0x0f0f).as_ref(), &[0x8F, 0x3c]);

Decode

use vu64::decode;

let slice = [0x8F, 0x3c].as_ref();
assert_eq!(decode(slice).unwrap(), 0x0f0f);

Encode and decode

use vu64::{encode, decode};

let val = 1234;
assert_eq!(decode(encode(val).as_ref()).unwrap(), val);

Modules

Support for encoding signed integers as vu64.

Structs

vu64: serialized variable-length 64-bit integers.

Enums

Error type

Constants

Maximum length of a vu64 in bytes

Maximun integer whose length of vu64 is 1 byte.

Maximun integer whose length of vu64 is 2 byte.

Maximun integer whose length of vu64 is 3 byte.

Maximun integer whose length of vu64 is 4 byte.

Maximun integer whose length of vu64 is 5 byte.

Maximun integer whose length of vu64 is 6 byte.

Maximun integer whose length of vu64 is 7 byte.

Maximun integer whose length of vu64 is 8 byte.

Maximun integer whose length of vu64 is 9 byte.

Functions

Decode a v64-encoded unsigned 64-bit integer.

Decode a v64-encoded unsigned 64-bit integer.

Decode a v64-encoded unsigned 64-bit integer.

Get the length of a vu64 from the first byte.

Encode an unsigned 64-bit integer as vu64.

Get the length of an encoded vu64 for the given value in bytes.