matter-kit 0.3.0

Matter (CSA smart-home standard) protocol implementation in Rust: no_std, no-alloc, executor-agnostic
Documentation
// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
//
// Binding — cluster 0x001E.
//
// Regenerate with `cargo xtask clusters --dm <checkout>/data_model/1.6`; `cargo xtask check`
// is the CI gate that keeps this file honest. The XML itself is not vendored here — it
// carries the CSA's own copyright notice and is not redistributable.

//! Binding (cluster `0x001E`, revision 1).
//!
//! 1 identifiers, 0 feature bits, and the specification's own conformance for
//! every element. `CLUSTER` is the whole table.

#![allow(unused_imports)]

use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
use crate::dm::meta::{EventPriority, Reporting};
use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
use crate::error::Result;
use crate::im::{AttributeId, ClusterId, CommandId, EventId};
use crate::tlv::{
    ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
};

/// The cluster id.
pub const ID: ClusterId = 0x001E;

/// The highest revision the specification's history defines — what `ClusterRevision`
/// must report (Core §7.13.1).
pub const REVISION: u16 = 1;

/// The PICS code, which a certification declaration names the cluster by.
pub const PICS: &str = "BIND";

/// This cluster defines no features, so its `FeatureMap` is always zero.
pub const FEATURES: &[Feature] = &[];

/// The attribute ids.
pub mod attribute {
    use crate::im::AttributeId;

    /// `Binding`.
    pub const BINDING: AttributeId = 0x00;
}

/// `TargetStruct`, fabric-scoped — §7.19.1.9's `FabricIndex` is field 254.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct TargetStruct {
    /// `Node`, field 1.
    pub node: Option<crate::msg::NodeId>,
    /// `Group`, field 2.
    pub group: Option<crate::msg::GroupId>,
    /// `Endpoint`, field 3.
    pub endpoint: Option<u16>,
    /// `Cluster`, field 4.
    pub cluster: Option<u32>,
    /// `FabricIndex`, field 254.
    pub fabric_index: crate::msg::FabricIndex,
}

impl ToTlv for TargetStruct {
    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
        w.start_structure(tag)?;
        if let Some(value) = &self.node {
            value.to_tlv(w, Tag::Context(1))?;
        }
        if let Some(value) = &self.group {
            value.to_tlv(w, Tag::Context(2))?;
        }
        if let Some(value) = &self.endpoint {
            value.to_tlv(w, Tag::Context(3))?;
        }
        if let Some(value) = &self.cluster {
            value.to_tlv(w, Tag::Context(4))?;
        }
        self.fabric_index.to_tlv(w, Tag::Context(254))?;
        w.end_container()
    }
}

impl<'a> FromTlv<'a> for TargetStruct {
    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
        if element.value.container() != Some(ContainerKind::Structure) {
            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
        }
        let mut node = None;
        let mut group = None;
        let mut endpoint = None;
        let mut cluster = None;
        let mut fabric_index = None;
        loop {
            let Some(field) = reader.next_element()? else {
                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
            };
            if field.value == Value::EndOfContainer {
                break;
            }
            match field.tag.context() {
                Some(1) => node = Some(<crate::msg::NodeId>::from_tlv(reader, &field)?),
                Some(2) => group = Some(<crate::msg::GroupId>::from_tlv(reader, &field)?),
                Some(3) => endpoint = Some(<u16>::from_tlv(reader, &field)?),
                Some(4) => cluster = Some(<u32>::from_tlv(reader, &field)?),
                Some(254) => {
                    fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
                }
                // A field this revision does not define. §7.19.2: a receiver
                // ignores what it does not know rather than refusing the whole
                // structure, which is what lets a newer peer talk to an older one.
                _ => reader.skip_value(&field)?,
            }
        }
        Ok(Self {
            node,
            group,
            endpoint,
            cluster,
            fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
        })
    }
}

/// Every attribute the specification defines, with its conformance.
pub const ATTRIBUTES: &[Attribute] = &[Attribute {
    id: 0x0000,
    name: "Binding",
    kind: "list[TargetStruct]",
    access: Access::read_write_with(Privilege::View, Privilege::Manage)
        .with_qualities(AccessQualities::FABRIC_SCOPED),
    qualities: AttributeQualities::NON_VOLATILE,
    reporting: Reporting::OnChange,
    conform: Conform::MANDATORY,
}];

/// Every command, with its conformance.
pub const COMMANDS: &[Command] = &[];

/// Every event, with its conformance.
pub const EVENTS: &[Event] = &[];

/// The whole cluster, as the specification defines it.
pub const CLUSTER: Cluster = Cluster {
    id: ID,
    name: "Binding",
    revision: REVISION,
    pics: "BIND",
    derived_from: None,
    features: FEATURES,
    attributes: ATTRIBUTES,
    commands: COMMANDS,
    events: EVENTS,
};