#integer #binary #byte #integer-compression

varintrs

A Rust implementation of Golang Variable-Length Integers

3 unstable releases

0.2.1 Aug 2, 2023
0.2.0 Dec 16, 2022
0.1.0 Nov 11, 2022

#861 in Database interfaces

Download history 32/week @ 2024-02-24 2/week @ 2024-03-02 4/week @ 2024-03-09 4/week @ 2024-03-16 44/week @ 2024-03-30 5/week @ 2024-04-06 72/week @ 2024-04-13

121 downloads per month
Used in furze

MIT license

15KB
410 lines

varintrs

A Rust implementation of Golang Variable-Length Integers

Notes:

This is a rust implementation of golang variable-length integers. Variable-length integers are usually used in writing database storage, which can compress integer data storage and save disk space.

For example:

use std::io::Cursor;
use varintrs::{Binary, ReadBytesVarExt};

let mut rdr = Cursor::new(vec![228, 211, 247, 161, 22]);
let (v, x) = rdr.read_vu64::<Binary>();
assert_eq!(5976746468, v);
assert_eq!(5, x);
use std::io::Cursor;
use varintrs::{Binary,WriteBytesVarExt};

let mut rdr = Cursor::new(vec![0u8; 7]);
rdr.write_vu64::<Binary>(88748464645454).unwrap();
assert!(rdr.get_ref().eq(&vec![206, 202, 214, 229, 245, 150, 20]));

No runtime deps