Expand description
Low-level bit packing primitives for the sdec codec.
This crate provides bounded BitWriter and BitReader for bit-level encoding and decoding.
For convenience, BitVecWriter can be used when a growable buffer is acceptable.
It is designed for bounded, panic-free operation with explicit error handling.
§Design Principles
- No unsafe code - Safety is paramount.
- Bounded operations - All reads/writes are bounds-checked.
- No domain knowledge - This crate knows nothing about entities, components, or game state.
- Explicit errors - All failures return structured errors, never panic.
§Example
use bitstream::{BitReader, BitVecWriter};
let mut writer = BitVecWriter::new();
writer.write_bit(true);
writer.write_bits(42, 7).unwrap();
let bytes = writer.finish();
let mut reader = BitReader::new(&bytes);
assert!(reader.read_bit().unwrap());
assert_eq!(reader.read_bits(7).unwrap(), 42);Structs§
- BitReader
- A bit-level reader for decoding packed binary data.
- BitVec
Writer - A growable bit-level writer backed by a
Vec<u8>. - BitWriter
- A bounded bit-level writer for encoding packed binary data.
Enums§
- BitError
- Errors that can occur during bit-level encoding/decoding.
Type Aliases§
- BitResult
- Result type for bitstream operations.