chdlady-huffman 0.1.0

Bitstream manipulation and canonical Huffman coding compatible with MAME CHD
//! Error types for Huffman codec operations.
use std::fmt;

/// Errors that can occur during Huffman coding or bitstream operations.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HuffmanError {
    /// Maximum bit length exceeded limit.
    TooManyBits,
    /// Bitstream contains corrupted or invalid data.
    InvalidData,
    /// Source buffer has fewer bytes than required.
    InputBufferTooSmall,
    /// Destination buffer is too small to hold output.
    OutputBufferTooSmall,
    /// Internal tree structure or code lengths are inconsistent.
    InternalInconsistency,
    /// Maximum context limit exceeded.
    TooManyContexts,
}

impl fmt::Display for HuffmanError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::TooManyBits => write!(f, "too many bits requested"),
            Self::InvalidData => write!(f, "invalid huffman data"),
            Self::InputBufferTooSmall => write!(f, "input buffer too small"),
            Self::OutputBufferTooSmall => write!(f, "output buffer too small"),
            Self::InternalInconsistency => write!(f, "internal inconsistency in huffman tree"),
            Self::TooManyContexts => write!(f, "too many contexts"),
        }
    }
}

impl std::error::Error for HuffmanError {}