Skip to main content

matter_kit/clusters/generated/
target_navigator.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Target Navigator — cluster 0x0505.
4//
5// Regenerate with `cargo xtask clusters --dm <checkout>/data_model/1.6`; `cargo xtask check`
6// is the CI gate that keeps this file honest. The XML itself is not vendored here — it
7// carries the CSA's own copyright notice and is not redistributable.
8
9//! Target Navigator (cluster `0x0505`, revision 2).
10//!
11//! 5 identifiers, 0 feature bits, and the specification's own conformance for
12//! every element. `CLUSTER` is the whole table.
13
14#![allow(unused_imports)]
15
16use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
17use crate::dm::meta::{EventPriority, Reporting};
18use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
19use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
20use crate::error::Result;
21use crate::im::{AttributeId, ClusterId, CommandId, EventId};
22use crate::tlv::{
23    ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
24};
25
26/// The cluster id.
27pub const ID: ClusterId = 0x0505;
28
29/// The highest revision the specification's history defines — what `ClusterRevision`
30/// must report (Core §7.13.1).
31pub const REVISION: u16 = 2;
32
33/// The PICS code, which a certification declaration names the cluster by.
34pub const PICS: &str = "TGTNAV";
35
36/// This cluster defines no features, so its `FeatureMap` is always zero.
37pub const FEATURES: &[Feature] = &[];
38
39/// The attribute ids.
40pub mod attribute {
41    use crate::im::AttributeId;
42
43    /// `TargetList`.
44    pub const TARGET_LIST: AttributeId = 0x00;
45    /// `CurrentTarget`.
46    pub const CURRENT_TARGET: AttributeId = 0x01;
47}
48
49/// The command ids.
50pub mod command {
51    use crate::im::CommandId;
52
53    /// `NavigateTarget`.
54    pub const NAVIGATE_TARGET: CommandId = 0x00;
55    /// `NavigateTargetResponse`.
56    pub const NAVIGATE_TARGET_RESPONSE: CommandId = 0x01;
57}
58
59/// The event ids.
60pub mod event {
61    use crate::im::EventId;
62
63    /// `TargetUpdated`.
64    pub const TARGET_UPDATED: EventId = 0x00;
65}
66
67/// `StatusEnum`.
68#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
69#[repr(u8)]
70pub enum StatusEnum {
71    /// Command succeeded
72    Success = 0,
73    /// Requested target was not found in the TargetList
74    TargetNotFound = 1,
75    /// Target request is not allowed in current state.
76    NotAllowed = 2,
77}
78
79impl StatusEnum {
80    /// Reads a wire value, or `None` for one this revision does not define.
81    #[must_use]
82    pub const fn from_value(value: u8) -> Option<Self> {
83        match value {
84            0 => Some(Self::Success),
85            1 => Some(Self::TargetNotFound),
86            2 => Some(Self::NotAllowed),
87            _ => None,
88        }
89    }
90
91    /// Its wire value.
92    #[must_use]
93    pub const fn value(self) -> u8 {
94        self as u8
95    }
96}
97
98impl ToTlv for StatusEnum {
99    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
100        self.value().to_tlv(w, tag)
101    }
102}
103
104impl<'a> FromTlv<'a> for StatusEnum {
105    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
106        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
107        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
108    }
109}
110
111/// `TargetInfoStruct`.
112#[derive(Debug, Clone, Copy, PartialEq)]
113pub struct TargetInfoStruct<'a> {
114    /// `Identifier`, field 0.
115    pub identifier: u8,
116    /// `Name`, field 1.
117    pub name: &'a str,
118}
119
120impl<'a> ToTlv for TargetInfoStruct<'a> {
121    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
122        w.start_structure(tag)?;
123        self.identifier.to_tlv(w, Tag::Context(0))?;
124        self.name.to_tlv(w, Tag::Context(1))?;
125        w.end_container()
126    }
127}
128
129impl<'a> FromTlv<'a> for TargetInfoStruct<'a> {
130    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
131        if element.value.container() != Some(ContainerKind::Structure) {
132            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
133        }
134        let mut identifier = None;
135        let mut name = None;
136        loop {
137            let Some(field) = reader.next_element()? else {
138                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
139            };
140            if field.value == Value::EndOfContainer {
141                break;
142            }
143            match field.tag.context() {
144                Some(0) => identifier = Some(<u8>::from_tlv(reader, &field)?),
145                Some(1) => name = Some(<&'a str>::from_tlv(reader, &field)?),
146                // A field this revision does not define. §7.19.2: a receiver
147                // ignores what it does not know rather than refusing the whole
148                // structure, which is what lets a newer peer talk to an older one.
149                _ => reader.skip_value(&field)?,
150            }
151        }
152        Ok(Self {
153            identifier: identifier.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
154            name: name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
155        })
156    }
157}
158
159/// The fields of `NavigateTarget` (command `0x00`).
160#[derive(Debug, Clone, Copy, PartialEq)]
161pub struct NavigateTargetFields<'a> {
162    /// `Target`, field 0.
163    pub target: u8,
164    /// `Data`, field 1.
165    pub data: Option<&'a str>,
166}
167
168impl<'a> ToTlv for NavigateTargetFields<'a> {
169    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
170        w.start_structure(tag)?;
171        self.target.to_tlv(w, Tag::Context(0))?;
172        if let Some(value) = &self.data {
173            value.to_tlv(w, Tag::Context(1))?;
174        }
175        w.end_container()
176    }
177}
178
179impl<'a> FromTlv<'a> for NavigateTargetFields<'a> {
180    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
181        if element.value.container() != Some(ContainerKind::Structure) {
182            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
183        }
184        let mut target = None;
185        let mut data = None;
186        loop {
187            let Some(field) = reader.next_element()? else {
188                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
189            };
190            if field.value == Value::EndOfContainer {
191                break;
192            }
193            match field.tag.context() {
194                Some(0) => target = Some(<u8>::from_tlv(reader, &field)?),
195                Some(1) => data = Some(<&'a str>::from_tlv(reader, &field)?),
196                // A field this revision does not define. §7.19.2: a receiver
197                // ignores what it does not know rather than refusing the whole
198                // structure, which is what lets a newer peer talk to an older one.
199                _ => reader.skip_value(&field)?,
200            }
201        }
202        Ok(Self {
203            target: target.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
204            data,
205        })
206    }
207}
208
209/// The fields of `NavigateTargetResponse` (command `0x01`).
210#[derive(Debug, Clone, Copy, PartialEq)]
211pub struct NavigateTargetResponseFields<'a> {
212    /// `Status`, field 0.
213    pub status: StatusEnum,
214    /// `Data`, field 1.
215    pub data: Option<&'a str>,
216}
217
218impl<'a> ToTlv for NavigateTargetResponseFields<'a> {
219    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
220        w.start_structure(tag)?;
221        self.status.to_tlv(w, Tag::Context(0))?;
222        if let Some(value) = &self.data {
223            value.to_tlv(w, Tag::Context(1))?;
224        }
225        w.end_container()
226    }
227}
228
229impl<'a> FromTlv<'a> for NavigateTargetResponseFields<'a> {
230    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
231        if element.value.container() != Some(ContainerKind::Structure) {
232            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
233        }
234        let mut status = None;
235        let mut data = None;
236        loop {
237            let Some(field) = reader.next_element()? else {
238                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
239            };
240            if field.value == Value::EndOfContainer {
241                break;
242            }
243            match field.tag.context() {
244                Some(0) => status = Some(<StatusEnum>::from_tlv(reader, &field)?),
245                Some(1) => data = Some(<&'a str>::from_tlv(reader, &field)?),
246                // A field this revision does not define. §7.19.2: a receiver
247                // ignores what it does not know rather than refusing the whole
248                // structure, which is what lets a newer peer talk to an older one.
249                _ => reader.skip_value(&field)?,
250            }
251        }
252        Ok(Self {
253            status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
254            data,
255        })
256    }
257}
258
259/// Every attribute the specification defines, with its conformance.
260pub const ATTRIBUTES: &[Attribute] = &[
261    Attribute {
262        id: 0x0000,
263        name: "TargetList",
264        kind: "list[TargetInfoStruct]",
265        access: Access::read_only(Privilege::View),
266        qualities: AttributeQualities::empty(),
267        reporting: Reporting::OnChange,
268        conform: Conform::MANDATORY,
269    },
270    Attribute {
271        id: 0x0001,
272        name: "CurrentTarget",
273        kind: "uint8",
274        access: Access::read_only(Privilege::View),
275        qualities: AttributeQualities::empty(),
276        reporting: Reporting::OnChange,
277        conform: Conform::OPTIONAL,
278    },
279];
280
281/// Every command, with its conformance.
282pub const COMMANDS: &[Command] = &[
283    Command {
284        id: 0x00,
285        name: "NavigateTarget",
286        to_server: true,
287        response: Some(0x01),
288        access: Access::invoke(Privilege::Operate),
289        conform: Conform::MANDATORY,
290    },
291    Command {
292        id: 0x01,
293        name: "NavigateTargetResponse",
294        to_server: false,
295        response: None,
296        access: Access::invoke(Privilege::Operate),
297        conform: Conform::MANDATORY,
298    },
299];
300
301/// Every event, with its conformance.
302pub const EVENTS: &[Event] = &[Event {
303    id: 0x00,
304    name: "TargetUpdated",
305    priority: EventPriority::Info,
306    access: Access::read_only(Privilege::View),
307    conform: Conform::OPTIONAL,
308}];
309
310/// The whole cluster, as the specification defines it.
311pub const CLUSTER: Cluster = Cluster {
312    id: ID,
313    name: "Target Navigator",
314    revision: REVISION,
315    pics: "TGTNAV",
316    derived_from: None,
317    features: FEATURES,
318    attributes: ATTRIBUTES,
319    commands: COMMANDS,
320    events: EVENTS,
321};