Skip to main content

Module bits

Module bits 

Source
Expand description

Shared bit-level I/O — MSB-first and LSB-first readers and writers.

Every oxideav-* codec crate used to ship its own bitwriter / bitreader implementation. Those implementations converged on the same two layouts (MSB-first for ~everything, LSB-first for Vorbis) with only cosmetic method-name differences, so the core copy lives here and each codec crate pulls it in via oxideav_core::bits.

§Bit orders

  • BitReader / BitWriterMSB-first. Within each byte the high bit is read/written first. This matches AAC, MP1/2/3, FLAC, Speex, H.263/4, MPEG-1/2/4 video, and just about every modern codec bitstream.
  • BitReaderLsb / BitWriterLsbLSB-first. Within each byte the low bit is read/written first. Vorbis I §2.1.4 packs its bitstream this way.

Both variants carry a 64-bit accumulator so callers can request up to 32 bits per call without straddling refill logic. 64-bit values are handled in two halves by read_u64 / write_u64.

§Method naming

Every writer exposes both of these names for the same operation — historical drift across the codec crates made both common, and keeping both as aliases lets migration stay mechanical:

  • write_u32(value, n)write_bits(value, n) — append low n bits
  • finish(self)into_bytes(self) — pad + consume

Similarly skip(n) and consume(n) are aliases on the reader.

Structs§

BitReader
MSB-first bit reader over a borrowed byte slice.
BitReaderLsb
LSB-first bit reader. See module docs for the LSB convention.
BitWriter
MSB-first bit writer over an internal byte buffer.
BitWriterLsb
LSB-first bit writer — inverse of BitReaderLsb.