Brotli::Enc::BitWriter
Inherits Reference < Object
Writes bits into bytes in increasing addresses, within a byte least-significant-bit first (RFC 7932 bit order).
Contract (same as C):
- up to 56 bits per call; (bits >> n_bits) must be 0;
- the byte at the NEW pos >> 3 must already be zero (the caller zeroes it via prepare_storage or by seeding from last_bytes).
Constructors
new(storage : Bytes, pos : Int32 = 0)
SourceInstance methods
pos
Sourcepos=(pos : Int32)
Sourceprepare_storage(pos : Int32) : Nil
array[pos >> 3] = 0; call before writing at a byte-aligned position.
rewind_bit_position(new_pos : Int32) : Nil
Moves #pos back; the partially-written byte is masked to its valid bits so a subsequent write starts clean (compress_fragment.c: uncompressed-metablock escape).
storage
Sourcestorage=(storage : Bytes)
Sourceupdate_bits(n_bits : Int32, bits : UInt32, pos : Int32) : Nil
Overwrites n_bits at an arbitrary earlier bit position (compress_fragment.c: in-place MLEN patch of an already-written metablock header). Does not move #pos. (bits >> n_bits) must be 0.
write_bits(n_bits : Int, bits : UInt64) : Nil
n_bits is coerced (depths arrive as UInt8/UInt32 lookups); bits values are zero-extended from any integer width.
write_bits(n_bits : Int, bits : Int) : Nil
Source