Skip to main content

matter_kit/clusters/generated/
content_app_observer.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Content App Observer — cluster 0x0510.
4//
5// Regenerate with `cargo xtask clusters --dm <checkout>/data_model/1.6`; `cargo xtask check`
6// is the CI gate that keeps this file honest. The XML itself is not vendored here — it
7// carries the CSA's own copyright notice and is not redistributable.
8
9//! Content App Observer (cluster `0x0510`, revision 1).
10//!
11//! 2 identifiers, 0 feature bits, and the specification's own conformance for
12//! every element. `CLUSTER` is the whole table.
13
14#![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
26/// The cluster id.
27pub const ID: ClusterId = 0x0510;
28
29/// The highest revision the specification's history defines — what `ClusterRevision`
30/// must report (Core §7.13.1).
31pub const REVISION: u16 = 1;
32
33/// The PICS code, which a certification declaration names the cluster by.
34pub const PICS: &str = "APPOBSERVER";
35
36/// This cluster defines no features, so its `FeatureMap` is always zero.
37pub const FEATURES: &[Feature] = &[];
38
39/// The command ids.
40pub mod command {
41    use crate::im::CommandId;
42
43    /// `ContentAppMessage`.
44    pub const CONTENT_APP_MESSAGE: CommandId = 0x00;
45    /// `ContentAppMessageResponse`.
46    pub const CONTENT_APP_MESSAGE_RESPONSE: CommandId = 0x01;
47}
48
49/// `StatusEnum`.
50#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
51#[repr(u8)]
52pub enum StatusEnum {
53    /// Command succeeded
54    Success = 0,
55    /// Data field in command was not understood by the Observer
56    UnexpectedData = 1,
57}
58
59impl StatusEnum {
60    /// Reads a wire value, or `None` for one this revision does not define.
61    #[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    /// Its wire value.
71    #[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/// The fields of `ContentAppMessage` (command `0x00`).
91#[derive(Debug, Clone, Copy, PartialEq)]
92pub struct ContentAppMessageFields<'a> {
93    /// `Data`, field 0.
94    pub data: &'a str,
95    /// `EncodingHint`, field 1.
96    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                // A field this revision does not define. §7.19.2: a receiver
128                // ignores what it does not know rather than refusing the whole
129                // structure, which is what lets a newer peer talk to an older one.
130                _ => 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/// The fields of `ContentAppMessageResponse` (command `0x01`).
141#[derive(Debug, Clone, Copy, PartialEq)]
142pub struct ContentAppMessageResponseFields<'a> {
143    /// `Status`, field 0.
144    pub status: StatusEnum,
145    /// `Data`, field 1.
146    pub data: Option<&'a str>,
147    /// `EncodingHint`, field 2.
148    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                // A field this revision does not define. §7.19.2: a receiver
185                // ignores what it does not know rather than refusing the whole
186                // structure, which is what lets a newer peer talk to an older one.
187                _ => 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
198/// Every attribute the specification defines, with its conformance.
199pub const ATTRIBUTES: &[Attribute] = &[];
200
201/// Every command, with its conformance.
202pub 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
221/// Every event, with its conformance.
222pub const EVENTS: &[Event] = &[];
223
224/// The whole cluster, as the specification defines it.
225pub 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};