Expand description
💎 Bijoux — the bijou family of bijective, length-prefixed
variable-length integer encodings. (Read the name both ways:
bijouX with X ranging over the widths — bijou32, bijou64,
bijou128 — and the French plural: all of the bijous.)
Each format module — unsigned u32, u64,
and u128, and signed i32,
i64, and i128 (zigzag over the matching
unsigned tier scheme) — defines one canonical encoding for one
integer type, exposed as free functions and gated behind a
same-named feature (all enabled by default). The Encode /
Decode traits are implemented directly on the integer types —
the family’s one-format-per-type commitment is what makes
impl Encode for u64 unambiguous.
Byte-lexicographic order matches numeric order for the unsigned
formats; for the signed formats it is zigzag order (see the
i64 module’s ordering caveat).
§Examples
Method syntax on the integers themselves:
use bijoux::{Decode, Encode};
let mut buf = Vec::new();
300u64.encode(&mut buf);
let (value, consumed) = u64::decode(&buf).unwrap();
assert_eq!((value, consumed), (300, 2));Code generic over any bijou-encodable integer:
use bijoux::Encode;
fn frame<T: Encode>(values: &[T], buf: &mut Vec<u8>) {
for &value in values {
value.encode(buf);
}
}
let mut buf = Vec::new();
frame(&[0u64, 247, 248], &mut buf);
assert_eq!(buf.len(), 1 + 1 + 2); // third value crosses into tier 1Modules§
- i32
i32 - Bijective variable-length encoding for signed 32-bit integers.
- i64
i64 - Bijective variable-length encoding for signed 64-bit integers.
- i128
i128 - Bijective variable-length encoding for signed 128-bit integers.
- u32
u32 - Bijective variable-length encoding for unsigned 32-bit integers.
- u64
u64 - Bijective variable-length encoding for unsigned 64-bit integers.
- u128
u128 - Bijective variable-length encoding for unsigned 128-bit integers.