Skip to main content

mlt_core/decoder/
analyze.rs

1use crate::decoder::{
2    Geometry, GeometryType, GeometryValues, Id, Layer01, Property, RawFsstData, RawGeometry, RawId,
3    RawIdValue, RawPlainData, RawPresence, RawProperty, RawScalar, RawSharedDict,
4    RawSharedDictEncoding, RawSharedDictItem, RawStrings, RawStringsEncoding, StreamMeta,
5};
6use crate::{Analyze, DecodeState, StatType};
7
8impl<'a, S: DecodeState> Analyze for Layer01<'a, S>
9where
10    Option<Id<'a, S>>: Analyze,
11    Geometry<'a, S>: Analyze,
12    Vec<Property<'a, S>>: Analyze,
13{
14    fn collect_statistic(&self, stat: StatType) -> usize {
15        match stat {
16            StatType::DecodedMetaSize => self.name().len() + size_of::<u32>(),
17            StatType::DecodedDataSize => {
18                self.id.collect_statistic(stat)
19                    + self.geometry.collect_statistic(stat)
20                    + self.properties.collect_statistic(stat)
21            }
22            StatType::FeatureCount => self.geometry.collect_statistic(stat),
23        }
24    }
25
26    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
27        self.id.for_each_stream(cb);
28        self.geometry.for_each_stream(cb);
29        self.properties.for_each_stream(cb);
30    }
31}
32
33impl Analyze for RawGeometry<'_> {
34    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
35        self.meta.for_each_stream(cb);
36        self.items.for_each_stream(cb);
37    }
38}
39
40impl Analyze for GeometryValues {
41    fn collect_statistic(&self, stat: StatType) -> usize {
42        match stat {
43            StatType::DecodedDataSize => {
44                self.vector_types.collect_statistic(stat)
45                    + self.geometry_offsets.collect_statistic(stat)
46                    + self.part_offsets.collect_statistic(stat)
47                    + self.ring_offsets.collect_statistic(stat)
48                    + self.index_buffer.collect_statistic(stat)
49                    + self.triangles.collect_statistic(stat)
50                    + self.vertices.collect_statistic(stat)
51            }
52            StatType::DecodedMetaSize => 0,
53            StatType::FeatureCount => self.vector_types.len(),
54        }
55    }
56}
57
58impl Analyze for GeometryType {
59    fn collect_statistic(&self, _stat: StatType) -> usize {
60        size_of::<Self>()
61    }
62}
63
64impl Analyze for RawId<'_> {
65    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
66        self.presence.for_each_stream(cb);
67        self.value.for_each_stream(cb);
68    }
69}
70
71impl Analyze for RawIdValue<'_> {
72    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
73        match self {
74            Self::Id32(v) | Self::Id64(v) => v.for_each_stream(cb),
75        }
76    }
77}
78
79impl Analyze for RawPresence<'_> {
80    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
81        match self {
82            Self::AllPresent => {}
83            Self::Stream(s) => s.for_each_stream(cb),
84        }
85    }
86}
87
88impl Analyze for RawPlainData<'_> {
89    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
90        self.lengths.for_each_stream(cb);
91        self.data.for_each_stream(cb);
92    }
93}
94
95impl Analyze for RawFsstData<'_> {
96    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
97        self.symbol_lengths.for_each_stream(cb);
98        self.symbol_table.for_each_stream(cb);
99        self.lengths.for_each_stream(cb);
100        self.corpus.for_each_stream(cb);
101    }
102}
103
104impl Analyze for RawStringsEncoding<'_> {
105    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
106        match self {
107            Self::Plain(plain_data) => plain_data.for_each_stream(cb),
108            Self::Dictionary {
109                plain_data,
110                offsets,
111            } => {
112                plain_data.for_each_stream(cb);
113                offsets.for_each_stream(cb);
114            }
115            Self::FsstPlain(fsst_data) => fsst_data.for_each_stream(cb),
116            Self::FsstDictionary { fsst_data, offsets } => {
117                fsst_data.for_each_stream(cb);
118                offsets.for_each_stream(cb);
119            }
120        }
121    }
122}
123
124impl Analyze for RawScalar<'_> {
125    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
126        self.presence.for_each_stream(cb);
127        self.data.for_each_stream(cb);
128    }
129}
130
131impl Analyze for RawStrings<'_> {
132    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
133        self.presence.for_each_stream(cb);
134        self.encoding.for_each_stream(cb);
135    }
136}
137
138impl Analyze for RawSharedDictItem<'_> {
139    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
140        self.presence.for_each_stream(cb);
141        self.data.for_each_stream(cb);
142    }
143}
144
145impl Analyze for RawSharedDictEncoding<'_> {
146    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
147        match self {
148            Self::Plain(plain_data) => plain_data.for_each_stream(cb),
149            Self::FsstPlain(fsst_data) => fsst_data.for_each_stream(cb),
150        }
151    }
152}
153
154impl Analyze for RawSharedDict<'_> {
155    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
156        self.encoding.for_each_stream(cb);
157        self.children.for_each_stream(cb);
158    }
159}
160
161impl Analyze for RawProperty<'_> {
162    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
163        match self {
164            Self::Bool(s)
165            | Self::I8(s)
166            | Self::U8(s)
167            | Self::I32(s)
168            | Self::U32(s)
169            | Self::I64(s)
170            | Self::U64(s)
171            | Self::F32(s)
172            | Self::F64(s) => s.for_each_stream(cb),
173            Self::Str(s) => s.for_each_stream(cb),
174            Self::SharedDict(s) => s.for_each_stream(cb),
175        }
176    }
177}