matter-clusters 0.3.0

Matter protocol cluster definitions (generated from the spec).
Documentation
//! BooleanState cluster (0x0045).
//! @generated by `cargo xtask codegen` — do not edit.

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

use crate::datatypes::SemanticTagStruct;
use crate::error::ClusterError;
use crate::types::Nullable;
use matter_codec::{ContainerKind, Element, Tag, TlvReader, TlvWriter, Value};

/// Cluster ID.
pub const CLUSTER_ID: u32 = 0x0045;
/// Cluster revision.
pub const CLUSTER_REVISION: u16 = 2;

/// Command IDs (requests and responses).
pub mod command_id {}

/// Attribute IDs (cluster-specific).
pub mod attribute_id {
    /// `StateValue`.
    pub const STATE_VALUE: u32 = 0x0000;
}

/// Decode the `StateValue` attribute value.
///
/// # Errors
/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
pub fn decode_state_value(tlv: &[u8]) -> Result<bool, ClusterError> {
    let mut r = TlvReader::new(tlv);
    match r.next()? {
        Some(Element::Scalar {
            value: Value::Bool(v),
            ..
        }) => Ok(v),
        _ => Err(ClusterError::UnexpectedType {
            context: "StateValue",
        }),
    }
}