Skip to main content

mlt_core/frames/v01/property/
analyze.rs

1use crate::analyse::{Analyze, StatType};
2use crate::v01::{EncodedProperty, ParsedScalar, ParsedSharedDict, RawProperty, StreamMeta};
3
4impl Analyze for EncodedProperty {
5    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
6        match self {
7            EncodedProperty::Bool(s)
8            | EncodedProperty::I8(s)
9            | EncodedProperty::U8(s)
10            | EncodedProperty::I32(s)
11            | EncodedProperty::U32(s)
12            | EncodedProperty::I64(s)
13            | EncodedProperty::U64(s)
14            | EncodedProperty::F32(s)
15            | EncodedProperty::F64(s) => {
16                s.presence.0.for_each_stream(cb);
17                s.data.for_each_stream(cb);
18            }
19            EncodedProperty::Str(s) => {
20                s.presence.0.for_each_stream(cb);
21                for stream in s.encoding.streams() {
22                    stream.for_each_stream(cb);
23                }
24            }
25            EncodedProperty::SharedDict(s) => {
26                for stream in s.encoding.dict_streams() {
27                    stream.for_each_stream(cb);
28                }
29                for child in &s.children {
30                    child.presence.0.for_each_stream(cb);
31                    child.data.for_each_stream(cb);
32                }
33            }
34        }
35    }
36}
37
38impl Analyze for RawProperty<'_> {
39    fn for_each_stream(&self, cb: &mut dyn FnMut(StreamMeta)) {
40        match self {
41            Self::Bool(s)
42            | Self::I8(s)
43            | Self::U8(s)
44            | Self::I32(s)
45            | Self::U32(s)
46            | Self::I64(s)
47            | Self::U64(s)
48            | Self::F32(s)
49            | Self::F64(s) => {
50                s.presence.0.for_each_stream(cb);
51                s.data.for_each_stream(cb);
52            }
53            Self::Str(s) => {
54                s.presence.0.for_each_stream(cb);
55                for stream in s.encoding.streams() {
56                    stream.for_each_stream(cb);
57                }
58            }
59            Self::SharedDict(s) => {
60                for stream in s.encoding.dict_streams() {
61                    stream.for_each_stream(cb);
62                }
63                for child in &s.children {
64                    child.presence.0.for_each_stream(cb);
65                    child.data.for_each_stream(cb);
66                }
67            }
68        }
69    }
70}
71
72impl<T: Analyze + Copy + PartialEq> Analyze for ParsedScalar<'_, T> {
73    fn collect_statistic(&self, stat: StatType) -> usize {
74        let meta = if stat == StatType::DecodedMetaSize {
75            self.name.len()
76        } else {
77            0
78        };
79        meta + self.values.collect_statistic(stat)
80    }
81}
82
83impl Analyze for ParsedSharedDict<'_> {
84    fn collect_statistic(&self, stat: StatType) -> usize {
85        let meta = if stat == StatType::DecodedMetaSize {
86            self.prefix.len()
87        } else {
88            0
89        };
90        meta + self
91            .items
92            .iter()
93            .map(|item| item.materialize(self).collect_statistic(stat))
94            .sum::<usize>()
95    }
96}