euv-core 0.54.0

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
use super::*;

/// Single state entry inside a flat Zstandard Finite State Entropy (FSE) decoding table.
#[derive(Clone, Copy, Data, Debug, Default, Eq, New, PartialEq)]
pub(crate) struct ZstdFseEntry {
    /// Output symbol emitted by this state.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) symbol: u8,
    /// Number of bits to read from the reverse bitstream to compute the next state.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) num_bits: u8,
    /// State baseline added to the read bits to produce the next state index.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) baseline: u16,
}

/// Decoded FSE table storing accuracy log and `1 << accuracy_log` state transition entries.
#[derive(Clone, Data, Debug, Default, Eq, PartialEq)]
pub(crate) struct ZstdFseTable {
    /// Accuracy log (`0..=9`).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) accuracy_log: u8,
    /// Flat state transition table of length `1 << accuracy_log`.
    #[get(pub(crate))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) entries: Vec<ZstdFseEntry>,
}

/// Single entry inside a flat canonical Zstandard Huffman decoding table.
#[derive(Clone, Copy, Data, Debug, Default, Eq, New, PartialEq)]
pub(crate) struct ZstdHuffmanEntry {
    /// Decoded literal byte value.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) symbol: u8,
    /// Codeword bit width (`1..=11`).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) num_bits: u8,
}

/// Decoded Zstandard canonical Huffman table supporting `Treeless` block reuse.
#[derive(Clone, Data, Debug, Default, Eq, PartialEq)]
pub(crate) struct ZstdHuffmanTable {
    /// Maximum codeword length in bits (`1..=11`).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) max_bits: u8,
    /// Direct lookup table indexed by `max_bits` MSB-first bits.
    #[get(pub(crate))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) entries: Vec<ZstdHuffmanEntry>,
}

/// Parsed RFC 8878 Zstandard frame header metadata.
#[derive(Clone, Copy, Data, Debug, Default, Eq, PartialEq)]
pub(crate) struct ZstdFrameHeader {
    /// Sliding window upper bound in bytes.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) window_size: usize,
    /// Optional declared uncompressed content size in bytes.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) frame_content_size: Option<u64>,
    /// Whether a 4-byte XXH64 low-32 content checksum trailer follows the final block.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) has_checksum: bool,
    /// Total byte length consumed by the frame header (excluding 4-byte magic).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) header_bytes: usize,
}

/// Persistent per-frame decoder state retaining repeat offsets and reusable entropy tables across blocks.
#[derive(Clone, Data, Debug, Default)]
pub(crate) struct ZstdFrameState {
    /// Active Huffman literal table reused by `Treeless_Literals_Block`.
    #[get(pub(crate))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) huffman: Option<ZstdHuffmanTable>,
    /// Active literals length FSE table reused by `Repeat` mode.
    #[get(pub(crate))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) ll_table: Option<ZstdFseTable>,
    /// Active offset FSE table reused by `Repeat` mode.
    #[get(pub(crate))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) of_table: Option<ZstdFseTable>,
    /// Active match length FSE table reused by `Repeat` mode.
    #[get(pub(crate))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) ml_table: Option<ZstdFseTable>,
    /// Three most recent match offsets (`[1, 4, 8]` initially).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) repeat_offsets: [usize; 3],
}

/// Reverse MSB-first bit reader for RFC 8878 Huffman and FSE backward bitstreams.
#[derive(Clone, Copy, Data, Debug)]
pub(crate) struct ZstdReverseBitReader<'a> {
    /// Backing compressed byte slice.
    #[get(pub(crate), type(copy))]
    #[set(skip)]
    #[get_mut(skip)]
    pub(crate) data: &'a [u8],
    /// Total payload bit count below the trailing sentinel `1` bit.
    #[get(pub(crate), type(copy))]
    #[set(skip)]
    #[get_mut(skip)]
    pub(crate) total_bits: usize,
    /// Number of bits consumed from the top of the stream (may exceed `total_bits` on FSE tail overflow).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) bits_consumed: usize,
}