Skip to main content

euv_core/runtime/vfs/format/
struct.rs

1use super::*;
2
3/// Parsed table-of-contents metadata for a single `.euvpak` archive entry.
4#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
5pub struct EuvPakEntryMeta {
6    /// 64-bit FNV-1a normalized virtual path hash.
7    #[get(type(copy))]
8    pub(crate) path_hash: u64,
9    /// 64-byte-aligned byte offset of the payload inside the archive.
10    #[get(type(copy))]
11    pub(crate) offset: u64,
12    /// Stored payload byte length inside the archive.
13    #[get(type(copy))]
14    pub(crate) compressed_size: u64,
15    /// Original uncompressed payload byte length.
16    #[get(type(copy))]
17    pub(crate) uncompressed_size: u64,
18    /// Semantic asset category.
19    #[get(type(copy))]
20    pub(crate) kind: EuvPakEntryKind,
21    /// True when the stored payload bytes are LZ4 block compressed.
22    #[get(type(copy))]
23    pub(crate) is_compressed: bool,
24}
25
26/// Zero-copy borrowed view of one entry stored inside a mounted `EuvPakArchive`.
27#[derive(Clone, Copy, Data, Debug, Eq, PartialEq)]
28pub struct EuvPakSlice<'a> {
29    /// 64-bit FNV-1a normalized virtual path hash.
30    #[get(type(copy))]
31    pub(crate) path_hash: u64,
32    /// Semantic entry payload category.
33    #[get(type(copy))]
34    pub(crate) kind: EuvPakEntryKind,
35    /// Uncompressed logical byte length of this entry.
36    #[get(type(copy))]
37    pub(crate) uncompressed_size: u64,
38    /// True when `bytes` holds LZ4 compressed data requiring decompression.
39    #[get(type(copy))]
40    pub(crate) is_compressed: bool,
41    /// Zero-copy borrowed byte slice inside the archive backing mapping.
42    #[get(type(copy))]
43    pub(crate) bytes: &'a [u8],
44}
45
46/// Internal queued entry stored inside `EuvPakWriter` prior to serialization.
47#[derive(Clone, Debug)]
48pub(crate) struct EuvPakPendingEntry {
49    /// Normalized 64-bit FNV-1a virtual path hash.
50    pub(crate) path_hash: u64,
51    /// Semantic asset category.
52    pub(crate) kind: EuvPakEntryKind,
53    /// Raw uncompressed input bytes.
54    pub(crate) raw_bytes: Vec<u8>,
55    /// Whether LZ4 block compression should be attempted when beneficial.
56    pub(crate) compress: bool,
57}
58
59/// Internal serialized record prepared during `EuvPakWriter::finish_bytes`.
60#[derive(Clone, Debug)]
61pub(crate) struct EuvPakEncodedRecord {
62    /// Parsed TOC metadata for this record.
63    pub(crate) meta: EuvPakEntryMeta,
64    /// CRC32 checksum of the stored payload bytes.
65    pub(crate) payload_crc32: u32,
66    /// CRC32 checksum of the original uncompressed bytes.
67    pub(crate) uncompressed_crc32: u32,
68    /// Stored payload bytes (raw or LZ4 block compressed).
69    pub(crate) stored_bytes: Vec<u8>,
70}
71
72/// Builder serializing virtual assets and contiguous mip-tail superblocks into a 64-byte-aligned `.euvpak` archive.
73#[derive(Clone, Debug, Default)]
74pub struct EuvPakWriter {
75    /// Pending general archive entries.
76    pub(crate) entries: Vec<EuvPakPendingEntry>,
77    /// Pending contiguous mip-tail superblock entries `(path_hash, payload)`.
78    pub(crate) mip_tails: Vec<(u64, Vec<u8>)>,
79}
80
81/// Mounted zero-copy `.euvpak` virtual filesystem archive supporting zero-allocation O(1) open-addressed TOC lookups.
82#[derive(Clone, Debug)]
83pub struct EuvPakArchive {
84    /// Read-only backing OS memory map or in-memory byte buffer.
85    pub(crate) mapping: EuvPakMapping,
86    /// Total count of occupied entries inside the archive TOC.
87    pub(crate) entry_count: usize,
88    /// Byte offset where the open-addressed hash table TOC starts inside `mapping`.
89    pub(crate) toc_offset: usize,
90    /// Power-of-two bucket capacity of the open-addressed hash table TOC.
91    pub(crate) toc_bucket_count: usize,
92    /// Contiguous byte range `(start, length)` of the Mip-Tail Superblock inside `mapping`.
93    pub(crate) mip_tail_range: (usize, usize),
94    /// Byte range `(start, length)` of general non-mip-tail asset payloads inside `mapping`.
95    pub(crate) data_range: (usize, usize),
96}
97
98/// Incremental chunk-resumable LZ4 block decoder enabling cooperative `<= 1.5 ms/frame` time-sliced decompression.
99#[derive(Clone, Debug)]
100pub struct Lz4StreamDecoder {
101    /// Current read cursor inside the compressed input slice.
102    pub(crate) input_pos: usize,
103    /// Current write cursor inside `output`.
104    pub(crate) output_pos: usize,
105    /// Expected uncompressed output length in bytes.
106    pub(crate) expected_len: usize,
107    /// Pre-allocated destination buffer populated incrementally across time slices.
108    pub(crate) output: Vec<u8>,
109}