matter_kit/clusters/generated/
content_app_observer.rs1#![allow(unused_imports)]
15
16use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
17use crate::dm::meta::{EventPriority, Reporting};
18use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
19use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
20use crate::error::Result;
21use crate::im::{AttributeId, ClusterId, CommandId, EventId};
22use crate::tlv::{
23 ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
24};
25
26pub const ID: ClusterId = 0x0510;
28
29pub const REVISION: u16 = 1;
32
33pub const PICS: &str = "APPOBSERVER";
35
36pub const FEATURES: &[Feature] = &[];
38
39pub mod command {
41 use crate::im::CommandId;
42
43 pub const CONTENT_APP_MESSAGE: CommandId = 0x00;
45 pub const CONTENT_APP_MESSAGE_RESPONSE: CommandId = 0x01;
47}
48
49#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
51#[repr(u8)]
52pub enum StatusEnum {
53 Success = 0,
55 UnexpectedData = 1,
57}
58
59impl StatusEnum {
60 #[must_use]
62 pub const fn from_value(value: u8) -> Option<Self> {
63 match value {
64 0 => Some(Self::Success),
65 1 => Some(Self::UnexpectedData),
66 _ => None,
67 }
68 }
69
70 #[must_use]
72 pub const fn value(self) -> u8 {
73 self as u8
74 }
75}
76
77impl ToTlv for StatusEnum {
78 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
79 self.value().to_tlv(w, tag)
80 }
81}
82
83impl<'a> FromTlv<'a> for StatusEnum {
84 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
85 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
86 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
87 }
88}
89
90#[derive(Debug, Clone, Copy, PartialEq)]
92pub struct ContentAppMessageFields<'a> {
93 pub data: &'a str,
95 pub encoding_hint: Option<&'a str>,
97}
98
99impl<'a> ToTlv for ContentAppMessageFields<'a> {
100 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
101 w.start_structure(tag)?;
102 self.data.to_tlv(w, Tag::Context(0))?;
103 if let Some(value) = &self.encoding_hint {
104 value.to_tlv(w, Tag::Context(1))?;
105 }
106 w.end_container()
107 }
108}
109
110impl<'a> FromTlv<'a> for ContentAppMessageFields<'a> {
111 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
112 if element.value.container() != Some(ContainerKind::Structure) {
113 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
114 }
115 let mut data = None;
116 let mut encoding_hint = None;
117 loop {
118 let Some(field) = reader.next_element()? else {
119 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
120 };
121 if field.value == Value::EndOfContainer {
122 break;
123 }
124 match field.tag.context() {
125 Some(0) => data = Some(<&'a str>::from_tlv(reader, &field)?),
126 Some(1) => encoding_hint = Some(<&'a str>::from_tlv(reader, &field)?),
127 _ => reader.skip_value(&field)?,
131 }
132 }
133 Ok(Self {
134 data: data.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
135 encoding_hint,
136 })
137 }
138}
139
140#[derive(Debug, Clone, Copy, PartialEq)]
142pub struct ContentAppMessageResponseFields<'a> {
143 pub status: StatusEnum,
145 pub data: Option<&'a str>,
147 pub encoding_hint: Option<&'a str>,
149}
150
151impl<'a> ToTlv for ContentAppMessageResponseFields<'a> {
152 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
153 w.start_structure(tag)?;
154 self.status.to_tlv(w, Tag::Context(0))?;
155 if let Some(value) = &self.data {
156 value.to_tlv(w, Tag::Context(1))?;
157 }
158 if let Some(value) = &self.encoding_hint {
159 value.to_tlv(w, Tag::Context(2))?;
160 }
161 w.end_container()
162 }
163}
164
165impl<'a> FromTlv<'a> for ContentAppMessageResponseFields<'a> {
166 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
167 if element.value.container() != Some(ContainerKind::Structure) {
168 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
169 }
170 let mut status = None;
171 let mut data = None;
172 let mut encoding_hint = None;
173 loop {
174 let Some(field) = reader.next_element()? else {
175 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
176 };
177 if field.value == Value::EndOfContainer {
178 break;
179 }
180 match field.tag.context() {
181 Some(0) => status = Some(<StatusEnum>::from_tlv(reader, &field)?),
182 Some(1) => data = Some(<&'a str>::from_tlv(reader, &field)?),
183 Some(2) => encoding_hint = Some(<&'a str>::from_tlv(reader, &field)?),
184 _ => reader.skip_value(&field)?,
188 }
189 }
190 Ok(Self {
191 status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
192 data,
193 encoding_hint,
194 })
195 }
196}
197
198pub const ATTRIBUTES: &[Attribute] = &[];
200
201pub const COMMANDS: &[Command] = &[
203 Command {
204 id: 0x00,
205 name: "ContentAppMessage",
206 to_server: true,
207 response: Some(0x01),
208 access: Access::invoke(Privilege::Operate),
209 conform: Conform::MANDATORY,
210 },
211 Command {
212 id: 0x01,
213 name: "ContentAppMessageResponse",
214 to_server: false,
215 response: None,
216 access: Access::invoke(Privilege::Operate),
217 conform: Conform::MANDATORY,
218 },
219];
220
221pub const EVENTS: &[Event] = &[];
223
224pub const CLUSTER: Cluster = Cluster {
226 id: ID,
227 name: "Content App Observer",
228 revision: REVISION,
229 pics: "APPOBSERVER",
230 derived_from: None,
231 features: FEATURES,
232 attributes: ATTRIBUTES,
233 commands: COMMANDS,
234 events: EVENTS,
235};