Skip to main content

euv_docs/codec/
struct.rs

1use super::*;
2
3/// Per-page heavy content record stored inside the compressed `site_bodies.euvz` payload.
4#[derive(Clone, Data, Debug, Default, Deserialize, New, PartialEq, Serialize)]
5pub struct PackedPageBody {
6    /// Raw Markdown body text used by the native `EuvMarkdown` renderer.
7    #[serde(default, skip_serializing_if = "String::is_empty")]
8    pub(crate) markdown_body: String,
9    /// Structured fallback blocks retained only when `markdown_body` is empty.
10    #[serde(default, skip_serializing_if = "Vec::is_empty")]
11    pub(crate) blocks: Vec<DocBlock>,
12}
13
14/// Split site bundle pairing a lightweight plaintext metadata shell with compressed page bodies.
15#[derive(Clone, Debug, Eq, Getter, New, PartialEq)]
16pub struct PackedSiteBundle {
17    /// Compact plaintext JSON carrying site metadata, TOC headings, and page index records.
18    pub(crate) shell_json: String,
19    /// `EUVZ`-compressed UTF-8 JSON payload storing all page bodies for the locale.
20    pub(crate) compressed_bodies: Vec<u8>,
21}
22
23/// LSB-first bit writer accumulating variable-width canonical Huffman codes into a byte vector.
24#[derive(Clone, Data, Debug, Default)]
25pub(crate) struct CodecBitWriter {
26    /// Output byte stream.
27    #[get(pub(crate))]
28    #[get_mut(pub(crate))]
29    #[set(pub(crate))]
30    pub(crate) bytes: Vec<u8>,
31    /// Buffered unwritten bits stored in the lowest `bit_count` positions.
32    #[get(pub(crate), type(copy))]
33    #[get_mut(pub(crate))]
34    #[set(pub(crate))]
35    pub(crate) bit_buf: u64,
36    /// Number of valid bits currently held in `bit_buf`.
37    #[get(pub(crate), type(copy))]
38    #[get_mut(pub(crate))]
39    #[set(pub(crate))]
40    pub(crate) bit_count: u32,
41}
42
43/// LSB-first bit reader streaming variable-width canonical Huffman codes from an immutable slice.
44#[derive(Clone, Data, Debug)]
45pub(crate) struct CodecBitReader<'a> {
46    /// Source byte slice.
47    #[get(pub(crate), type(copy))]
48    #[get_mut(skip)]
49    #[set(skip)]
50    pub(crate) data: &'a [u8],
51    /// Current byte read cursor within `data`.
52    #[get(pub(crate), type(copy))]
53    #[get_mut(pub(crate))]
54    #[set(pub(crate))]
55    pub(crate) cursor: usize,
56    /// Prefetched bits stored in the lowest `bit_count` positions.
57    #[get(pub(crate), type(copy))]
58    #[get_mut(pub(crate))]
59    #[set(pub(crate))]
60    pub(crate) bit_buf: u64,
61    /// Number of valid unread bits currently held in `bit_buf`.
62    #[get(pub(crate), type(copy))]
63    #[get_mut(pub(crate))]
64    #[set(pub(crate))]
65    pub(crate) bit_count: u32,
66}