Skip to main content

mlt_core/decoder/
analyze.rs

1use crate::decoder::{
2    GeoTypes, Geometry, GeometryType, GeometryValues, Id, Layer01, Property, RawFloats,
3    RawFloatsEncoding, RawFsstData, RawGeometry, RawId, RawIdValue, RawPlainData, RawPresence,
4    RawProperty, RawScalar, RawSharedDict, RawSharedDictEncoding, RawSharedDictItem, RawStrings,
5    RawStringsEncoding, StreamMeta,
6};
7#[cfg(feature = "unstable-v2")]
8use crate::decoder::{RawMValue, root02::ColumnValues};
9use crate::{Analyze, DecodeState, StatType};
10
11impl<'a, S: DecodeState> Analyze for Layer01<'a, S>
12where
13    Option<Id<'a, S>>: Analyze,
14    Geometry<'a, S>: Analyze,
15    Vec<Property<'a, S>>: Analyze,
16{
17    fn collect_statistic(&self, stat: StatType) -> usize {
18        match stat {
19            StatType::DecodedMetaSize => self.name().len() + size_of::<u32>(),
20            StatType::DecodedDataSize => {
21                self.id.collect_statistic(stat)
22                    + self.geometry.collect_statistic(stat)
23                    + self.properties.collect_statistic(stat)
24            }
25            StatType::FeatureCount => self.geometry.collect_statistic(stat),
26        }
27    }
28
29    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
30        self.id.for_each_stream(cb);
31        self.geometry.for_each_stream(cb);
32        self.properties.for_each_stream(cb);
33    }
34}
35
36impl Analyze for RawGeometry<'_> {
37    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
38        match &self.types {
39            GeoTypes::Stream(types) => types.for_each_stream(cb),
40            #[cfg(feature = "unstable-v2")]
41            GeoTypes::Uniform { .. } => {}
42        }
43        self.items.for_each_stream(cb);
44    }
45}
46
47impl Analyze for GeometryValues {
48    fn collect_statistic(&self, stat: StatType) -> usize {
49        match stat {
50            StatType::DecodedDataSize => {
51                self.vector_types.collect_statistic(stat)
52                    + self.geometry_offsets.collect_statistic(stat)
53                    + self.part_offsets.collect_statistic(stat)
54                    + self.ring_offsets.collect_statistic(stat)
55                    + self.index_buffer.collect_statistic(stat)
56                    + self.triangle_offsets.collect_statistic(stat)
57                    + self.vertices.collect_statistic(stat)
58            }
59            StatType::DecodedMetaSize => 0,
60            StatType::FeatureCount => self.vector_types.len(),
61        }
62    }
63}
64
65impl Analyze for GeometryType {
66    fn collect_statistic(&self, _stat: StatType) -> usize {
67        size_of::<Self>()
68    }
69}
70
71impl Analyze for RawId<'_> {
72    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
73        self.presence.for_each_stream(cb);
74        self.value.for_each_stream(cb);
75    }
76}
77
78impl Analyze for RawIdValue<'_> {
79    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
80        match self {
81            Self::Id32(v) | Self::Id64(v) => v.for_each_stream(cb),
82        }
83    }
84}
85
86impl Analyze for RawPresence<'_> {
87    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
88        match self {
89            Self::AllPresent => {}
90            // v2 presence is headerless, not a stream, whichever coding holds it.
91            #[cfg(feature = "unstable-v2")]
92            Self::Bitfield(_) | Self::Decoded(_) => {}
93            Self::Stream(s) => s.for_each_stream(cb),
94        }
95    }
96}
97
98impl Analyze for RawPlainData<'_> {
99    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
100        self.lengths.for_each_stream(cb);
101        self.data.for_each_stream(cb);
102    }
103}
104
105impl Analyze for RawFsstData<'_> {
106    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
107        self.symbol_lengths.for_each_stream(cb);
108        self.symbol_table.for_each_stream(cb);
109        self.lengths.for_each_stream(cb);
110        self.corpus.for_each_stream(cb);
111    }
112}
113
114impl Analyze for RawStringsEncoding<'_> {
115    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
116        match self {
117            Self::Plain(plain_data) => plain_data.for_each_stream(cb),
118            Self::Dictionary {
119                plain_data,
120                offsets,
121                dict: _,
122            } => {
123                plain_data.for_each_stream(cb);
124                offsets.for_each_stream(cb);
125            }
126            Self::FsstPlain(fsst_data) => fsst_data.for_each_stream(cb),
127            Self::FsstDictionary {
128                fsst_data,
129                offsets,
130                dict: _,
131            } => {
132                fsst_data.for_each_stream(cb);
133                offsets.for_each_stream(cb);
134            }
135        }
136    }
137}
138
139impl Analyze for RawScalar<'_> {
140    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
141        self.presence.for_each_stream(cb);
142        self.data.for_each_stream(cb);
143    }
144}
145
146impl Analyze for RawFloats<'_> {
147    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
148        self.presence.for_each_stream(cb);
149        self.encoding.for_each_stream(cb);
150    }
151}
152
153impl Analyze for RawFloatsEncoding<'_> {
154    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
155        match self {
156            Self::Single(data) => data.for_each_stream(cb),
157            #[cfg(feature = "unstable-v2")]
158            Self::Dictionary { codes, dictionary } => {
159                codes.for_each_stream(cb);
160                dictionary.for_each_stream(cb);
161            }
162            #[cfg(feature = "unstable-v2")]
163            Self::Alp { data, .. } => data.for_each_stream(cb),
164        }
165    }
166}
167
168impl Analyze for RawStrings<'_> {
169    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
170        self.presence.for_each_stream(cb);
171        self.encoding.for_each_stream(cb);
172    }
173}
174
175impl Analyze for RawSharedDictItem<'_> {
176    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
177        self.presence.for_each_stream(cb);
178        self.data.for_each_stream(cb);
179    }
180}
181
182impl Analyze for RawSharedDictEncoding<'_> {
183    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
184        match self {
185            Self::Plain(plain_data) => plain_data.for_each_stream(cb),
186            Self::FsstPlain(fsst_data) => fsst_data.for_each_stream(cb),
187        }
188    }
189}
190
191impl Analyze for RawSharedDict<'_> {
192    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
193        self.encoding.for_each_stream(cb);
194        self.children.for_each_stream(cb);
195    }
196}
197
198impl Analyze for RawProperty<'_> {
199    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
200        match self {
201            Self::Bool(s)
202            | Self::I8(s)
203            | Self::U8(s)
204            | Self::I32(s)
205            | Self::U32(s)
206            | Self::I64(s)
207            | Self::U64(s) => s.for_each_stream(cb),
208            Self::F32(s) | Self::F64(s) => s.for_each_stream(cb),
209            Self::Str(s) => s.for_each_stream(cb),
210            Self::SharedDict(s) => s.for_each_stream(cb),
211        }
212    }
213}
214
215#[cfg(feature = "unstable-v2")]
216impl Analyze for RawMValue<'_> {
217    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
218        match self {
219            Self::Bool(s)
220            | Self::I8(s)
221            | Self::U8(s)
222            | Self::I32(s)
223            | Self::U32(s)
224            | Self::I64(s)
225            | Self::U64(s) => s.for_each_stream(cb),
226            Self::F32(s) | Self::F64(s) => s.for_each_stream(cb),
227            Self::Str(s) => s.for_each_stream(cb),
228        }
229    }
230}
231
232#[cfg(feature = "unstable-v2")]
233impl Analyze for ColumnValues<'_> {
234    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
235        match self {
236            Self::Bool(s)
237            | Self::I8(s)
238            | Self::U8(s)
239            | Self::I32(s)
240            | Self::U32(s)
241            | Self::I64(s)
242            | Self::U64(s) => s.for_each_stream(cb),
243            Self::F32(s) | Self::F64(s) => s.for_each_stream(cb),
244            Self::Str(s) => s.for_each_stream(cb),
245        }
246    }
247}