pub struct PrefixCode { /* private fields */ }Expand description
A canonical prefix (Huffman) decoder built from per-symbol code lengths (RFC 9649 §3.7.2).
Decoding uses the classic canonical algorithm (no large lookup table): bits are read one at a time and accumulated MSB-first until they identify a symbol. A single-symbol code returns its symbol without consuming any bits.
Implementations§
Source§impl PrefixCode
impl PrefixCode
Sourcepub fn from_code_lengths(code_lengths: &[u8]) -> Result<Self>
pub fn from_code_lengths(code_lengths: &[u8]) -> Result<Self>
Builds a decoder from code_lengths (one entry per symbol; 0 = unused).
§Errors
Returns Error::InvalidInput if a length exceeds MAX_CODE_LENGTH, if no symbol is
used, or if the lengths do not form a complete tree (the single-symbol leaf is the one
permitted incomplete tree, per §3.7.2).
Sourcepub fn read_symbol(&self, r: &mut BitReader<'_>) -> Result<u16>
pub fn read_symbol(&self, r: &mut BitReader<'_>) -> Result<u16>
Reads one symbol from r.
§Errors
Returns Error::InvalidInput on truncation or if the bits do not match any code.
Trait Implementations§
Source§impl Clone for PrefixCode
impl Clone for PrefixCode
Source§fn clone(&self) -> PrefixCode
fn clone(&self) -> PrefixCode
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for PrefixCode
impl RefUnwindSafe for PrefixCode
impl Send for PrefixCode
impl Sync for PrefixCode
impl Unpin for PrefixCode
impl UnsafeUnpin for PrefixCode
impl UnwindSafe for PrefixCode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more