Skip to main content

matter_kit/clusters/generated/
binding.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Binding — cluster 0x001E.
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//! Binding (cluster `0x001E`, 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 = 0x001E;
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 = "BIND";
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    /// `Binding`.
44    pub const BINDING: AttributeId = 0x00;
45}
46
47/// `TargetStruct`, fabric-scoped — §7.19.1.9's `FabricIndex` is field 254.
48#[derive(Debug, Clone, Copy, PartialEq)]
49pub struct TargetStruct {
50    /// `Node`, field 1.
51    pub node: Option<crate::msg::NodeId>,
52    /// `Group`, field 2.
53    pub group: Option<crate::msg::GroupId>,
54    /// `Endpoint`, field 3.
55    pub endpoint: Option<u16>,
56    /// `Cluster`, field 4.
57    pub cluster: Option<u32>,
58    /// `FabricIndex`, field 254.
59    pub fabric_index: crate::msg::FabricIndex,
60}
61
62impl ToTlv for TargetStruct {
63    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
64        w.start_structure(tag)?;
65        if let Some(value) = &self.node {
66            value.to_tlv(w, Tag::Context(1))?;
67        }
68        if let Some(value) = &self.group {
69            value.to_tlv(w, Tag::Context(2))?;
70        }
71        if let Some(value) = &self.endpoint {
72            value.to_tlv(w, Tag::Context(3))?;
73        }
74        if let Some(value) = &self.cluster {
75            value.to_tlv(w, Tag::Context(4))?;
76        }
77        self.fabric_index.to_tlv(w, Tag::Context(254))?;
78        w.end_container()
79    }
80}
81
82impl<'a> FromTlv<'a> for TargetStruct {
83    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
84        if element.value.container() != Some(ContainerKind::Structure) {
85            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
86        }
87        let mut node = None;
88        let mut group = None;
89        let mut endpoint = None;
90        let mut cluster = None;
91        let mut fabric_index = None;
92        loop {
93            let Some(field) = reader.next_element()? else {
94                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
95            };
96            if field.value == Value::EndOfContainer {
97                break;
98            }
99            match field.tag.context() {
100                Some(1) => node = Some(<crate::msg::NodeId>::from_tlv(reader, &field)?),
101                Some(2) => group = Some(<crate::msg::GroupId>::from_tlv(reader, &field)?),
102                Some(3) => endpoint = Some(<u16>::from_tlv(reader, &field)?),
103                Some(4) => cluster = Some(<u32>::from_tlv(reader, &field)?),
104                Some(254) => {
105                    fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
106                }
107                // A field this revision does not define. §7.19.2: a receiver
108                // ignores what it does not know rather than refusing the whole
109                // structure, which is what lets a newer peer talk to an older one.
110                _ => reader.skip_value(&field)?,
111            }
112        }
113        Ok(Self {
114            node,
115            group,
116            endpoint,
117            cluster,
118            fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
119        })
120    }
121}
122
123/// Every attribute the specification defines, with its conformance.
124pub const ATTRIBUTES: &[Attribute] = &[Attribute {
125    id: 0x0000,
126    name: "Binding",
127    kind: "list[TargetStruct]",
128    access: Access::read_write_with(Privilege::View, Privilege::Manage)
129        .with_qualities(AccessQualities::FABRIC_SCOPED),
130    qualities: AttributeQualities::NON_VOLATILE,
131    reporting: Reporting::OnChange,
132    conform: Conform::MANDATORY,
133}];
134
135/// Every command, with its conformance.
136pub const COMMANDS: &[Command] = &[];
137
138/// Every event, with its conformance.
139pub const EVENTS: &[Event] = &[];
140
141/// The whole cluster, as the specification defines it.
142pub const CLUSTER: Cluster = Cluster {
143    id: ID,
144    name: "Binding",
145    revision: REVISION,
146    pics: "BIND",
147    derived_from: None,
148    features: FEATURES,
149    attributes: ATTRIBUTES,
150    commands: COMMANDS,
151    events: EVENTS,
152};