matc/clusters/codec/
joint_fabric_administrator_cluster.rs

1//! Generated Matter TLV encoders and decoders for Joint Fabric Administrator Cluster
2//! Cluster ID: 0x0753
3//! 
4//! This file is automatically generated from JointFabricAdministratorCluster.xml
5
6use crate::tlv;
7use anyhow;
8use serde_json;
9
10
11// Command encoders
12
13/// Encode AddICAC command (0x02)
14pub fn encode_add_icac(icac_value: Vec<u8>) -> anyhow::Result<Vec<u8>> {
15    let tlv = tlv::TlvItemEnc {
16        tag: 0,
17        value: tlv::TlvItemValueEnc::StructInvisible(vec![
18        (1, tlv::TlvItemValueEnc::OctetString(icac_value)).into(),
19        ]),
20    };
21    Ok(tlv.encode()?)
22}
23
24/// Encode OpenJointCommissioningWindow command (0x04)
25pub fn encode_open_joint_commissioning_window(commissioning_timeout: u16, pake_passcode_verifier: Vec<u8>, discriminator: u16, iterations: u32, salt: Vec<u8>) -> anyhow::Result<Vec<u8>> {
26    let tlv = tlv::TlvItemEnc {
27        tag: 0,
28        value: tlv::TlvItemValueEnc::StructInvisible(vec![
29        (0, tlv::TlvItemValueEnc::UInt16(commissioning_timeout)).into(),
30        (1, tlv::TlvItemValueEnc::OctetString(pake_passcode_verifier)).into(),
31        (2, tlv::TlvItemValueEnc::UInt16(discriminator)).into(),
32        (3, tlv::TlvItemValueEnc::UInt32(iterations)).into(),
33        (4, tlv::TlvItemValueEnc::OctetString(salt)).into(),
34        ]),
35    };
36    Ok(tlv.encode()?)
37}
38
39/// Encode AnnounceJointFabricAdministrator command (0x08)
40pub fn encode_announce_joint_fabric_administrator(endpoint_id: u16) -> anyhow::Result<Vec<u8>> {
41    let tlv = tlv::TlvItemEnc {
42        tag: 0,
43        value: tlv::TlvItemValueEnc::StructInvisible(vec![
44        (0, tlv::TlvItemValueEnc::UInt16(endpoint_id)).into(),
45        ]),
46    };
47    Ok(tlv.encode()?)
48}
49
50// Attribute decoders
51
52/// Decode AdministratorFabricIndex attribute (0x0000)
53pub fn decode_administrator_fabric_index(inp: &tlv::TlvItemValue) -> anyhow::Result<Option<u8>> {
54    if let tlv::TlvItemValue::Int(v) = inp {
55        Ok(Some(*v as u8))
56    } else {
57        Ok(None)
58    }
59}
60
61
62// JSON dispatcher function
63
64/// Decode attribute value and return as JSON string
65/// 
66/// # Parameters
67/// * `cluster_id` - The cluster identifier
68/// * `attribute_id` - The attribute identifier
69/// * `tlv_value` - The TLV value to decode
70/// 
71/// # Returns
72/// JSON string representation of the decoded value or error
73pub fn decode_attribute_json(cluster_id: u32, attribute_id: u32, tlv_value: &crate::tlv::TlvItemValue) -> String {
74    // Verify this is the correct cluster
75    if cluster_id != 0x0753 {
76        return format!("{{\"error\": \"Invalid cluster ID. Expected 0x0753, got {}\"}}", cluster_id);
77    }
78    
79    match attribute_id {
80        0x0000 => {
81            match decode_administrator_fabric_index(tlv_value) {
82                Ok(value) => serde_json::to_string(&value).unwrap_or_else(|_| "null".to_string()),
83                Err(e) => format!("{{\"error\": \"{}\"}}", e),
84            }
85        }
86        _ => format!("{{\"error\": \"Unknown attribute ID: {}\"}}", attribute_id),
87    }
88}
89
90/// Get list of all attributes supported by this cluster
91/// 
92/// # Returns
93/// Vector of tuples containing (attribute_id, attribute_name)
94pub fn get_attribute_list() -> Vec<(u32, &'static str)> {
95    vec![
96        (0x0000, "AdministratorFabricIndex"),
97    ]
98}
99