matc/clusters/codec/
user_label_cluster.rs

1//! Generated Matter TLV encoders and decoders for User Label Cluster
2//! Cluster ID: 0x0041
3//! 
4//! This file is automatically generated from UserLabel-Cluster.xml
5
6use crate::tlv;
7use anyhow;
8use serde_json;
9
10
11// Attribute decoders
12
13/// Decode LabelList attribute (0x0000)
14pub fn decode_label_list(inp: &tlv::TlvItemValue) -> anyhow::Result<Vec<u8>> {
15    let mut res = Vec::new();
16    if let tlv::TlvItemValue::List(v) = inp {
17        for item in v {
18            if let tlv::TlvItemValue::Int(i) = &item.value {
19                res.push(*i as u8);
20            }
21        }
22    }
23    Ok(res)
24}
25
26
27// JSON dispatcher function
28
29/// Decode attribute value and return as JSON string
30/// 
31/// # Parameters
32/// * `cluster_id` - The cluster identifier
33/// * `attribute_id` - The attribute identifier
34/// * `tlv_value` - The TLV value to decode
35/// 
36/// # Returns
37/// JSON string representation of the decoded value or error
38pub fn decode_attribute_json(cluster_id: u32, attribute_id: u32, tlv_value: &crate::tlv::TlvItemValue) -> String {
39    // Verify this is the correct cluster
40    if cluster_id != 0x0041 {
41        return format!("{{\"error\": \"Invalid cluster ID. Expected 0x0041, got {}\"}}", cluster_id);
42    }
43    
44    match attribute_id {
45        0x0000 => {
46            match decode_label_list(tlv_value) {
47                Ok(value) => serde_json::to_string(&value).unwrap_or_else(|_| "null".to_string()),
48                Err(e) => format!("{{\"error\": \"{}\"}}", e),
49            }
50        }
51        _ => format!("{{\"error\": \"Unknown attribute ID: {}\"}}", attribute_id),
52    }
53}
54
55/// Get list of all attributes supported by this cluster
56/// 
57/// # Returns
58/// Vector of tuples containing (attribute_id, attribute_name)
59pub fn get_attribute_list() -> Vec<(u32, &'static str)> {
60    vec![
61        (0x0000, "LabelList"),
62    ]
63}
64