GitXplorerGitXplorer
j

bitpacker

public
0 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
4f660399ae4dac3eafbc281db57e096ba560f060

Fix a typo

jjstasiak committed 5 years ago
Unverified
a2727389091abd6d3e3e0ca2e1588c177d1c23e7

Document the API in the readme

jjstasiak committed 5 years ago
Unverified
75b586a4e4334a0d5e4fa2c572264b7e67497ec5

Mark Packer/Unpacker/bin as pub to get rid of dead code warnings

jjstasiak committed 5 years ago
Unverified
ffdb14b6f0feab93f6ed6e9536005c80818cc1c7

Add some more description to the readme

jjstasiak committed 5 years ago
Unverified
a2115b64f3b89219b0c984ac9643ac2f98a6edd5

Add debug prints that are no longer necessary

jjstasiak committed 5 years ago
Unverified
0894d9399a429050dd9076eb264c3fb6e6a86b82

Add some Cargo metadata

jjstasiak committed 5 years ago

README

The README file for this repository.

bitpacker

Build Status Coverage Status

Pack numbers tightly. In Rust.

What is this?

I heard about this fun exercise of packing numbers tightly using as few bits as possible for fun and profit, so I decided to see what's all that about.

This is a purely exploratory/learning project and literally nothing should be expected of it.

The API

let mut packer = Packer::new();

// pack() will panic if you pass bits lower than 1 or greater than 64
packer.pack(2, 2);
packer.pack(7, 4);
packer.pack(1, 1);

// In packer total_bits() will return the precise number of bits packed.
dbg!(packer.total_bits()); // Prints 7

// Prints [158]. 158 in binary is 0b10011110. In that we have:
// * 0b10 (2 bits) -> 2
// * 0b0111 (4 bits) -> 7
// * 0b1 (1 bit) -> 1
// * 0b0 (1 bit) -> unused space
dbg!(packer.buffer());

let mut unpacker = Unpacker::new(packer.buffer());
dbg!(unpacker.total_bits()); // 8, because unpacker doesn't know if there are unused bits.
dbg!(unpacker.remaining_bits()); // 8, see above + we haven't unpacked anything yet
dbg!(unpacker.unpack(2)); // 2
dbg!(unpacker.unpack(4)); // 7
dbg!(unpacker.unpack(1)); // 1
dbg!(unpacker.remaining_bits()); // 1, because there's one unused bit left. Its value is undefined.