Crate stream_vbyte [] [src]

Encode and decode u32s with the Stream VByte format.

use stream_vbyte::*;

let nums: Vec<u32> = (0..12345).collect();
let mut encoded_data = Vec::new();
// make some space to encode into
encoded_data.resize(5 * nums.len(), 0x0);

// use Scalar implementation that works on any hardware
let encoded_len = encode::<Scalar>(&nums, &mut encoded_data);
println!("Encoded {} u32s into {} bytes", nums.len(), encoded_len);

let mut decoded_nums = Vec::new();
decoded_nums.resize(nums.len(), 0);
// now decode
decode::<Scalar>(&encoded_data, nums.len(), &mut decoded_nums);

assert_eq!(nums, decoded_nums);

Structs

Scalar

Regular ol' byte shuffling. Works on every platform, but it's not the quickest.

Traits

Decoder
Encoder

Functions

decode

Decode count numbers from input, appending them to output. The count must be the same as the number of items originally encoded. Returns the number of bytes read from input.

encode

Encode the input slice into the output slice. The worst-case encoded length is 4 bytes per u32 plus another byte for every 4 u32s, including a trailing partial 4-some. Returns the number of bytes written to the output slice.