euv-core 0.55.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::*;

/// Parsed table-of-contents metadata for a single `.euvpak` archive entry.
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
pub struct EuvPakEntryMeta {
    /// 64-bit FNV-1a normalized virtual path hash.
    #[get(type(copy))]
    pub(crate) path_hash: u64,
    /// 64-byte-aligned byte offset of the payload inside the archive.
    #[get(type(copy))]
    pub(crate) offset: u64,
    /// Stored payload byte length inside the archive.
    #[get(type(copy))]
    pub(crate) compressed_size: u64,
    /// Original uncompressed payload byte length.
    #[get(type(copy))]
    pub(crate) uncompressed_size: u64,
    /// Semantic asset category.
    #[get(type(copy))]
    pub(crate) kind: EuvPakEntryKind,
    /// True when the stored payload bytes are LZ4 block compressed.
    #[get(type(copy))]
    pub(crate) is_compressed: bool,
}

/// Zero-copy borrowed view of one entry stored inside a mounted `EuvPakArchive`.
#[derive(Clone, Copy, Data, Debug, Eq, PartialEq)]
pub struct EuvPakSlice<'a> {
    /// 64-bit FNV-1a normalized virtual path hash.
    #[get(type(copy))]
    pub(crate) path_hash: u64,
    /// Semantic entry payload category.
    #[get(type(copy))]
    pub(crate) kind: EuvPakEntryKind,
    /// Uncompressed logical byte length of this entry.
    #[get(type(copy))]
    pub(crate) uncompressed_size: u64,
    /// True when `bytes` holds LZ4 compressed data requiring decompression.
    #[get(type(copy))]
    pub(crate) is_compressed: bool,
    /// Zero-copy borrowed byte slice inside the archive backing mapping.
    #[get(type(copy))]
    pub(crate) bytes: &'a [u8],
}

/// Internal queued entry stored inside `EuvPakWriter` prior to serialization.
#[derive(Clone, Debug)]
pub(crate) struct EuvPakPendingEntry {
    /// Normalized 64-bit FNV-1a virtual path hash.
    pub(crate) path_hash: u64,
    /// Semantic asset category.
    pub(crate) kind: EuvPakEntryKind,
    /// Raw uncompressed input bytes.
    pub(crate) raw_bytes: Vec<u8>,
    /// Whether LZ4 block compression should be attempted when beneficial.
    pub(crate) compress: bool,
}

/// Internal serialized record prepared during `EuvPakWriter::finish_bytes`.
#[derive(Clone, Debug)]
pub(crate) struct EuvPakEncodedRecord {
    /// Parsed TOC metadata for this record.
    pub(crate) meta: EuvPakEntryMeta,
    /// CRC32 checksum of the stored payload bytes.
    pub(crate) payload_crc32: u32,
    /// CRC32 checksum of the original uncompressed bytes.
    pub(crate) uncompressed_crc32: u32,
    /// Stored payload bytes (raw or LZ4 block compressed).
    pub(crate) stored_bytes: Vec<u8>,
}

/// Builder serializing virtual assets and contiguous mip-tail superblocks into a 64-byte-aligned `.euvpak` archive.
#[derive(Clone, Debug, Default)]
pub struct EuvPakWriter {
    /// Pending general archive entries.
    pub(crate) entries: Vec<EuvPakPendingEntry>,
    /// Pending contiguous mip-tail superblock entries `(path_hash, payload)`.
    pub(crate) mip_tails: Vec<(u64, Vec<u8>)>,
}

/// Mounted zero-copy `.euvpak` virtual filesystem archive supporting zero-allocation O(1) open-addressed TOC lookups.
#[derive(Clone, Debug)]
pub struct EuvPakArchive {
    /// Read-only backing OS memory map or in-memory byte buffer.
    pub(crate) mapping: EuvPakMapping,
    /// Total count of occupied entries inside the archive TOC.
    pub(crate) entry_count: usize,
    /// Byte offset where the open-addressed hash table TOC starts inside `mapping`.
    pub(crate) toc_offset: usize,
    /// Power-of-two bucket capacity of the open-addressed hash table TOC.
    pub(crate) toc_bucket_count: usize,
    /// Contiguous byte range `(start, length)` of the Mip-Tail Superblock inside `mapping`.
    pub(crate) mip_tail_range: (usize, usize),
    /// Byte range `(start, length)` of general non-mip-tail asset payloads inside `mapping`.
    pub(crate) data_range: (usize, usize),
}

/// Incremental chunk-resumable LZ4 block decoder enabling cooperative `<= 1.5 ms/frame` time-sliced decompression.
#[derive(Clone, Debug)]
pub struct Lz4StreamDecoder {
    /// Current read cursor inside the compressed input slice.
    pub(crate) input_pos: usize,
    /// Current write cursor inside `output`.
    pub(crate) output_pos: usize,
    /// Expected uncompressed output length in bytes.
    pub(crate) expected_len: usize,
    /// Pre-allocated destination buffer populated incrementally across time slices.
    pub(crate) output: Vec<u8>,
}