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.
//
// Label — cluster 0xFFFF0002.
//
// 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.

//! Label (cluster `0xFFFF0002`, 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 = 0xFFFF0002;

/// 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 = "LABEL";

/// 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;

    /// `LabelList`.
    pub const LABEL_LIST: AttributeId = 0x00;
}

/// `LabelStruct`.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct LabelStruct<'a> {
    /// `Label`, field 0.
    pub label: &'a str,
    /// `Value`, field 1.
    pub value: &'a str,
}

impl<'a> ToTlv for LabelStruct<'a> {
    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
        w.start_structure(tag)?;
        self.label.to_tlv(w, Tag::Context(0))?;
        self.value.to_tlv(w, Tag::Context(1))?;
        w.end_container()
    }
}

impl<'a> FromTlv<'a> for LabelStruct<'a> {
    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 label = None;
        let mut value = 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(0) => label = Some(<&'a str>::from_tlv(reader, &field)?),
                Some(1) => value = Some(<&'a str>::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 {
            label: label.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
            value: value.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
        })
    }
}