Skip to main content

mlt_core/dump/
model.rs

1//! Data model for the annotated binary dump (see [`crate::dump`]).
2
3use crate::wire::StreamMeta;
4
5/// Whether a region is tile metadata or an opaque data payload.
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum RegionKind {
8    /// Framing, schema, or stream-header bytes, annotated byte- and bit-for-byte.
9    Meta,
10    /// A stream payload, rendered as raw hex plus best-effort decoded values.
11    DataBlob,
12}
13
14/// How a [`RegionKind::DataBlob`] payload is decoded for display.
15///
16/// Best-effort: on any decode error the renderer falls back to raw hex.
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub enum DecodeHint {
19    /// Nullability bitmap (byte-RLE -> packed bits).
20    Presence,
21    /// Boolean data stream (byte-RLE -> bools).
22    Bool,
23    /// Signed 32-bit integers (`i8`/`i32` columns).
24    I32,
25    /// Unsigned 32-bit integers (`u8`/`u32` columns, offsets, lengths).
26    U32,
27    /// Signed 64-bit integers (`i64` columns).
28    I64,
29    /// Unsigned 64-bit integers (`u64` columns, 64-bit ids).
30    U64,
31    /// 32-bit floats.
32    F32,
33    /// 64-bit floats.
34    F64,
35    /// Opaque bytes (string / dictionary / FSST payloads); shown as hex + UTF-8 preview.
36    Bytes,
37    /// A raw LSB0 bitfield, not a stream: `ceil(num_values/8)` packed bytes.
38    #[cfg(feature = "unstable-v2")]
39    PackedBits,
40}
41
42/// One sub-field of a bit-packed byte, e.g. a nibble of `stream_type`.
43#[derive(Debug, Clone)]
44pub struct BitField {
45    /// Inclusive high bit index (7..=0, MSB first).
46    pub hi: u8,
47    /// Inclusive low bit index.
48    pub lo: u8,
49    /// The extracted field value.
50    pub raw: u64,
51    /// Human-readable meaning, e.g. `"physical = VarInt"`.
52    pub meaning: String,
53}
54
55/// Stream metadata attached to a [`RegionKind::DataBlob`] so the renderer can decode it.
56#[derive(Debug, Clone, Copy)]
57pub struct BlobInfo {
58    pub meta: StreamMeta,
59    pub hint: DecodeHint,
60}
61
62/// A single annotated span of the tile buffer.
63///
64/// Emitted in pre-order. Containers bracket their children and may overlap them.
65/// Leaf regions partition the buffer exactly; the coverage test relies on this.
66#[derive(Debug, Clone)]
67pub struct Region {
68    /// Absolute byte offset into the tile buffer.
69    pub offset: usize,
70    pub len: usize,
71    /// Nesting depth, for indentation.
72    pub depth: usize,
73    /// Short label, e.g. `"column[2].type"` or `"num_values"`.
74    pub label: String,
75    /// Rendered scalar value (varint value, string, enum name), if any.
76    pub value: Option<String>,
77    /// Bit-level breakdown; empty unless this is a bit-packed byte.
78    pub bits: Vec<BitField>,
79    pub kind: RegionKind,
80    /// True for structural groups that span their children (excluded from coverage).
81    pub container: bool,
82    /// Present for `DataBlob` regions that carry decodable stream metadata.
83    pub blob: Option<BlobInfo>,
84}
85
86/// The full annotation of a tile: a flat, depth-tagged region list.
87pub struct DumpTree {
88    pub buf_len: usize,
89    /// Regions in pre-order (containers before their children).
90    pub regions: Vec<Region>,
91}