Skip to main content

mlt_core/frames/v01/stream/
model.rs

1use num_enum::TryFromPrimitive;
2
3/// Logical encoding technique used for a column, as stored in the tile
4#[derive(Debug, Clone, Copy, PartialEq, TryFromPrimitive)]
5#[repr(u8)]
6pub enum LogicalTechnique {
7    None = 0,
8    Delta = 1,
9    ComponentwiseDelta = 2,
10    Rle = 3,
11    Morton = 4,
12    PseudoDecimal = 5,
13}
14
15/// Metadata for RLE decoding
16/// TODO v2 optimizations:
17///   * runs is identical to half the size of the associated array
18///   * `num_rle_values` is identical to the size of the sum of the first half of the array.
19///     Computing checked sum should not be too expensive.
20#[derive(Debug, Clone, Copy, PartialEq)]
21pub struct RleMeta {
22    pub runs: u32,
23    pub num_rle_values: u32,
24}
25
26/// Metadata for Morton decoding
27#[derive(Debug, Clone, Copy, PartialEq)]
28pub struct MortonMeta {
29    pub num_bits: u32,
30    pub coordinate_shift: u32,
31}
32
33/// How should the stream be interpreted at the logical level (second pass of decoding)
34#[derive(Clone, Copy, PartialEq)]
35pub enum LogicalEncoding {
36    None,
37    Delta,
38    DeltaRle(RleMeta),
39    ComponentwiseDelta,
40    Rle(RleMeta),
41    Morton(MortonMeta),
42    MortonDelta(MortonMeta),
43    MortonRle(MortonMeta),
44    PseudoDecimal,
45}
46
47/// Carries the stream metadata needed to perform the logical decode pass.
48///
49/// Construct with [`LogicalValue::new`] after the physical decode pass fills a
50/// `&[u32]` or `&[u64]` buffer, then call the appropriate `decode_*` method,
51/// passing that slice as `data`.
52#[derive(Debug, PartialEq)]
53pub struct LogicalValue {
54    pub(crate) meta: StreamMeta,
55}
56
57// Physical encoding types
58
59/// Dictionary type used for a column, as stored in the tile
60#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, TryFromPrimitive)]
61#[repr(u8)]
62pub enum DictionaryType {
63    None = 0,
64    Single = 1,
65    Shared = 2,
66    Vertex = 3,
67    Morton = 4,
68    Fsst = 5,
69}
70
71/// Offset type used for a column, as stored in the tile
72#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, TryFromPrimitive)]
73#[repr(u8)]
74pub enum OffsetType {
75    Vertex = 0,
76    Index = 1,
77    String = 2,
78    Key = 3,
79}
80
81/// Length type used for a column, as stored in the tile
82#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, TryFromPrimitive)]
83#[repr(u8)]
84pub enum LengthType {
85    VarBinary = 0,
86    Geometries = 1,
87    Parts = 2,
88    Rings = 3,
89    Triangles = 4,
90    Symbol = 5,
91    Dictionary = 6,
92}
93
94/// How should the stream be interpreted at the physical level (first pass of decoding)
95#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
96pub enum StreamType {
97    Present,
98    Data(DictionaryType),
99    Offset(OffsetType),
100    Length(LengthType),
101}
102
103/// Physical encoding used for a column, as stored in the tile
104#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, TryFromPrimitive)]
105#[repr(u8)]
106pub enum PhysicalEncoding {
107    None = 0,
108    /// Preferred, tends to produce the best compression ratio and decoding performance.
109    /// But currently limited to 32-bit integer.
110    FastPFOR = 1,
111    /// Can produce better results in combination with a heavyweight compression scheme like `Gzip`.
112    /// Simple compression scheme where the encoding is easier to implement compared to `FastPfor`.
113    VarInt = 2,
114    /// Adaptive Lossless floating-Point Compression
115    Alp = 3,
116}
117
118// RawStream types
119
120#[derive(Clone, Copy, PartialEq)]
121pub struct IntEncoding {
122    pub logical: LogicalEncoding,
123    pub physical: PhysicalEncoding,
124}
125
126/// Metadata about an encoded stream
127#[derive(Clone, Copy, PartialEq)]
128pub struct StreamMeta {
129    pub stream_type: StreamType,
130    pub encoding: IntEncoding,
131    pub num_values: u32,
132}
133
134/// Representation of an encoded stream
135#[derive(Debug, PartialEq, Clone)]
136pub struct RawStream<'a> {
137    pub meta: StreamMeta,
138    pub data: RawStreamData<'a>,
139}
140
141/// Owned variant of [`RawStream`].
142#[derive(Debug, PartialEq, Clone)]
143pub struct EncodedStream {
144    pub meta: StreamMeta,
145    pub data: EncodedStreamData,
146}
147
148#[derive(PartialEq, Clone)]
149pub enum RawStreamData<'a> {
150    VarInt(&'a [u8]),
151    Encoded(&'a [u8]),
152}
153
154#[derive(PartialEq, Clone)]
155pub enum EncodedStreamData {
156    VarInt(Vec<u8>),
157    Encoded(Vec<u8>),
158}