1use derive_debug::Dbg;
2use num_enum::TryFromPrimitive;
3
4use crate::utils::formatter::{bytes_dbg, compact_dbg};
5use crate::{MltError, MltResult};
6
7#[derive(Debug, Clone, Copy, PartialEq, TryFromPrimitive)]
9#[repr(u8)]
10pub enum LogicalTechnique {
11 None = 0,
12 Delta = 1,
13 ComponentwiseDelta = 2,
14 Rle = 3,
15 Morton = 4,
16 PseudoDecimal = 5,
17}
18
19#[derive(Debug, Clone, Copy, PartialEq)]
25pub struct RleMeta {
26 pub(crate) runs: u32,
27 pub(crate) num_rle_values: u32,
28}
29
30#[derive(Debug, Clone, Copy, PartialEq)]
32pub struct Morton {
33 pub(crate) bits: u32,
35 pub(crate) shift: u32,
37}
38
39impl Morton {
40 pub fn new(bits: u32, shift: u32) -> MltResult<Self> {
41 if bits <= 16 {
42 Ok(Self { bits, shift })
43 } else {
44 Err(MltError::InvalidMortonBits(bits))
45 }
46 }
47}
48
49#[derive(Debug, Clone, Copy, PartialEq)]
51pub enum LogicalEncoding {
52 None,
53 Delta,
54 DeltaRle(RleMeta),
55 ComponentwiseDelta,
56 Rle(RleMeta),
57 Morton(Morton),
58 MortonDelta(Morton),
59 MortonRle(Morton),
60 PseudoDecimal,
61}
62
63#[derive(Debug, PartialEq)]
69pub struct LogicalValue {
70 pub(crate) meta: StreamMeta,
71}
72
73#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, TryFromPrimitive)]
77#[repr(u8)]
78pub enum DictionaryType {
79 None = 0,
80 Single = 1,
81 Shared = 2,
82 Vertex = 3,
83 Morton = 4,
84 Fsst = 5,
85}
86
87#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, TryFromPrimitive)]
89#[repr(u8)]
90pub enum OffsetType {
91 Vertex = 0,
92 Index = 1,
93 String = 2,
94 Key = 3,
95}
96
97#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, TryFromPrimitive)]
99#[repr(u8)]
100pub enum LengthType {
101 VarBinary = 0,
102 Geometries = 1,
103 Parts = 2,
104 Rings = 3,
105 Triangles = 4,
106 Symbol = 5,
107 Dictionary = 6,
108}
109
110#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
112pub enum StreamType {
113 Present,
114 Data(DictionaryType),
115 Offset(OffsetType),
116 Length(LengthType),
117}
118
119#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, TryFromPrimitive)]
121#[repr(u8)]
122pub enum PhysicalEncoding {
123 None = 0,
124 FastPFor256 = 1,
127 VarInt = 2,
130}
131
132#[derive(Debug, Clone, Copy, PartialEq)]
135pub struct IntEncoding {
136 pub logical: LogicalEncoding,
137 pub physical: PhysicalEncoding,
138}
139
140#[derive(Clone, Copy, Dbg, PartialEq)]
142pub struct StreamMeta {
143 #[dbg(formatter = "compact_dbg")]
144 pub stream_type: StreamType,
145 #[dbg(formatter = "compact_dbg")]
146 pub encoding: IntEncoding,
147 pub(crate) num_values: u32,
148}
149
150#[derive(Clone, Dbg, PartialEq)]
152pub struct RawStream<'a> {
153 pub meta: StreamMeta,
154 #[dbg(formatter = "bytes_dbg")]
155 pub(crate) data: &'a [u8],
156}