mlt_core/decoder/
analyze.rs1use 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 #[cfg(feature = "unstable-v2")]
85 Self::Bitfield(_) => {}
86 Self::Stream(s) => s.for_each_stream(cb),
87 }
88 }
89}
90
91impl Analyze for RawPlainData<'_> {
92 fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
93 self.lengths.for_each_stream(cb);
94 self.data.for_each_stream(cb);
95 }
96}
97
98impl Analyze for RawFsstData<'_> {
99 fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
100 self.symbol_lengths.for_each_stream(cb);
101 self.symbol_table.for_each_stream(cb);
102 self.lengths.for_each_stream(cb);
103 self.corpus.for_each_stream(cb);
104 }
105}
106
107impl Analyze for RawStringsEncoding<'_> {
108 fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
109 match self {
110 Self::Plain(plain_data) => plain_data.for_each_stream(cb),
111 Self::Dictionary {
112 plain_data,
113 offsets,
114 } => {
115 plain_data.for_each_stream(cb);
116 offsets.for_each_stream(cb);
117 }
118 Self::FsstPlain(fsst_data) => fsst_data.for_each_stream(cb),
119 Self::FsstDictionary { fsst_data, offsets } => {
120 fsst_data.for_each_stream(cb);
121 offsets.for_each_stream(cb);
122 }
123 }
124 }
125}
126
127impl Analyze for RawScalar<'_> {
128 fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
129 self.presence.for_each_stream(cb);
130 self.data.for_each_stream(cb);
131 }
132}
133
134impl Analyze for RawStrings<'_> {
135 fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
136 self.presence.for_each_stream(cb);
137 self.encoding.for_each_stream(cb);
138 }
139}
140
141impl Analyze for RawSharedDictItem<'_> {
142 fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
143 self.presence.for_each_stream(cb);
144 self.data.for_each_stream(cb);
145 }
146}
147
148impl Analyze for RawSharedDictEncoding<'_> {
149 fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
150 match self {
151 Self::Plain(plain_data) => plain_data.for_each_stream(cb),
152 Self::FsstPlain(fsst_data) => fsst_data.for_each_stream(cb),
153 }
154 }
155}
156
157impl Analyze for RawSharedDict<'_> {
158 fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
159 self.encoding.for_each_stream(cb);
160 self.children.for_each_stream(cb);
161 }
162}
163
164impl Analyze for RawProperty<'_> {
165 fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
166 match self {
167 Self::Bool(s)
168 | Self::I8(s)
169 | Self::U8(s)
170 | Self::I32(s)
171 | Self::U32(s)
172 | Self::I64(s)
173 | Self::U64(s)
174 | Self::F32(s)
175 | Self::F64(s) => s.for_each_stream(cb),
176 Self::Str(s) => s.for_each_stream(cb),
177 Self::SharedDict(s) => s.for_each_stream(cb),
178 }
179 }
180}