matter-clusters 0.1.0

Matter protocol cluster definitions (generated from the spec).
Documentation
//! Global attributes present on every cluster (Matter spec §7.13).
//! @generated by `cargo xtask codegen` — do not edit.

#![allow(
    clippy::all,
    clippy::pedantic,
    dead_code,
    unreachable_pub,
    unused_imports
)]

use crate::error::ClusterError;
use matter_codec::{Element, TlvReader, Value};

/// FeatureMap (0xFFFC).
pub const FEATURE_MAP: u32 = 0xFFFC;
/// ClusterRevision (0xFFFD).
pub const CLUSTER_REVISION: u32 = 0xFFFD;
/// AttributeList (0xFFFB).
pub const ATTRIBUTE_LIST: u32 = 0xFFFB;
/// AcceptedCommandList (0xFFF9).
pub const ACCEPTED_COMMAND_LIST: u32 = 0xFFF9;
/// GeneratedCommandList (0xFFF8).
pub const GENERATED_COMMAND_LIST: u32 = 0xFFF8;

/// Decode a FeatureMap / any `u32` global attribute value.
///
/// # Errors
/// Returns [`ClusterError`] if the element is not an unsigned int.
pub fn decode_u32(tlv: &[u8]) -> Result<u32, ClusterError> {
    let mut r = TlvReader::new(tlv);
    match r.next()? {
        Some(Element::Scalar {
            value: Value::Uint(v),
            ..
        }) => u32::try_from(v).map_err(|_| ClusterError::InvalidLength("global u32")),
        _ => Err(ClusterError::UnexpectedType {
            context: "global u32",
        }),
    }
}