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}
38
39/// One sub-field of a bit-packed byte, e.g. a nibble of `stream_type`.
40#[derive(Debug, Clone)]
41pub struct BitField {
42    /// Inclusive high bit index (7..=0, MSB first).
43    pub hi: u8,
44    /// Inclusive low bit index.
45    pub lo: u8,
46    /// The extracted field value.
47    pub raw: u64,
48    /// Human-readable meaning, e.g. `"physical = VarInt"`.
49    pub meaning: String,
50}
51
52/// Stream metadata attached to a [`RegionKind::DataBlob`] so the renderer can decode it.
53#[derive(Debug, Clone, Copy)]
54pub struct BlobInfo {
55    pub meta: StreamMeta,
56    pub hint: DecodeHint,
57}
58
59/// A single annotated span of the tile buffer.
60///
61/// Emitted in pre-order. Containers bracket their children and may overlap them.
62/// Leaf regions partition the buffer exactly; the coverage test relies on this.
63#[derive(Debug, Clone)]
64pub struct Region {
65    /// Absolute byte offset into the tile buffer.
66    pub offset: usize,
67    pub len: usize,
68    /// Nesting depth, for indentation.
69    pub depth: usize,
70    /// Short label, e.g. `"column[2].type"` or `"num_values"`.
71    pub label: String,
72    /// Rendered scalar value (varint value, string, enum name), if any.
73    pub value: Option<String>,
74    /// Bit-level breakdown; empty unless this is a bit-packed byte.
75    pub bits: Vec<BitField>,
76    pub kind: RegionKind,
77    /// True for structural groups that span their children (excluded from coverage).
78    pub container: bool,
79    /// Present for `DataBlob` regions that carry decodable stream metadata.
80    pub blob: Option<BlobInfo>,
81}
82
83/// The full annotation of a tile: a flat, depth-tagged region list.
84pub struct DumpTree {
85    pub buf_len: usize,
86    /// Regions in pre-order (containers before their children).
87    pub regions: Vec<Region>,
88}