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