Bitack
Allows describe how bits are arranged and provides utilities to serialize and deserialize binary data.
Why use bitack?
- Declarative: Define binary formats as schemes instead of manually manipulating bits.
- Safe: Avoid error-prone bit shifting and masking operations.
- Compact: Designed for binary formats where every bit matters.
- Flexible: Supports reading and writing custom bit layouts.
Installation
[]
= "0.1"
Bit Fields
A BitScheme is composed of BitFields. Each field defines how bits are written and read.
Example:
let scheme = new;
This scheme describes a 16-bit layout:
[ Next(4) ][ Skip(4) ][ LeadingOnes(4) ][ LeadingZeros(4) ]
When writing, only fields that store values consume elements from the input vector.
scheme.write;
The values are assigned as:
Next(4) <- 2
Skip(4) <- ignored (does not consume a value)
LeadingOnes(4) <- 3
LeadingZeros(4) <- 1
The resulting bits are:
[0010][0000][1110][0100]
Next Skip Ones Zeros
2 3 1
Example
use ;
use ;
see more examples
Status
Bitack is currently in early development. The API may change before version 1.0.
Limitations
Bitack is currently under active development. Some limitations exist in the current version:
- Bit fields are currently limited to 32 bits.
- Internal operations are based on
u32, so larger layouts are not supported yet. - Output is currently aligned to 4-byte blocks. Unused bits are padded with zeros.
- Error handling is still being improved and some invalid inputs may not provide detailed errors yet.