Skip to main content

matter_kit/clusters/generated/
push_av_stream_transport.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Push AV Stream Transport — cluster 0x0555.
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//! Push AV Stream Transport (cluster `0x0555`, revision 2).
10//!
11//! 12 identifiers, 2 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 = 0x0555;
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 = "PAVST";
35
36/// The `FeatureMap` bits (Core §7.13.2).
37///
38/// A feature has conformance of its own: a device may not claim one the
39/// specification forbids it alongside another.
40pub mod feature {
41    /// Supports a sensitivity value per Zone
42    ///
43    /// Code `PERZONESENS`, bit 0.
44    pub const PER_ZONE_SENSITIVITY: u32 = 1 << 0;
45    /// Supports metadata transmission in Push transports
46    ///
47    /// Code `METADATA`, bit 1.
48    pub const METADATA: u32 = 1 << 1;
49}
50
51/// Every feature bit, with its conformance.
52pub const FEATURES: &[Feature] = &[
53    Feature {
54        bit: 0,
55        code: "PERZONESENS",
56        name: "PerZoneSensitivity",
57        conform: Conform::OPTIONAL,
58    },
59    Feature {
60        bit: 1,
61        code: "METADATA",
62        name: "Metadata",
63        conform: Conform {
64            clauses: &[
65                Clause {
66                    verdict: Conformance::Provisional,
67                    when: Condition::Always,
68                },
69                Clause {
70                    verdict: Conformance::Optional,
71                    when: Condition::Always,
72                },
73            ],
74        },
75    },
76];
77
78/// The attribute ids.
79pub mod attribute {
80    use crate::im::AttributeId;
81
82    /// `SupportedFormats`.
83    pub const SUPPORTED_FORMATS: AttributeId = 0x00;
84    /// `CurrentConnections`.
85    pub const CURRENT_CONNECTIONS: AttributeId = 0x01;
86}
87
88/// The command ids.
89pub mod command {
90    use crate::im::CommandId;
91
92    /// `AllocatePushTransport`.
93    pub const ALLOCATE_PUSH_TRANSPORT: CommandId = 0x00;
94    /// `AllocatePushTransportResponse`.
95    pub const ALLOCATE_PUSH_TRANSPORT_RESPONSE: CommandId = 0x01;
96    /// `DeallocatePushTransport`.
97    pub const DEALLOCATE_PUSH_TRANSPORT: CommandId = 0x02;
98    /// `ModifyPushTransport`.
99    pub const MODIFY_PUSH_TRANSPORT: CommandId = 0x03;
100    /// `SetTransportStatus`.
101    pub const SET_TRANSPORT_STATUS: CommandId = 0x04;
102    /// `ManuallyTriggerTransport`.
103    pub const MANUALLY_TRIGGER_TRANSPORT: CommandId = 0x05;
104    /// `FindTransport`.
105    pub const FIND_TRANSPORT: CommandId = 0x06;
106    /// `FindTransportResponse`.
107    pub const FIND_TRANSPORT_RESPONSE: CommandId = 0x07;
108}
109
110/// The event ids.
111pub mod event {
112    use crate::im::EventId;
113
114    /// `PushTransportBegin`.
115    pub const PUSH_TRANSPORT_BEGIN: EventId = 0x00;
116    /// `PushTransportEnd`.
117    pub const PUSH_TRANSPORT_END: EventId = 0x01;
118}
119
120/// `CMAFInterfaceEnum`.
121#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
122#[repr(u8)]
123pub enum CMAFInterfaceEnum {
124    /// CMAF Interface-1 Mode
125    Interface1 = 0,
126    /// CMAF Interface-2 Mode with DASH Support
127    Interface2DASH = 1,
128    /// CMAF Interface-2 Mode with HLS Support
129    Interface2HLS = 2,
130}
131
132impl CMAFInterfaceEnum {
133    /// Reads a wire value, or `None` for one this revision does not define.
134    #[must_use]
135    pub const fn from_value(value: u8) -> Option<Self> {
136        match value {
137            0 => Some(Self::Interface1),
138            1 => Some(Self::Interface2DASH),
139            2 => Some(Self::Interface2HLS),
140            _ => None,
141        }
142    }
143
144    /// Its wire value.
145    #[must_use]
146    pub const fn value(self) -> u8 {
147        self as u8
148    }
149}
150
151impl ToTlv for CMAFInterfaceEnum {
152    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
153        self.value().to_tlv(w, tag)
154    }
155}
156
157impl<'a> FromTlv<'a> for CMAFInterfaceEnum {
158    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
159        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
160        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
161    }
162}
163
164/// `ContainerFormatEnum`.
165#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
166#[repr(u8)]
167pub enum ContainerFormatEnum {
168    /// CMAF container format
169    CMAF = 0,
170}
171
172impl ContainerFormatEnum {
173    /// Reads a wire value, or `None` for one this revision does not define.
174    #[must_use]
175    pub const fn from_value(value: u8) -> Option<Self> {
176        match value {
177            0 => Some(Self::CMAF),
178            _ => None,
179        }
180    }
181
182    /// Its wire value.
183    #[must_use]
184    pub const fn value(self) -> u8 {
185        self as u8
186    }
187}
188
189impl ToTlv for ContainerFormatEnum {
190    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
191        self.value().to_tlv(w, tag)
192    }
193}
194
195impl<'a> FromTlv<'a> for ContainerFormatEnum {
196    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
197        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
198        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
199    }
200}
201
202/// `IngestMethodsEnum`.
203#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
204#[repr(u8)]
205pub enum IngestMethodsEnum {
206    /// CMAF ingestion format
207    CMAFIngest = 0,
208}
209
210impl IngestMethodsEnum {
211    /// Reads a wire value, or `None` for one this revision does not define.
212    #[must_use]
213    pub const fn from_value(value: u8) -> Option<Self> {
214        match value {
215            0 => Some(Self::CMAFIngest),
216            _ => None,
217        }
218    }
219
220    /// Its wire value.
221    #[must_use]
222    pub const fn value(self) -> u8 {
223        self as u8
224    }
225}
226
227impl ToTlv for IngestMethodsEnum {
228    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
229        self.value().to_tlv(w, tag)
230    }
231}
232
233impl<'a> FromTlv<'a> for IngestMethodsEnum {
234    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
235        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
236        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
237    }
238}
239
240/// `StatusCodeEnum`.
241#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
242#[repr(u8)]
243pub enum StatusCodeEnum {
244    /// The specified TLSEndpointID cannot be found.
245    InvalidTLSEndpoint = 2,
246    /// The specified VideoStreamID or AudioStreamID cannot be found.
247    InvalidStream = 3,
248    /// The specified URL is invalid.
249    InvalidURL = 4,
250    /// A specified ZoneID was invalid.
251    InvalidZone = 5,
252    /// The specified combination of Ingestion method and Container format is not supported.
253    InvalidCombination = 6,
254    /// The trigger type is invalid for this command.
255    InvalidTriggerType = 7,
256    /// The Stream Transport Status is invalid for this command.
257    InvalidTransportStatus = 8,
258    /// The requested Container options are not supported with the streams indicated.
259    InvalidOptions = 9,
260    /// The requested StreamUsage is not allowed.
261    InvalidStreamUsage = 10,
262    /// Time sync has not occurred yet.
263    InvalidTime = 11,
264    /// The requested pre roll length is not compatible with the streams key frame interval.
265    InvalidPreRollLength = 12,
266    /// The requested Streams info contained duplicate entries.
267    DuplicateStreamValues = 13,
268}
269
270impl StatusCodeEnum {
271    /// Reads a wire value, or `None` for one this revision does not define.
272    #[must_use]
273    pub const fn from_value(value: u8) -> Option<Self> {
274        match value {
275            2 => Some(Self::InvalidTLSEndpoint),
276            3 => Some(Self::InvalidStream),
277            4 => Some(Self::InvalidURL),
278            5 => Some(Self::InvalidZone),
279            6 => Some(Self::InvalidCombination),
280            7 => Some(Self::InvalidTriggerType),
281            8 => Some(Self::InvalidTransportStatus),
282            9 => Some(Self::InvalidOptions),
283            10 => Some(Self::InvalidStreamUsage),
284            11 => Some(Self::InvalidTime),
285            12 => Some(Self::InvalidPreRollLength),
286            13 => Some(Self::DuplicateStreamValues),
287            _ => None,
288        }
289    }
290
291    /// Its wire value.
292    #[must_use]
293    pub const fn value(self) -> u8 {
294        self as u8
295    }
296}
297
298impl ToTlv for StatusCodeEnum {
299    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
300        self.value().to_tlv(w, tag)
301    }
302}
303
304impl<'a> FromTlv<'a> for StatusCodeEnum {
305    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
306        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
307        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
308    }
309}
310
311/// `TransportStatusEnum`.
312#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
313#[repr(u8)]
314pub enum TransportStatusEnum {
315    /// Push Transport can transport AV Streams
316    Active = 0,
317    /// Push Transport cannot transport AV Streams
318    Inactive = 1,
319}
320
321impl TransportStatusEnum {
322    /// Reads a wire value, or `None` for one this revision does not define.
323    #[must_use]
324    pub const fn from_value(value: u8) -> Option<Self> {
325        match value {
326            0 => Some(Self::Active),
327            1 => Some(Self::Inactive),
328            _ => None,
329        }
330    }
331
332    /// Its wire value.
333    #[must_use]
334    pub const fn value(self) -> u8 {
335        self as u8
336    }
337}
338
339impl ToTlv for TransportStatusEnum {
340    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
341        self.value().to_tlv(w, tag)
342    }
343}
344
345impl<'a> FromTlv<'a> for TransportStatusEnum {
346    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
347        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
348        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
349    }
350}
351
352/// `TransportTriggerTypeEnum`.
353#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
354#[repr(u8)]
355pub enum TransportTriggerTypeEnum {
356    /// Triggered only via a command invocation
357    Command = 0,
358    /// Triggered via motion detection or command
359    Motion = 1,
360    /// Triggered always when transport status is Active
361    Continuous = 2,
362}
363
364impl TransportTriggerTypeEnum {
365    /// Reads a wire value, or `None` for one this revision does not define.
366    #[must_use]
367    pub const fn from_value(value: u8) -> Option<Self> {
368        match value {
369            0 => Some(Self::Command),
370            1 => Some(Self::Motion),
371            2 => Some(Self::Continuous),
372            _ => None,
373        }
374    }
375
376    /// Its wire value.
377    #[must_use]
378    pub const fn value(self) -> u8 {
379        self as u8
380    }
381}
382
383impl ToTlv for TransportTriggerTypeEnum {
384    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
385        self.value().to_tlv(w, tag)
386    }
387}
388
389impl<'a> FromTlv<'a> for TransportTriggerTypeEnum {
390    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
391        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
392        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
393    }
394}
395
396/// `TriggerActivationReasonEnum`.
397#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
398#[repr(u8)]
399pub enum TriggerActivationReasonEnum {
400    /// Trigger has been activated by user action
401    UserInitiated = 0,
402    /// Trigger has been activated by automation
403    Automation = 1,
404    /// Trigger has been activated for emergency reasons
405    Emergency = 2,
406    /// Trigger has been activated by a doorbell press
407    DoorbellPressed = 3,
408}
409
410impl TriggerActivationReasonEnum {
411    /// Reads a wire value, or `None` for one this revision does not define.
412    #[must_use]
413    pub const fn from_value(value: u8) -> Option<Self> {
414        match value {
415            0 => Some(Self::UserInitiated),
416            1 => Some(Self::Automation),
417            2 => Some(Self::Emergency),
418            3 => Some(Self::DoorbellPressed),
419            _ => None,
420        }
421    }
422
423    /// Its wire value.
424    #[must_use]
425    pub const fn value(self) -> u8 {
426        self as u8
427    }
428}
429
430impl ToTlv for TriggerActivationReasonEnum {
431    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
432        self.value().to_tlv(w, tag)
433    }
434}
435
436impl<'a> FromTlv<'a> for TriggerActivationReasonEnum {
437    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
438        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
439        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
440    }
441}
442
443/// `AudioStreamStruct`.
444#[derive(Debug, Clone, Copy, PartialEq)]
445pub struct AudioStreamStruct<'a> {
446    /// `AudioStreamName`, field 0.
447    pub audio_stream_name: &'a str,
448    /// `AudioStreamID`, field 1.
449    pub audio_stream_id: u16,
450}
451
452impl<'a> ToTlv for AudioStreamStruct<'a> {
453    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
454        w.start_structure(tag)?;
455        self.audio_stream_name.to_tlv(w, Tag::Context(0))?;
456        self.audio_stream_id.to_tlv(w, Tag::Context(1))?;
457        w.end_container()
458    }
459}
460
461impl<'a> FromTlv<'a> for AudioStreamStruct<'a> {
462    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
463        if element.value.container() != Some(ContainerKind::Structure) {
464            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
465        }
466        let mut audio_stream_name = None;
467        let mut audio_stream_id = None;
468        loop {
469            let Some(field) = reader.next_element()? else {
470                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
471            };
472            if field.value == Value::EndOfContainer {
473                break;
474            }
475            match field.tag.context() {
476                Some(0) => audio_stream_name = Some(<&'a str>::from_tlv(reader, &field)?),
477                Some(1) => audio_stream_id = Some(<u16>::from_tlv(reader, &field)?),
478                // A field this revision does not define. §7.19.2: a receiver
479                // ignores what it does not know rather than refusing the whole
480                // structure, which is what lets a newer peer talk to an older one.
481                _ => reader.skip_value(&field)?,
482            }
483        }
484        Ok(Self {
485            audio_stream_name: audio_stream_name
486                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
487            audio_stream_id: audio_stream_id
488                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
489        })
490    }
491}
492
493/// `CMAFContainerOptionsStruct`.
494#[derive(Debug, Clone, Copy, PartialEq)]
495pub struct CMAFContainerOptionsStruct<'a> {
496    /// `CMAFInterface`, field 0.
497    pub cmaf_interface: CMAFInterfaceEnum,
498    /// `SegmentDuration`, field 1.
499    pub segment_duration: u16,
500    /// `ChunkDuration`, field 2.
501    pub chunk_duration: u16,
502    /// `SessionGroup`, field 3.
503    pub session_group: Option<u8>,
504    /// `TrackName`, field 4.
505    pub track_name: Option<&'a str>,
506    /// `MetadataEnabled`, field 7.
507    pub metadata_enabled: Option<bool>,
508}
509
510impl<'a> ToTlv for CMAFContainerOptionsStruct<'a> {
511    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
512        w.start_structure(tag)?;
513        self.cmaf_interface.to_tlv(w, Tag::Context(0))?;
514        self.segment_duration.to_tlv(w, Tag::Context(1))?;
515        self.chunk_duration.to_tlv(w, Tag::Context(2))?;
516        if let Some(value) = &self.session_group {
517            value.to_tlv(w, Tag::Context(3))?;
518        }
519        if let Some(value) = &self.track_name {
520            value.to_tlv(w, Tag::Context(4))?;
521        }
522        if let Some(value) = &self.metadata_enabled {
523            value.to_tlv(w, Tag::Context(7))?;
524        }
525        w.end_container()
526    }
527}
528
529impl<'a> FromTlv<'a> for CMAFContainerOptionsStruct<'a> {
530    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
531        if element.value.container() != Some(ContainerKind::Structure) {
532            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
533        }
534        let mut cmaf_interface = None;
535        let mut segment_duration = None;
536        let mut chunk_duration = None;
537        let mut session_group = None;
538        let mut track_name = None;
539        let mut metadata_enabled = None;
540        loop {
541            let Some(field) = reader.next_element()? else {
542                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
543            };
544            if field.value == Value::EndOfContainer {
545                break;
546            }
547            match field.tag.context() {
548                Some(0) => cmaf_interface = Some(<CMAFInterfaceEnum>::from_tlv(reader, &field)?),
549                Some(1) => segment_duration = Some(<u16>::from_tlv(reader, &field)?),
550                Some(2) => chunk_duration = Some(<u16>::from_tlv(reader, &field)?),
551                Some(3) => session_group = Some(<u8>::from_tlv(reader, &field)?),
552                Some(4) => track_name = Some(<&'a str>::from_tlv(reader, &field)?),
553                Some(7) => metadata_enabled = Some(<bool>::from_tlv(reader, &field)?),
554                // A field this revision does not define. §7.19.2: a receiver
555                // ignores what it does not know rather than refusing the whole
556                // structure, which is what lets a newer peer talk to an older one.
557                _ => reader.skip_value(&field)?,
558            }
559        }
560        Ok(Self {
561            cmaf_interface: cmaf_interface
562                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
563            segment_duration: segment_duration
564                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
565            chunk_duration: chunk_duration
566                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
567            session_group,
568            track_name,
569            metadata_enabled,
570        })
571    }
572}
573
574/// `ContainerOptionsStruct`.
575#[derive(Debug, Clone, Copy, PartialEq)]
576pub struct ContainerOptionsStruct<'a> {
577    /// `ContainerType`, field 0.
578    pub container_type: ContainerFormatEnum,
579    /// `CMAFContainerOptions`, field 1.
580    pub cmaf_container_options: Option<CMAFContainerOptionsStruct<'a>>,
581}
582
583impl<'a> ToTlv for ContainerOptionsStruct<'a> {
584    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
585        w.start_structure(tag)?;
586        self.container_type.to_tlv(w, Tag::Context(0))?;
587        if let Some(value) = &self.cmaf_container_options {
588            value.to_tlv(w, Tag::Context(1))?;
589        }
590        w.end_container()
591    }
592}
593
594impl<'a> FromTlv<'a> for ContainerOptionsStruct<'a> {
595    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
596        if element.value.container() != Some(ContainerKind::Structure) {
597            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
598        }
599        let mut container_type = None;
600        let mut cmaf_container_options = None;
601        loop {
602            let Some(field) = reader.next_element()? else {
603                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
604            };
605            if field.value == Value::EndOfContainer {
606                break;
607            }
608            match field.tag.context() {
609                Some(0) => container_type = Some(<ContainerFormatEnum>::from_tlv(reader, &field)?),
610                Some(1) => {
611                    cmaf_container_options =
612                        Some(<CMAFContainerOptionsStruct<'a>>::from_tlv(reader, &field)?)
613                }
614                // A field this revision does not define. §7.19.2: a receiver
615                // ignores what it does not know rather than refusing the whole
616                // structure, which is what lets a newer peer talk to an older one.
617                _ => reader.skip_value(&field)?,
618            }
619        }
620        Ok(Self {
621            container_type: container_type
622                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
623            cmaf_container_options,
624        })
625    }
626}
627
628/// `SupportedFormatStruct`.
629#[derive(Debug, Clone, Copy, PartialEq)]
630pub struct SupportedFormatStruct {
631    /// `ContainerFormat`, field 0.
632    pub container_format: ContainerFormatEnum,
633    /// `IngestMethod`, field 1.
634    pub ingest_method: IngestMethodsEnum,
635}
636
637impl ToTlv for SupportedFormatStruct {
638    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
639        w.start_structure(tag)?;
640        self.container_format.to_tlv(w, Tag::Context(0))?;
641        self.ingest_method.to_tlv(w, Tag::Context(1))?;
642        w.end_container()
643    }
644}
645
646impl<'a> FromTlv<'a> for SupportedFormatStruct {
647    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
648        if element.value.container() != Some(ContainerKind::Structure) {
649            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
650        }
651        let mut container_format = None;
652        let mut ingest_method = None;
653        loop {
654            let Some(field) = reader.next_element()? else {
655                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
656            };
657            if field.value == Value::EndOfContainer {
658                break;
659            }
660            match field.tag.context() {
661                Some(0) => {
662                    container_format = Some(<ContainerFormatEnum>::from_tlv(reader, &field)?)
663                }
664                Some(1) => ingest_method = Some(<IngestMethodsEnum>::from_tlv(reader, &field)?),
665                // A field this revision does not define. §7.19.2: a receiver
666                // ignores what it does not know rather than refusing the whole
667                // structure, which is what lets a newer peer talk to an older one.
668                _ => reader.skip_value(&field)?,
669            }
670        }
671        Ok(Self {
672            container_format: container_format
673                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
674            ingest_method: ingest_method.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
675        })
676    }
677}
678
679/// `TransportConfigurationStruct`, fabric-scoped — §7.19.1.9's `FabricIndex` is field 254.
680#[derive(Debug, Clone, Copy, PartialEq)]
681pub struct TransportConfigurationStruct<'a> {
682    /// `ConnectionID`, field 0.
683    pub connection_id: u16,
684    /// `TransportStatus`, field 1.
685    pub transport_status: TransportStatusEnum,
686    /// `TransportOptions`, field 2.
687    pub transport_options: Option<TransportOptionsStruct<'a>>,
688    /// `FabricIndex`, field 254.
689    pub fabric_index: crate::msg::FabricIndex,
690}
691
692impl<'a> ToTlv for TransportConfigurationStruct<'a> {
693    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
694        w.start_structure(tag)?;
695        self.connection_id.to_tlv(w, Tag::Context(0))?;
696        self.transport_status.to_tlv(w, Tag::Context(1))?;
697        if let Some(value) = &self.transport_options {
698            value.to_tlv(w, Tag::Context(2))?;
699        }
700        self.fabric_index.to_tlv(w, Tag::Context(254))?;
701        w.end_container()
702    }
703}
704
705impl<'a> FromTlv<'a> for TransportConfigurationStruct<'a> {
706    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
707        if element.value.container() != Some(ContainerKind::Structure) {
708            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
709        }
710        let mut connection_id = None;
711        let mut transport_status = None;
712        let mut transport_options = None;
713        let mut fabric_index = None;
714        loop {
715            let Some(field) = reader.next_element()? else {
716                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
717            };
718            if field.value == Value::EndOfContainer {
719                break;
720            }
721            match field.tag.context() {
722                Some(0) => connection_id = Some(<u16>::from_tlv(reader, &field)?),
723                Some(1) => {
724                    transport_status = Some(<TransportStatusEnum>::from_tlv(reader, &field)?)
725                }
726                Some(2) => {
727                    transport_options =
728                        Some(<TransportOptionsStruct<'a>>::from_tlv(reader, &field)?)
729                }
730                Some(254) => {
731                    fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
732                }
733                // A field this revision does not define. §7.19.2: a receiver
734                // ignores what it does not know rather than refusing the whole
735                // structure, which is what lets a newer peer talk to an older one.
736                _ => reader.skip_value(&field)?,
737            }
738        }
739        Ok(Self {
740            connection_id: connection_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
741            transport_status: transport_status
742                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
743            transport_options,
744            fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
745        })
746    }
747}
748
749/// `TransportMotionTriggerTimeControlStruct`.
750#[derive(Debug, Clone, Copy, PartialEq)]
751pub struct TransportMotionTriggerTimeControlStruct {
752    /// `InitialDuration`, field 0.
753    pub initial_duration: u16,
754    /// `AugmentationDuration`, field 1.
755    pub augmentation_duration: u16,
756    /// `MaxDuration`, field 2.
757    pub max_duration: u32,
758    /// `BlindDuration`, field 3.
759    pub blind_duration: u16,
760}
761
762impl ToTlv for TransportMotionTriggerTimeControlStruct {
763    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
764        w.start_structure(tag)?;
765        self.initial_duration.to_tlv(w, Tag::Context(0))?;
766        self.augmentation_duration.to_tlv(w, Tag::Context(1))?;
767        self.max_duration.to_tlv(w, Tag::Context(2))?;
768        self.blind_duration.to_tlv(w, Tag::Context(3))?;
769        w.end_container()
770    }
771}
772
773impl<'a> FromTlv<'a> for TransportMotionTriggerTimeControlStruct {
774    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
775        if element.value.container() != Some(ContainerKind::Structure) {
776            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
777        }
778        let mut initial_duration = None;
779        let mut augmentation_duration = None;
780        let mut max_duration = None;
781        let mut blind_duration = None;
782        loop {
783            let Some(field) = reader.next_element()? else {
784                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
785            };
786            if field.value == Value::EndOfContainer {
787                break;
788            }
789            match field.tag.context() {
790                Some(0) => initial_duration = Some(<u16>::from_tlv(reader, &field)?),
791                Some(1) => augmentation_duration = Some(<u16>::from_tlv(reader, &field)?),
792                Some(2) => max_duration = Some(<u32>::from_tlv(reader, &field)?),
793                Some(3) => blind_duration = Some(<u16>::from_tlv(reader, &field)?),
794                // A field this revision does not define. §7.19.2: a receiver
795                // ignores what it does not know rather than refusing the whole
796                // structure, which is what lets a newer peer talk to an older one.
797                _ => reader.skip_value(&field)?,
798            }
799        }
800        Ok(Self {
801            initial_duration: initial_duration
802                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
803            augmentation_duration: augmentation_duration
804                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
805            max_duration: max_duration.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
806            blind_duration: blind_duration
807                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
808        })
809    }
810}
811
812/// `TransportOptionsStruct`.
813#[derive(Debug, Clone, Copy, PartialEq)]
814pub struct TransportOptionsStruct<'a> {
815    /// `StreamUsage`, field 0.
816    pub stream_usage: crate::clusters::generated::globals::StreamUsageEnum,
817    /// `VideoStreamID`, field 1.
818    pub video_stream_id: Option<Nullable<u16>>,
819    /// `AudioStreamID`, field 2.
820    pub audio_stream_id: Option<Nullable<u16>>,
821    /// `TLSEndpointID`, field 3.
822    pub tls_endpoint_id: u16,
823    /// `URL`, field 4.
824    pub url: &'a str,
825    /// `TriggerOptions`, field 5.
826    pub trigger_options: TransportTriggerOptionsStruct<'a>,
827    /// `IngestMethod`, field 6.
828    pub ingest_method: IngestMethodsEnum,
829    /// `ContainerOptions`, field 7.
830    pub container_options: ContainerOptionsStruct<'a>,
831    /// `ExpiryTime`, field 8.
832    pub expiry_time: Option<u32>,
833    /// `VideoStreams`, field 9.
834    pub video_streams: Option<TlvList<'a, VideoStreamStruct<'a>>>,
835    /// `AudioStreams`, field 10.
836    pub audio_streams: Option<TlvList<'a, AudioStreamStruct<'a>>>,
837}
838
839impl<'a> ToTlv for TransportOptionsStruct<'a> {
840    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
841        w.start_structure(tag)?;
842        self.stream_usage.to_tlv(w, Tag::Context(0))?;
843        if let Some(value) = &self.video_stream_id {
844            value.to_tlv(w, Tag::Context(1))?;
845        }
846        if let Some(value) = &self.audio_stream_id {
847            value.to_tlv(w, Tag::Context(2))?;
848        }
849        self.tls_endpoint_id.to_tlv(w, Tag::Context(3))?;
850        self.url.to_tlv(w, Tag::Context(4))?;
851        self.trigger_options.to_tlv(w, Tag::Context(5))?;
852        self.ingest_method.to_tlv(w, Tag::Context(6))?;
853        self.container_options.to_tlv(w, Tag::Context(7))?;
854        if let Some(value) = &self.expiry_time {
855            value.to_tlv(w, Tag::Context(8))?;
856        }
857        if let Some(value) = &self.video_streams {
858            value.to_tlv(w, Tag::Context(9))?;
859        }
860        if let Some(value) = &self.audio_streams {
861            value.to_tlv(w, Tag::Context(10))?;
862        }
863        w.end_container()
864    }
865}
866
867impl<'a> FromTlv<'a> for TransportOptionsStruct<'a> {
868    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
869        if element.value.container() != Some(ContainerKind::Structure) {
870            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
871        }
872        let mut stream_usage = None;
873        let mut video_stream_id = None;
874        let mut audio_stream_id = None;
875        let mut tls_endpoint_id = None;
876        let mut url = None;
877        let mut trigger_options = None;
878        let mut ingest_method = None;
879        let mut container_options = None;
880        let mut expiry_time = None;
881        let mut video_streams = None;
882        let mut audio_streams = None;
883        loop {
884            let Some(field) = reader.next_element()? else {
885                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
886            };
887            if field.value == Value::EndOfContainer {
888                break;
889            }
890            match field.tag.context() {
891                Some(0) => {
892                    stream_usage = Some(
893                        <crate::clusters::generated::globals::StreamUsageEnum>::from_tlv(
894                            reader, &field,
895                        )?,
896                    )
897                }
898                Some(1) => video_stream_id = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
899                Some(2) => audio_stream_id = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
900                Some(3) => tls_endpoint_id = Some(<u16>::from_tlv(reader, &field)?),
901                Some(4) => url = Some(<&'a str>::from_tlv(reader, &field)?),
902                Some(5) => {
903                    trigger_options = Some(<TransportTriggerOptionsStruct<'a>>::from_tlv(
904                        reader, &field,
905                    )?)
906                }
907                Some(6) => ingest_method = Some(<IngestMethodsEnum>::from_tlv(reader, &field)?),
908                Some(7) => {
909                    container_options =
910                        Some(<ContainerOptionsStruct<'a>>::from_tlv(reader, &field)?)
911                }
912                Some(8) => expiry_time = Some(<u32>::from_tlv(reader, &field)?),
913                Some(9) => {
914                    video_streams = Some(<TlvList<'a, VideoStreamStruct<'a>>>::from_tlv(
915                        reader, &field,
916                    )?)
917                }
918                Some(10) => {
919                    audio_streams = Some(<TlvList<'a, AudioStreamStruct<'a>>>::from_tlv(
920                        reader, &field,
921                    )?)
922                }
923                // A field this revision does not define. §7.19.2: a receiver
924                // ignores what it does not know rather than refusing the whole
925                // structure, which is what lets a newer peer talk to an older one.
926                _ => reader.skip_value(&field)?,
927            }
928        }
929        Ok(Self {
930            stream_usage: stream_usage.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
931            video_stream_id,
932            audio_stream_id,
933            tls_endpoint_id: tls_endpoint_id
934                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
935            url: url.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
936            trigger_options: trigger_options
937                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
938            ingest_method: ingest_method.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
939            container_options: container_options
940                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
941            expiry_time,
942            video_streams,
943            audio_streams,
944        })
945    }
946}
947
948/// `TransportTriggerOptionsStruct`.
949#[derive(Debug, Clone, Copy, PartialEq)]
950pub struct TransportTriggerOptionsStruct<'a> {
951    /// `TriggerType`, field 0.
952    pub trigger_type: TransportTriggerTypeEnum,
953    /// `MotionZones`, field 1.
954    pub motion_zones: Option<Nullable<TlvList<'a, TransportZoneOptionsStruct>>>,
955    /// `MotionSensitivity`, field 2.
956    pub motion_sensitivity: Option<Nullable<u8>>,
957    /// `MotionTimeControl`, field 3.
958    pub motion_time_control: Option<TransportMotionTriggerTimeControlStruct>,
959    /// `MaxPreRollLen`, field 4.
960    pub max_pre_roll_len: Option<u16>,
961}
962
963impl<'a> ToTlv for TransportTriggerOptionsStruct<'a> {
964    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
965        w.start_structure(tag)?;
966        self.trigger_type.to_tlv(w, Tag::Context(0))?;
967        if let Some(value) = &self.motion_zones {
968            value.to_tlv(w, Tag::Context(1))?;
969        }
970        if let Some(value) = &self.motion_sensitivity {
971            value.to_tlv(w, Tag::Context(2))?;
972        }
973        if let Some(value) = &self.motion_time_control {
974            value.to_tlv(w, Tag::Context(3))?;
975        }
976        if let Some(value) = &self.max_pre_roll_len {
977            value.to_tlv(w, Tag::Context(4))?;
978        }
979        w.end_container()
980    }
981}
982
983impl<'a> FromTlv<'a> for TransportTriggerOptionsStruct<'a> {
984    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
985        if element.value.container() != Some(ContainerKind::Structure) {
986            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
987        }
988        let mut trigger_type = None;
989        let mut motion_zones = None;
990        let mut motion_sensitivity = None;
991        let mut motion_time_control = None;
992        let mut max_pre_roll_len = None;
993        loop {
994            let Some(field) = reader.next_element()? else {
995                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
996            };
997            if field.value == Value::EndOfContainer {
998                break;
999            }
1000            match field.tag.context() {
1001                Some(0) => {
1002                    trigger_type = Some(<TransportTriggerTypeEnum>::from_tlv(reader, &field)?)
1003                }
1004                Some(1) => {
1005                    motion_zones = Some(
1006                        <Nullable<TlvList<'a, TransportZoneOptionsStruct>>>::from_tlv(
1007                            reader, &field,
1008                        )?,
1009                    )
1010                }
1011                Some(2) => motion_sensitivity = Some(<Nullable<u8>>::from_tlv(reader, &field)?),
1012                Some(3) => {
1013                    motion_time_control = Some(<TransportMotionTriggerTimeControlStruct>::from_tlv(
1014                        reader, &field,
1015                    )?)
1016                }
1017                Some(4) => max_pre_roll_len = Some(<u16>::from_tlv(reader, &field)?),
1018                // A field this revision does not define. §7.19.2: a receiver
1019                // ignores what it does not know rather than refusing the whole
1020                // structure, which is what lets a newer peer talk to an older one.
1021                _ => reader.skip_value(&field)?,
1022            }
1023        }
1024        Ok(Self {
1025            trigger_type: trigger_type.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1026            motion_zones,
1027            motion_sensitivity,
1028            motion_time_control,
1029            max_pre_roll_len,
1030        })
1031    }
1032}
1033
1034/// `TransportZoneOptionsStruct`.
1035#[derive(Debug, Clone, Copy, PartialEq)]
1036pub struct TransportZoneOptionsStruct {
1037    /// `Zone`, field 0.
1038    pub zone: Nullable<u16>,
1039    /// `Sensitivity`, field 1.
1040    pub sensitivity: Option<u8>,
1041}
1042
1043impl ToTlv for TransportZoneOptionsStruct {
1044    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1045        w.start_structure(tag)?;
1046        self.zone.to_tlv(w, Tag::Context(0))?;
1047        if let Some(value) = &self.sensitivity {
1048            value.to_tlv(w, Tag::Context(1))?;
1049        }
1050        w.end_container()
1051    }
1052}
1053
1054impl<'a> FromTlv<'a> for TransportZoneOptionsStruct {
1055    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1056        if element.value.container() != Some(ContainerKind::Structure) {
1057            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1058        }
1059        let mut zone = None;
1060        let mut sensitivity = None;
1061        loop {
1062            let Some(field) = reader.next_element()? else {
1063                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1064            };
1065            if field.value == Value::EndOfContainer {
1066                break;
1067            }
1068            match field.tag.context() {
1069                Some(0) => zone = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
1070                Some(1) => sensitivity = Some(<u8>::from_tlv(reader, &field)?),
1071                // A field this revision does not define. §7.19.2: a receiver
1072                // ignores what it does not know rather than refusing the whole
1073                // structure, which is what lets a newer peer talk to an older one.
1074                _ => reader.skip_value(&field)?,
1075            }
1076        }
1077        Ok(Self {
1078            zone: zone.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1079            sensitivity,
1080        })
1081    }
1082}
1083
1084/// `VideoStreamStruct`.
1085#[derive(Debug, Clone, Copy, PartialEq)]
1086pub struct VideoStreamStruct<'a> {
1087    /// `VideoStreamName`, field 0.
1088    pub video_stream_name: &'a str,
1089    /// `VideoStreamID`, field 1.
1090    pub video_stream_id: u16,
1091}
1092
1093impl<'a> ToTlv for VideoStreamStruct<'a> {
1094    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1095        w.start_structure(tag)?;
1096        self.video_stream_name.to_tlv(w, Tag::Context(0))?;
1097        self.video_stream_id.to_tlv(w, Tag::Context(1))?;
1098        w.end_container()
1099    }
1100}
1101
1102impl<'a> FromTlv<'a> for VideoStreamStruct<'a> {
1103    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1104        if element.value.container() != Some(ContainerKind::Structure) {
1105            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1106        }
1107        let mut video_stream_name = None;
1108        let mut video_stream_id = None;
1109        loop {
1110            let Some(field) = reader.next_element()? else {
1111                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1112            };
1113            if field.value == Value::EndOfContainer {
1114                break;
1115            }
1116            match field.tag.context() {
1117                Some(0) => video_stream_name = Some(<&'a str>::from_tlv(reader, &field)?),
1118                Some(1) => video_stream_id = Some(<u16>::from_tlv(reader, &field)?),
1119                // A field this revision does not define. §7.19.2: a receiver
1120                // ignores what it does not know rather than refusing the whole
1121                // structure, which is what lets a newer peer talk to an older one.
1122                _ => reader.skip_value(&field)?,
1123            }
1124        }
1125        Ok(Self {
1126            video_stream_name: video_stream_name
1127                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1128            video_stream_id: video_stream_id
1129                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1130        })
1131    }
1132}
1133
1134/// The fields of `AllocatePushTransport` (command `0x00`).
1135#[derive(Debug, Clone, Copy, PartialEq)]
1136pub struct AllocatePushTransportFields<'a> {
1137    /// `TransportOptions`, field 0.
1138    pub transport_options: TransportOptionsStruct<'a>,
1139}
1140
1141impl<'a> ToTlv for AllocatePushTransportFields<'a> {
1142    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1143        w.start_structure(tag)?;
1144        self.transport_options.to_tlv(w, Tag::Context(0))?;
1145        w.end_container()
1146    }
1147}
1148
1149impl<'a> FromTlv<'a> for AllocatePushTransportFields<'a> {
1150    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1151        if element.value.container() != Some(ContainerKind::Structure) {
1152            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1153        }
1154        let mut transport_options = None;
1155        loop {
1156            let Some(field) = reader.next_element()? else {
1157                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1158            };
1159            if field.value == Value::EndOfContainer {
1160                break;
1161            }
1162            match field.tag.context() {
1163                Some(0) => {
1164                    transport_options =
1165                        Some(<TransportOptionsStruct<'a>>::from_tlv(reader, &field)?)
1166                }
1167                // A field this revision does not define. §7.19.2: a receiver
1168                // ignores what it does not know rather than refusing the whole
1169                // structure, which is what lets a newer peer talk to an older one.
1170                _ => reader.skip_value(&field)?,
1171            }
1172        }
1173        Ok(Self {
1174            transport_options: transport_options
1175                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1176        })
1177    }
1178}
1179
1180/// The fields of `AllocatePushTransportResponse` (command `0x01`).
1181#[derive(Debug, Clone, Copy, PartialEq)]
1182pub struct AllocatePushTransportResponseFields<'a> {
1183    /// `TransportConfiguration`, field 0.
1184    pub transport_configuration: TransportConfigurationStruct<'a>,
1185}
1186
1187impl<'a> ToTlv for AllocatePushTransportResponseFields<'a> {
1188    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1189        w.start_structure(tag)?;
1190        self.transport_configuration.to_tlv(w, Tag::Context(0))?;
1191        w.end_container()
1192    }
1193}
1194
1195impl<'a> FromTlv<'a> for AllocatePushTransportResponseFields<'a> {
1196    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1197        if element.value.container() != Some(ContainerKind::Structure) {
1198            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1199        }
1200        let mut transport_configuration = None;
1201        loop {
1202            let Some(field) = reader.next_element()? else {
1203                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1204            };
1205            if field.value == Value::EndOfContainer {
1206                break;
1207            }
1208            match field.tag.context() {
1209                Some(0) => {
1210                    transport_configuration = Some(<TransportConfigurationStruct<'a>>::from_tlv(
1211                        reader, &field,
1212                    )?)
1213                }
1214                // A field this revision does not define. §7.19.2: a receiver
1215                // ignores what it does not know rather than refusing the whole
1216                // structure, which is what lets a newer peer talk to an older one.
1217                _ => reader.skip_value(&field)?,
1218            }
1219        }
1220        Ok(Self {
1221            transport_configuration: transport_configuration
1222                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1223        })
1224    }
1225}
1226
1227/// The fields of `DeallocatePushTransport` (command `0x02`).
1228#[derive(Debug, Clone, Copy, PartialEq)]
1229pub struct DeallocatePushTransportFields {
1230    /// `ConnectionID`, field 0.
1231    pub connection_id: u16,
1232}
1233
1234impl ToTlv for DeallocatePushTransportFields {
1235    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1236        w.start_structure(tag)?;
1237        self.connection_id.to_tlv(w, Tag::Context(0))?;
1238        w.end_container()
1239    }
1240}
1241
1242impl<'a> FromTlv<'a> for DeallocatePushTransportFields {
1243    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1244        if element.value.container() != Some(ContainerKind::Structure) {
1245            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1246        }
1247        let mut connection_id = None;
1248        loop {
1249            let Some(field) = reader.next_element()? else {
1250                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1251            };
1252            if field.value == Value::EndOfContainer {
1253                break;
1254            }
1255            match field.tag.context() {
1256                Some(0) => connection_id = Some(<u16>::from_tlv(reader, &field)?),
1257                // A field this revision does not define. §7.19.2: a receiver
1258                // ignores what it does not know rather than refusing the whole
1259                // structure, which is what lets a newer peer talk to an older one.
1260                _ => reader.skip_value(&field)?,
1261            }
1262        }
1263        Ok(Self {
1264            connection_id: connection_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1265        })
1266    }
1267}
1268
1269/// The fields of `ModifyPushTransport` (command `0x03`).
1270#[derive(Debug, Clone, Copy, PartialEq)]
1271pub struct ModifyPushTransportFields<'a> {
1272    /// `ConnectionID`, field 0.
1273    pub connection_id: u16,
1274    /// `TransportOptions`, field 1.
1275    pub transport_options: TransportOptionsStruct<'a>,
1276}
1277
1278impl<'a> ToTlv for ModifyPushTransportFields<'a> {
1279    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1280        w.start_structure(tag)?;
1281        self.connection_id.to_tlv(w, Tag::Context(0))?;
1282        self.transport_options.to_tlv(w, Tag::Context(1))?;
1283        w.end_container()
1284    }
1285}
1286
1287impl<'a> FromTlv<'a> for ModifyPushTransportFields<'a> {
1288    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1289        if element.value.container() != Some(ContainerKind::Structure) {
1290            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1291        }
1292        let mut connection_id = None;
1293        let mut transport_options = None;
1294        loop {
1295            let Some(field) = reader.next_element()? else {
1296                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1297            };
1298            if field.value == Value::EndOfContainer {
1299                break;
1300            }
1301            match field.tag.context() {
1302                Some(0) => connection_id = Some(<u16>::from_tlv(reader, &field)?),
1303                Some(1) => {
1304                    transport_options =
1305                        Some(<TransportOptionsStruct<'a>>::from_tlv(reader, &field)?)
1306                }
1307                // A field this revision does not define. §7.19.2: a receiver
1308                // ignores what it does not know rather than refusing the whole
1309                // structure, which is what lets a newer peer talk to an older one.
1310                _ => reader.skip_value(&field)?,
1311            }
1312        }
1313        Ok(Self {
1314            connection_id: connection_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1315            transport_options: transport_options
1316                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1317        })
1318    }
1319}
1320
1321/// The fields of `SetTransportStatus` (command `0x04`).
1322#[derive(Debug, Clone, Copy, PartialEq)]
1323pub struct SetTransportStatusFields {
1324    /// `ConnectionID`, field 0.
1325    pub connection_id: Nullable<u16>,
1326    /// `TransportStatus`, field 1.
1327    pub transport_status: TransportStatusEnum,
1328}
1329
1330impl ToTlv for SetTransportStatusFields {
1331    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1332        w.start_structure(tag)?;
1333        self.connection_id.to_tlv(w, Tag::Context(0))?;
1334        self.transport_status.to_tlv(w, Tag::Context(1))?;
1335        w.end_container()
1336    }
1337}
1338
1339impl<'a> FromTlv<'a> for SetTransportStatusFields {
1340    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1341        if element.value.container() != Some(ContainerKind::Structure) {
1342            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1343        }
1344        let mut connection_id = None;
1345        let mut transport_status = None;
1346        loop {
1347            let Some(field) = reader.next_element()? else {
1348                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1349            };
1350            if field.value == Value::EndOfContainer {
1351                break;
1352            }
1353            match field.tag.context() {
1354                Some(0) => connection_id = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
1355                Some(1) => {
1356                    transport_status = Some(<TransportStatusEnum>::from_tlv(reader, &field)?)
1357                }
1358                // A field this revision does not define. §7.19.2: a receiver
1359                // ignores what it does not know rather than refusing the whole
1360                // structure, which is what lets a newer peer talk to an older one.
1361                _ => reader.skip_value(&field)?,
1362            }
1363        }
1364        Ok(Self {
1365            connection_id: connection_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1366            transport_status: transport_status
1367                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1368        })
1369    }
1370}
1371
1372/// The fields of `ManuallyTriggerTransport` (command `0x05`).
1373#[derive(Debug, Clone, Copy, PartialEq)]
1374pub struct ManuallyTriggerTransportFields<'a> {
1375    /// `ConnectionID`, field 0.
1376    pub connection_id: u16,
1377    /// `ActivationReason`, field 1.
1378    pub activation_reason: TriggerActivationReasonEnum,
1379    /// `TimeControl`, field 2.
1380    pub time_control: Option<TransportMotionTriggerTimeControlStruct>,
1381    /// `UserDefined`, field 3.
1382    pub user_defined: Option<&'a [u8]>,
1383}
1384
1385impl<'a> ToTlv for ManuallyTriggerTransportFields<'a> {
1386    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1387        w.start_structure(tag)?;
1388        self.connection_id.to_tlv(w, Tag::Context(0))?;
1389        self.activation_reason.to_tlv(w, Tag::Context(1))?;
1390        if let Some(value) = &self.time_control {
1391            value.to_tlv(w, Tag::Context(2))?;
1392        }
1393        if let Some(value) = &self.user_defined {
1394            value.to_tlv(w, Tag::Context(3))?;
1395        }
1396        w.end_container()
1397    }
1398}
1399
1400impl<'a> FromTlv<'a> for ManuallyTriggerTransportFields<'a> {
1401    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1402        if element.value.container() != Some(ContainerKind::Structure) {
1403            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1404        }
1405        let mut connection_id = None;
1406        let mut activation_reason = None;
1407        let mut time_control = None;
1408        let mut user_defined = None;
1409        loop {
1410            let Some(field) = reader.next_element()? else {
1411                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1412            };
1413            if field.value == Value::EndOfContainer {
1414                break;
1415            }
1416            match field.tag.context() {
1417                Some(0) => connection_id = Some(<u16>::from_tlv(reader, &field)?),
1418                Some(1) => {
1419                    activation_reason =
1420                        Some(<TriggerActivationReasonEnum>::from_tlv(reader, &field)?)
1421                }
1422                Some(2) => {
1423                    time_control = Some(<TransportMotionTriggerTimeControlStruct>::from_tlv(
1424                        reader, &field,
1425                    )?)
1426                }
1427                Some(3) => user_defined = Some(<&'a [u8]>::from_tlv(reader, &field)?),
1428                // A field this revision does not define. §7.19.2: a receiver
1429                // ignores what it does not know rather than refusing the whole
1430                // structure, which is what lets a newer peer talk to an older one.
1431                _ => reader.skip_value(&field)?,
1432            }
1433        }
1434        Ok(Self {
1435            connection_id: connection_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1436            activation_reason: activation_reason
1437                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1438            time_control,
1439            user_defined,
1440        })
1441    }
1442}
1443
1444/// The fields of `FindTransport` (command `0x06`).
1445#[derive(Debug, Clone, Copy, PartialEq)]
1446pub struct FindTransportFields {
1447    /// `ConnectionID`, field 0.
1448    pub connection_id: Nullable<u16>,
1449}
1450
1451impl ToTlv for FindTransportFields {
1452    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1453        w.start_structure(tag)?;
1454        self.connection_id.to_tlv(w, Tag::Context(0))?;
1455        w.end_container()
1456    }
1457}
1458
1459impl<'a> FromTlv<'a> for FindTransportFields {
1460    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1461        if element.value.container() != Some(ContainerKind::Structure) {
1462            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1463        }
1464        let mut connection_id = None;
1465        loop {
1466            let Some(field) = reader.next_element()? else {
1467                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1468            };
1469            if field.value == Value::EndOfContainer {
1470                break;
1471            }
1472            match field.tag.context() {
1473                Some(0) => connection_id = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
1474                // A field this revision does not define. §7.19.2: a receiver
1475                // ignores what it does not know rather than refusing the whole
1476                // structure, which is what lets a newer peer talk to an older one.
1477                _ => reader.skip_value(&field)?,
1478            }
1479        }
1480        Ok(Self {
1481            connection_id: connection_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1482        })
1483    }
1484}
1485
1486/// The fields of `FindTransportResponse` (command `0x07`).
1487#[derive(Debug, Clone, Copy, PartialEq)]
1488pub struct FindTransportResponseFields<'a> {
1489    /// `TransportConfigurations`, field 0.
1490    pub transport_configurations: TlvList<'a, TransportConfigurationStruct<'a>>,
1491}
1492
1493impl<'a> ToTlv for FindTransportResponseFields<'a> {
1494    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1495        w.start_structure(tag)?;
1496        self.transport_configurations.to_tlv(w, Tag::Context(0))?;
1497        w.end_container()
1498    }
1499}
1500
1501impl<'a> FromTlv<'a> for FindTransportResponseFields<'a> {
1502    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1503        if element.value.container() != Some(ContainerKind::Structure) {
1504            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1505        }
1506        let mut transport_configurations = None;
1507        loop {
1508            let Some(field) = reader.next_element()? else {
1509                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1510            };
1511            if field.value == Value::EndOfContainer {
1512                break;
1513            }
1514            match field.tag.context() {
1515                Some(0) => {
1516                    transport_configurations = Some(
1517                        <TlvList<'a, TransportConfigurationStruct<'a>>>::from_tlv(reader, &field)?,
1518                    )
1519                }
1520                // A field this revision does not define. §7.19.2: a receiver
1521                // ignores what it does not know rather than refusing the whole
1522                // structure, which is what lets a newer peer talk to an older one.
1523                _ => reader.skip_value(&field)?,
1524            }
1525        }
1526        Ok(Self {
1527            transport_configurations: transport_configurations
1528                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1529        })
1530    }
1531}
1532
1533/// Every attribute the specification defines, with its conformance.
1534pub const ATTRIBUTES: &[Attribute] = &[
1535    Attribute {
1536        id: 0x0000,
1537        name: "SupportedFormats",
1538        kind: "list[SupportedFormatStruct]",
1539        access: Access::read_only(Privilege::View),
1540        qualities: AttributeQualities::FIXED,
1541        reporting: Reporting::OnChange,
1542        conform: Conform::MANDATORY,
1543    },
1544    Attribute {
1545        id: 0x0001,
1546        name: "CurrentConnections",
1547        kind: "list[TransportConfigurationStruct]",
1548        access: Access::read_only(Privilege::View)
1549            .with_qualities(AccessQualities::FABRIC_SENSITIVE),
1550        qualities: AttributeQualities::NON_VOLATILE,
1551        reporting: Reporting::OnChange,
1552        conform: Conform::MANDATORY,
1553    },
1554];
1555
1556/// Every command, with its conformance.
1557pub const COMMANDS: &[Command] = &[
1558    Command {
1559        id: 0x00,
1560        name: "AllocatePushTransport",
1561        to_server: true,
1562        response: Some(0x01),
1563        access: Access::invoke(Privilege::Manage)
1564            .with_qualities(AccessQualities::FABRIC_SCOPED.union(AccessQualities::LARGE)),
1565        conform: Conform::MANDATORY,
1566    },
1567    Command {
1568        id: 0x01,
1569        name: "AllocatePushTransportResponse",
1570        to_server: false,
1571        response: None,
1572        access: Access::invoke(Privilege::Operate).with_qualities(AccessQualities::LARGE),
1573        conform: Conform::MANDATORY,
1574    },
1575    Command {
1576        id: 0x02,
1577        name: "DeallocatePushTransport",
1578        to_server: true,
1579        response: None,
1580        access: Access::invoke(Privilege::Manage).with_qualities(AccessQualities::FABRIC_SCOPED),
1581        conform: Conform::MANDATORY,
1582    },
1583    Command {
1584        id: 0x03,
1585        name: "ModifyPushTransport",
1586        to_server: true,
1587        response: None,
1588        access: Access::invoke(Privilege::Manage).with_qualities(AccessQualities::FABRIC_SCOPED),
1589        conform: Conform::MANDATORY,
1590    },
1591    Command {
1592        id: 0x04,
1593        name: "SetTransportStatus",
1594        to_server: true,
1595        response: None,
1596        access: Access::invoke(Privilege::Manage).with_qualities(AccessQualities::FABRIC_SCOPED),
1597        conform: Conform::MANDATORY,
1598    },
1599    Command {
1600        id: 0x05,
1601        name: "ManuallyTriggerTransport",
1602        to_server: true,
1603        response: None,
1604        access: Access::invoke(Privilege::Operate).with_qualities(AccessQualities::FABRIC_SCOPED),
1605        conform: Conform::MANDATORY,
1606    },
1607    Command {
1608        id: 0x06,
1609        name: "FindTransport",
1610        to_server: true,
1611        response: Some(0x07),
1612        access: Access::invoke(Privilege::Operate)
1613            .with_qualities(AccessQualities::FABRIC_SCOPED.union(AccessQualities::LARGE)),
1614        conform: Conform::MANDATORY,
1615    },
1616    Command {
1617        id: 0x07,
1618        name: "FindTransportResponse",
1619        to_server: false,
1620        response: None,
1621        access: Access::invoke(Privilege::Operate).with_qualities(AccessQualities::LARGE),
1622        conform: Conform::MANDATORY,
1623    },
1624];
1625
1626/// Every event, with its conformance.
1627pub const EVENTS: &[Event] = &[
1628    Event {
1629        id: 0x00,
1630        name: "PushTransportBegin",
1631        priority: EventPriority::Info,
1632        access: Access::read_only(Privilege::View),
1633        conform: Conform::MANDATORY,
1634    },
1635    Event {
1636        id: 0x01,
1637        name: "PushTransportEnd",
1638        priority: EventPriority::Info,
1639        access: Access::read_only(Privilege::View),
1640        conform: Conform::MANDATORY,
1641    },
1642];
1643
1644/// The whole cluster, as the specification defines it.
1645pub const CLUSTER: Cluster = Cluster {
1646    id: ID,
1647    name: "Push AV Stream Transport",
1648    revision: REVISION,
1649    pics: "PAVST",
1650    derived_from: None,
1651    features: FEATURES,
1652    attributes: ATTRIBUTES,
1653    commands: COMMANDS,
1654    events: EVENTS,
1655};