Skip to main content

matter_kit/clusters/generated/
fixed_label.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Fixed Label — cluster 0x0040.
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//! Fixed Label (cluster `0x0040`, revision 1).
10//!
11//! 1 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 = 0x0040;
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 = "FLABEL";
35
36/// This cluster defines no features, so its `FeatureMap` is always zero.
37pub const FEATURES: &[Feature] = &[];
38
39/// The attribute ids.
40pub mod attribute {
41    use crate::im::AttributeId;
42
43    /// `LabelList`.
44    pub const LABEL_LIST: AttributeId = 0x00;
45}
46
47/// `LabelStruct`.
48#[derive(Debug, Clone, Copy, PartialEq)]
49pub struct LabelStruct<'a> {
50    /// `Label`, field 0.
51    pub label: &'a str,
52    /// `Value`, field 1.
53    pub value: &'a str,
54}
55
56impl<'a> ToTlv for LabelStruct<'a> {
57    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
58        w.start_structure(tag)?;
59        self.label.to_tlv(w, Tag::Context(0))?;
60        self.value.to_tlv(w, Tag::Context(1))?;
61        w.end_container()
62    }
63}
64
65impl<'a> FromTlv<'a> for LabelStruct<'a> {
66    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
67        if element.value.container() != Some(ContainerKind::Structure) {
68            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
69        }
70        let mut label = None;
71        let mut value = None;
72        loop {
73            let Some(field) = reader.next_element()? else {
74                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
75            };
76            if field.value == Value::EndOfContainer {
77                break;
78            }
79            match field.tag.context() {
80                Some(0) => label = Some(<&'a str>::from_tlv(reader, &field)?),
81                Some(1) => value = Some(<&'a str>::from_tlv(reader, &field)?),
82                // A field this revision does not define. §7.19.2: a receiver
83                // ignores what it does not know rather than refusing the whole
84                // structure, which is what lets a newer peer talk to an older one.
85                _ => reader.skip_value(&field)?,
86            }
87        }
88        Ok(Self {
89            label: label.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
90            value: value.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
91        })
92    }
93}
94
95/// Every attribute the specification defines, with its conformance.
96pub const ATTRIBUTES: &[Attribute] = &[Attribute {
97    id: 0x0000,
98    name: "LabelList",
99    kind: "list[LabelStruct]",
100    access: Access::read_only(Privilege::View),
101    qualities: AttributeQualities::NON_VOLATILE,
102    reporting: Reporting::OnChange,
103    conform: Conform::MANDATORY,
104}];
105
106/// Every command, with its conformance.
107pub const COMMANDS: &[Command] = &[];
108
109/// Every event, with its conformance.
110pub const EVENTS: &[Event] = &[];
111
112/// The whole cluster, as the specification defines it.
113pub const CLUSTER: Cluster = Cluster {
114    id: ID,
115    name: "Fixed Label",
116    revision: REVISION,
117    pics: "FLABEL",
118    derived_from: Some("Label"),
119    features: FEATURES,
120    attributes: ATTRIBUTES,
121    commands: COMMANDS,
122    events: EVENTS,
123};