ebml_iterable_specification/
empty_spec.rs1use super::{EbmlSpecification, EbmlTag, Master, TagDataType, PathPart};
2
3#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd)]
11pub struct EmptySpec {
12 id: u64,
13 children: Option<Master<EmptySpec>>,
14 data: Option<Vec<u8>>,
15}
16
17impl EmptySpec {
18 pub fn with_children(id: u64, children: Vec<EmptySpec>) -> Self {
19 EmptySpec::get_master_tag(id, Master::Full(children)).unwrap()
20 }
21
22 pub fn with_data(id: u64, data: &[u8]) -> Self {
23 EmptySpec::get_binary_tag(id, data).unwrap()
24 }
25}
26
27impl EbmlSpecification<EmptySpec> for EmptySpec {
28 fn get_tag_data_type(_id: u64) -> Option<TagDataType> {
29 Some(TagDataType::Binary)
30 }
31
32 fn get_path_by_id(_id: u64) -> &'static [PathPart] {
33 &[]
34 }
35
36 fn get_unsigned_int_tag(_id: u64, _data: u64) -> Option<EmptySpec> {
37 None
38 }
39
40 fn get_signed_int_tag(_id: u64, _data: i64) -> Option<EmptySpec> {
41 None
42 }
43
44 fn get_utf8_tag(_id: u64, _data: String) -> Option<EmptySpec> {
45 None
46 }
47
48 fn get_binary_tag(id: u64, data: &[u8]) -> Option<EmptySpec> {
49 Some(EmptySpec {
50 id,
51 children: None,
52 data: Some(data.to_vec()),
53 })
54 }
55
56 fn get_float_tag(_id: u64, _data: f64) -> Option<EmptySpec> {
57 None
58 }
59
60 fn get_master_tag(id: u64, data: Master<EmptySpec>) -> Option<EmptySpec> {
61 Some(EmptySpec {
62 id,
63 children: Some(data),
64 data: None,
65 })
66 }
67
68 fn get_raw_tag(id: u64, data: &[u8]) -> EmptySpec {
69 EmptySpec::get_binary_tag(id, data).expect("get binary tag for EmptySpec should always return Some")
70 }
71}
72
73impl EbmlTag<EmptySpec> for EmptySpec {
74
75 fn get_id(&self) -> u64 {
76 self.id
77 }
78
79 fn as_unsigned_int(&self) -> Option<&u64> {
80 None
81 }
82
83 fn as_signed_int(&self) -> Option<&i64> {
84 None
85 }
86
87 fn as_utf8(&self) -> Option<&str> {
88 None
89 }
90
91 fn as_binary(&self) -> Option<&[u8]> {
92 self.data.as_deref()
93 }
94
95 fn as_float(&self) -> Option<&f64> {
96 None
97 }
98
99 fn as_master(&self) -> Option<&Master<EmptySpec>> {
100 match &self.children {
101 Some(children) => Some(children),
102 None => None
103 }
104 }
105}