Skip to main content

matter_kit/clusters/generated/
audio_output.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Audio Output — cluster 0x050B.
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//! Audio Output (cluster `0x050B`, revision 1).
10//!
11//! 4 identifiers, 1 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 = 0x050B;
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 = "AUDIOOUTPUT";
35
36/// The `FeatureMap` bits (Core §7.13.2).
37///
38/// A feature has conformance of its own: a device may not claim one the
39/// specification forbids it alongside another.
40pub mod feature {
41    /// Supports updates to output names
42    ///
43    /// Code `NU`, bit 0.
44    pub const NAME_UPDATES: u32 = 1 << 0;
45}
46
47/// Every feature bit, with its conformance.
48pub const FEATURES: &[Feature] = &[Feature {
49    bit: 0,
50    code: "NU",
51    name: "NameUpdates",
52    conform: Conform::OPTIONAL,
53}];
54
55/// The attribute ids.
56pub mod attribute {
57    use crate::im::AttributeId;
58
59    /// `OutputList`.
60    pub const OUTPUT_LIST: AttributeId = 0x00;
61    /// `CurrentOutput`.
62    pub const CURRENT_OUTPUT: AttributeId = 0x01;
63}
64
65/// The command ids.
66pub mod command {
67    use crate::im::CommandId;
68
69    /// `SelectOutput`.
70    pub const SELECT_OUTPUT: CommandId = 0x00;
71    /// `RenameOutput`.
72    pub const RENAME_OUTPUT: CommandId = 0x01;
73}
74
75/// `OutputTypeEnum`.
76#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
77#[repr(u8)]
78pub enum OutputTypeEnum {
79    /// HDMI
80    HDMI = 0,
81    /// `BT`.
82    BT = 1,
83    /// `Optical`.
84    Optical = 2,
85    /// `Headphone`.
86    Headphone = 3,
87    /// `Internal`.
88    Internal = 4,
89    /// `Other`.
90    Other = 5,
91}
92
93impl OutputTypeEnum {
94    /// Reads a wire value, or `None` for one this revision does not define.
95    #[must_use]
96    pub const fn from_value(value: u8) -> Option<Self> {
97        match value {
98            0 => Some(Self::HDMI),
99            1 => Some(Self::BT),
100            2 => Some(Self::Optical),
101            3 => Some(Self::Headphone),
102            4 => Some(Self::Internal),
103            5 => Some(Self::Other),
104            _ => None,
105        }
106    }
107
108    /// Its wire value.
109    #[must_use]
110    pub const fn value(self) -> u8 {
111        self as u8
112    }
113}
114
115impl ToTlv for OutputTypeEnum {
116    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
117        self.value().to_tlv(w, tag)
118    }
119}
120
121impl<'a> FromTlv<'a> for OutputTypeEnum {
122    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
123        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
124        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
125    }
126}
127
128/// `OutputInfoStruct`.
129#[derive(Debug, Clone, Copy, PartialEq)]
130pub struct OutputInfoStruct<'a> {
131    /// `Index`, field 0.
132    pub index: u8,
133    /// `OutputType`, field 1.
134    pub output_type: OutputTypeEnum,
135    /// `Name`, field 2.
136    pub name: &'a str,
137}
138
139impl<'a> ToTlv for OutputInfoStruct<'a> {
140    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
141        w.start_structure(tag)?;
142        self.index.to_tlv(w, Tag::Context(0))?;
143        self.output_type.to_tlv(w, Tag::Context(1))?;
144        self.name.to_tlv(w, Tag::Context(2))?;
145        w.end_container()
146    }
147}
148
149impl<'a> FromTlv<'a> for OutputInfoStruct<'a> {
150    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
151        if element.value.container() != Some(ContainerKind::Structure) {
152            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
153        }
154        let mut index = None;
155        let mut output_type = None;
156        let mut name = None;
157        loop {
158            let Some(field) = reader.next_element()? else {
159                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
160            };
161            if field.value == Value::EndOfContainer {
162                break;
163            }
164            match field.tag.context() {
165                Some(0) => index = Some(<u8>::from_tlv(reader, &field)?),
166                Some(1) => output_type = Some(<OutputTypeEnum>::from_tlv(reader, &field)?),
167                Some(2) => name = Some(<&'a str>::from_tlv(reader, &field)?),
168                // A field this revision does not define. §7.19.2: a receiver
169                // ignores what it does not know rather than refusing the whole
170                // structure, which is what lets a newer peer talk to an older one.
171                _ => reader.skip_value(&field)?,
172            }
173        }
174        Ok(Self {
175            index: index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
176            output_type: output_type.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
177            name: name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
178        })
179    }
180}
181
182/// The fields of `SelectOutput` (command `0x00`).
183#[derive(Debug, Clone, Copy, PartialEq)]
184pub struct SelectOutputFields {
185    /// `Index`, field 0.
186    pub index: u8,
187}
188
189impl ToTlv for SelectOutputFields {
190    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
191        w.start_structure(tag)?;
192        self.index.to_tlv(w, Tag::Context(0))?;
193        w.end_container()
194    }
195}
196
197impl<'a> FromTlv<'a> for SelectOutputFields {
198    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
199        if element.value.container() != Some(ContainerKind::Structure) {
200            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
201        }
202        let mut index = None;
203        loop {
204            let Some(field) = reader.next_element()? else {
205                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
206            };
207            if field.value == Value::EndOfContainer {
208                break;
209            }
210            match field.tag.context() {
211                Some(0) => index = Some(<u8>::from_tlv(reader, &field)?),
212                // A field this revision does not define. §7.19.2: a receiver
213                // ignores what it does not know rather than refusing the whole
214                // structure, which is what lets a newer peer talk to an older one.
215                _ => reader.skip_value(&field)?,
216            }
217        }
218        Ok(Self {
219            index: index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
220        })
221    }
222}
223
224/// The fields of `RenameOutput` (command `0x01`).
225#[derive(Debug, Clone, Copy, PartialEq)]
226pub struct RenameOutputFields<'a> {
227    /// `Index`, field 0.
228    pub index: u8,
229    /// `Name`, field 1.
230    pub name: &'a str,
231}
232
233impl<'a> ToTlv for RenameOutputFields<'a> {
234    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
235        w.start_structure(tag)?;
236        self.index.to_tlv(w, Tag::Context(0))?;
237        self.name.to_tlv(w, Tag::Context(1))?;
238        w.end_container()
239    }
240}
241
242impl<'a> FromTlv<'a> for RenameOutputFields<'a> {
243    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
244        if element.value.container() != Some(ContainerKind::Structure) {
245            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
246        }
247        let mut index = None;
248        let mut name = None;
249        loop {
250            let Some(field) = reader.next_element()? else {
251                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
252            };
253            if field.value == Value::EndOfContainer {
254                break;
255            }
256            match field.tag.context() {
257                Some(0) => index = Some(<u8>::from_tlv(reader, &field)?),
258                Some(1) => name = Some(<&'a str>::from_tlv(reader, &field)?),
259                // A field this revision does not define. §7.19.2: a receiver
260                // ignores what it does not know rather than refusing the whole
261                // structure, which is what lets a newer peer talk to an older one.
262                _ => reader.skip_value(&field)?,
263            }
264        }
265        Ok(Self {
266            index: index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
267            name: name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
268        })
269    }
270}
271
272/// Every attribute the specification defines, with its conformance.
273pub const ATTRIBUTES: &[Attribute] = &[
274    Attribute {
275        id: 0x0000,
276        name: "OutputList",
277        kind: "list[OutputInfoStruct]",
278        access: Access::read_only(Privilege::View),
279        qualities: AttributeQualities::empty(),
280        reporting: Reporting::OnChange,
281        conform: Conform::MANDATORY,
282    },
283    Attribute {
284        id: 0x0001,
285        name: "CurrentOutput",
286        kind: "uint8",
287        access: Access::read_only(Privilege::View),
288        qualities: AttributeQualities::empty(),
289        reporting: Reporting::OnChange,
290        conform: Conform::MANDATORY,
291    },
292];
293
294/// Every command, with its conformance.
295pub const COMMANDS: &[Command] = &[
296    Command {
297        id: 0x00,
298        name: "SelectOutput",
299        to_server: true,
300        response: None,
301        access: Access::invoke(Privilege::Operate),
302        conform: Conform::MANDATORY,
303    },
304    Command {
305        id: 0x01,
306        name: "RenameOutput",
307        to_server: true,
308        response: None,
309        access: Access::invoke(Privilege::Manage),
310        conform: Conform {
311            clauses: &[Clause {
312                verdict: Conformance::Mandatory,
313                when: Condition::Feature(0),
314            }],
315        },
316    },
317];
318
319/// Every event, with its conformance.
320pub const EVENTS: &[Event] = &[];
321
322/// The whole cluster, as the specification defines it.
323pub const CLUSTER: Cluster = Cluster {
324    id: ID,
325    name: "Audio Output",
326    revision: REVISION,
327    pics: "AUDIOOUTPUT",
328    derived_from: None,
329    features: FEATURES,
330    attributes: ATTRIBUTES,
331    commands: COMMANDS,
332    events: EVENTS,
333};