matter_clusters/gen/
fixed_label.rs1#![allow(
5 clippy::all,
6 clippy::pedantic,
7 dead_code,
8 unreachable_pub,
9 unused_imports
10)]
11
12use crate::datatypes::SemanticTagStruct;
13use crate::error::ClusterError;
14use crate::types::Nullable;
15use matter_codec::{ContainerKind, Element, Tag, TlvReader, TlvWriter, Value};
16
17pub const CLUSTER_ID: u32 = 0x0040;
19pub const CLUSTER_REVISION: u16 = 1;
21
22pub mod command_id {}
24
25pub mod attribute_id {
27 pub const LABEL_LIST: u32 = 0x0000;
29}
30
31#[derive(Clone, Debug, PartialEq)]
33#[non_exhaustive]
34pub struct LabelStruct {
35 pub label: String,
37 pub value: String,
39}
40
41impl LabelStruct {
42 pub fn decode_from(r: &mut TlvReader<'_>) -> Result<Self, ClusterError> {
48 let mut f_label: Option<String> = None;
49 let mut f_value: Option<String> = None;
50 loop {
51 match r.next()? {
52 Some(Element::ContainerEnd) => break,
53 Some(Element::Scalar {
54 tag: Tag::Context(0),
55 value: Value::Utf8(v),
56 }) => f_label = Some(v),
57 Some(Element::Scalar {
58 tag: Tag::Context(1),
59 value: Value::Utf8(v),
60 }) => f_value = Some(v),
61 None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
62 Some(Element::ContainerStart { .. }) => r.skip_container()?,
63 Some(_) => {} }
65 }
66 Ok(Self {
67 label: f_label.ok_or(ClusterError::MissingField("Label"))?,
68 value: f_value.ok_or(ClusterError::MissingField("Value"))?,
69 })
70 }
71 pub fn decode(tlv: &[u8]) -> Result<Self, ClusterError> {
76 let mut r = TlvReader::new(tlv);
77 match r.next()? {
78 Some(Element::ContainerStart {
79 kind: ContainerKind::Structure,
80 ..
81 }) => {}
82 _ => {
83 return Err(ClusterError::UnexpectedType {
84 context: "LabelStruct",
85 })
86 }
87 }
88 Self::decode_from(&mut r)
89 }
90 #[allow(clippy::expect_used)] pub fn write_fields(&self, w: &mut TlvWriter<'_>) {
93 w.put_utf8(Tag::Context(0), &self.label)
94 .expect("infallible: vec writer");
95 w.put_utf8(Tag::Context(1), &self.value)
96 .expect("infallible: vec writer");
97 }
98 #[must_use]
100 #[allow(clippy::expect_used)] pub fn encode(&self) -> Vec<u8> {
102 let mut buf = Vec::new();
103 let mut w = TlvWriter::new(&mut buf);
104 w.start_structure(Tag::Anonymous)
105 .expect("infallible: vec writer");
106 self.write_fields(&mut w);
107 w.end_container().expect("infallible: vec writer");
108 buf
109 }
110}
111
112pub fn decode_label_list(tlv: &[u8]) -> Result<Vec<LabelStruct>, ClusterError> {
117 let mut r = TlvReader::new(tlv);
118 match r.next()? {
119 Some(Element::ContainerStart {
120 kind: ContainerKind::Array,
121 ..
122 }) => {}
123 _ => {
124 return Err(ClusterError::UnexpectedType {
125 context: "LabelList",
126 })
127 }
128 }
129 let r = &mut r;
130 let mut out = Vec::new();
131 loop {
132 match r.next()? {
133 Some(Element::ContainerEnd) => break,
134 Some(Element::ContainerStart {
135 kind: ContainerKind::Structure,
136 ..
137 }) => {
138 out.push(LabelStruct::decode_from(r)?);
139 }
140 None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
141 Some(Element::ContainerStart { .. }) => r.skip_container()?,
142 Some(_) => {} }
144 }
145 Ok(out)
146}