Skip to main content

matter_kit/clusters/generated/
channel.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Channel — cluster 0x0504.
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//! Channel (cluster `0x0504`, revision 2).
10//!
11//! 11 identifiers, 4 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 = 0x0504;
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 = "CHANNEL";
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    /// Provides list of available channels.
42    ///
43    /// Code `CL`, bit 0.
44    pub const CHANNEL_LIST: u32 = 1 << 0;
45    /// Provides lineup info, which is a reference to an external source of lineup information.
46    ///
47    /// Code `LI`, bit 1.
48    pub const LINEUP_INFO: u32 = 1 << 1;
49    /// Provides electronic program guide information.
50    ///
51    /// Code `EG`, bit 2.
52    pub const ELECTRONIC_GUIDE: u32 = 1 << 2;
53    /// Provides ability to record program.
54    ///
55    /// Code `RP`, bit 3.
56    pub const RECORD_PROGRAM: u32 = 1 << 3;
57}
58
59/// Every feature bit, with its conformance.
60pub const FEATURES: &[Feature] = &[
61    Feature {
62        bit: 0,
63        code: "CL",
64        name: "ChannelList",
65        conform: Conform::OPTIONAL,
66    },
67    Feature {
68        bit: 1,
69        code: "LI",
70        name: "LineupInfo",
71        conform: Conform::OPTIONAL,
72    },
73    Feature {
74        bit: 2,
75        code: "EG",
76        name: "ElectronicGuide",
77        conform: Conform::OPTIONAL,
78    },
79    Feature {
80        bit: 3,
81        code: "RP",
82        name: "RecordProgram",
83        conform: Conform::OPTIONAL,
84    },
85];
86
87/// The attribute ids.
88pub mod attribute {
89    use crate::im::AttributeId;
90
91    /// `ChannelList`.
92    pub const CHANNEL_LIST: AttributeId = 0x00;
93    /// `Lineup`.
94    pub const LINEUP: AttributeId = 0x01;
95    /// `CurrentChannel`.
96    pub const CURRENT_CHANNEL: AttributeId = 0x02;
97}
98
99/// The command ids.
100pub mod command {
101    use crate::im::CommandId;
102
103    /// `ChangeChannel`.
104    pub const CHANGE_CHANNEL: CommandId = 0x00;
105    /// `ChangeChannelResponse`.
106    pub const CHANGE_CHANNEL_RESPONSE: CommandId = 0x01;
107    /// `ChangeChannelByNumber`.
108    pub const CHANGE_CHANNEL_BY_NUMBER: CommandId = 0x02;
109    /// `SkipChannel`.
110    pub const SKIP_CHANNEL: CommandId = 0x03;
111    /// `GetProgramGuide`.
112    pub const GET_PROGRAM_GUIDE: CommandId = 0x04;
113    /// `ProgramGuideResponse`.
114    pub const PROGRAM_GUIDE_RESPONSE: CommandId = 0x05;
115    /// `RecordProgram`.
116    pub const RECORD_PROGRAM: CommandId = 0x06;
117    /// `CancelRecordProgram`.
118    pub const CANCEL_RECORD_PROGRAM: CommandId = 0x07;
119}
120
121/// `ChannelTypeEnum`.
122#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
123#[repr(u8)]
124pub enum ChannelTypeEnum {
125    /// The channel is sourced from a satellite provider.
126    Satellite = 0,
127    /// The channel is sourced from a cable provider.
128    Cable = 1,
129    /// The channel is sourced from a terrestrial provider.
130    Terrestrial = 2,
131    /// The channel is sourced from an OTT provider.
132    OTT = 3,
133}
134
135impl ChannelTypeEnum {
136    /// Reads a wire value, or `None` for one this revision does not define.
137    #[must_use]
138    pub const fn from_value(value: u8) -> Option<Self> {
139        match value {
140            0 => Some(Self::Satellite),
141            1 => Some(Self::Cable),
142            2 => Some(Self::Terrestrial),
143            3 => Some(Self::OTT),
144            _ => None,
145        }
146    }
147
148    /// Its wire value.
149    #[must_use]
150    pub const fn value(self) -> u8 {
151        self as u8
152    }
153}
154
155impl ToTlv for ChannelTypeEnum {
156    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
157        self.value().to_tlv(w, tag)
158    }
159}
160
161impl<'a> FromTlv<'a> for ChannelTypeEnum {
162    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
163        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
164        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
165    }
166}
167
168/// `LineupInfoTypeEnum`.
169#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
170#[repr(u8)]
171pub enum LineupInfoTypeEnum {
172    /// Multi System Operator
173    MSO = 0,
174}
175
176impl LineupInfoTypeEnum {
177    /// Reads a wire value, or `None` for one this revision does not define.
178    #[must_use]
179    pub const fn from_value(value: u8) -> Option<Self> {
180        match value {
181            0 => Some(Self::MSO),
182            _ => None,
183        }
184    }
185
186    /// Its wire value.
187    #[must_use]
188    pub const fn value(self) -> u8 {
189        self as u8
190    }
191}
192
193impl ToTlv for LineupInfoTypeEnum {
194    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
195        self.value().to_tlv(w, tag)
196    }
197}
198
199impl<'a> FromTlv<'a> for LineupInfoTypeEnum {
200    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
201        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
202        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
203    }
204}
205
206/// `StatusEnum`.
207#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
208#[repr(u8)]
209pub enum StatusEnum {
210    /// Command succeeded
211    Success = 0,
212    /// More than one equal match for the ChannelInfoStruct passed in.
213    MultipleMatches = 1,
214    /// No matches for the ChannelInfoStruct passed in.
215    NoMatches = 2,
216}
217
218impl StatusEnum {
219    /// Reads a wire value, or `None` for one this revision does not define.
220    #[must_use]
221    pub const fn from_value(value: u8) -> Option<Self> {
222        match value {
223            0 => Some(Self::Success),
224            1 => Some(Self::MultipleMatches),
225            2 => Some(Self::NoMatches),
226            _ => None,
227        }
228    }
229
230    /// Its wire value.
231    #[must_use]
232    pub const fn value(self) -> u8 {
233        self as u8
234    }
235}
236
237impl ToTlv for StatusEnum {
238    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
239        self.value().to_tlv(w, tag)
240    }
241}
242
243impl<'a> FromTlv<'a> for StatusEnum {
244    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
245        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
246        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
247    }
248}
249
250bitflags::bitflags! {
251    /// `RecordingFlagBitmap`.
252    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
253    pub struct RecordingFlagBitmap: u8 {
254        /// The program is scheduled for recording.
255        const SCHEDULED = 1 << 0;
256        /// The program series is scheduled for recording.
257        const RECORD_SERIES = 1 << 1;
258        /// The program is recorded and available to be played.
259        const RECORDED = 1 << 2;
260    }
261}
262
263impl ToTlv for RecordingFlagBitmap {
264    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
265        self.bits().to_tlv(w, tag)
266    }
267}
268
269impl<'a> FromTlv<'a> for RecordingFlagBitmap {
270    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
271        let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
272        Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
273    }
274}
275
276/// `ChannelInfoStruct`.
277#[derive(Debug, Clone, Copy, PartialEq)]
278pub struct ChannelInfoStruct<'a> {
279    /// `MajorNumber`, field 0.
280    pub major_number: u16,
281    /// `MinorNumber`, field 1.
282    pub minor_number: u16,
283    /// `Name`, field 2.
284    pub name: Option<&'a str>,
285    /// `CallSign`, field 3.
286    pub call_sign: Option<&'a str>,
287    /// `AffiliateCallSign`, field 4.
288    pub affiliate_call_sign: Option<&'a str>,
289    /// `Identifier`, field 5.
290    pub identifier: Option<&'a str>,
291    /// `Type`, field 6.
292    pub type_: Option<ChannelTypeEnum>,
293}
294
295impl<'a> ToTlv for ChannelInfoStruct<'a> {
296    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
297        w.start_structure(tag)?;
298        self.major_number.to_tlv(w, Tag::Context(0))?;
299        self.minor_number.to_tlv(w, Tag::Context(1))?;
300        if let Some(value) = &self.name {
301            value.to_tlv(w, Tag::Context(2))?;
302        }
303        if let Some(value) = &self.call_sign {
304            value.to_tlv(w, Tag::Context(3))?;
305        }
306        if let Some(value) = &self.affiliate_call_sign {
307            value.to_tlv(w, Tag::Context(4))?;
308        }
309        if let Some(value) = &self.identifier {
310            value.to_tlv(w, Tag::Context(5))?;
311        }
312        if let Some(value) = &self.type_ {
313            value.to_tlv(w, Tag::Context(6))?;
314        }
315        w.end_container()
316    }
317}
318
319impl<'a> FromTlv<'a> for ChannelInfoStruct<'a> {
320    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
321        if element.value.container() != Some(ContainerKind::Structure) {
322            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
323        }
324        let mut major_number = None;
325        let mut minor_number = None;
326        let mut name = None;
327        let mut call_sign = None;
328        let mut affiliate_call_sign = None;
329        let mut identifier = None;
330        let mut type_ = None;
331        loop {
332            let Some(field) = reader.next_element()? else {
333                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
334            };
335            if field.value == Value::EndOfContainer {
336                break;
337            }
338            match field.tag.context() {
339                Some(0) => major_number = Some(<u16>::from_tlv(reader, &field)?),
340                Some(1) => minor_number = Some(<u16>::from_tlv(reader, &field)?),
341                Some(2) => name = Some(<&'a str>::from_tlv(reader, &field)?),
342                Some(3) => call_sign = Some(<&'a str>::from_tlv(reader, &field)?),
343                Some(4) => affiliate_call_sign = Some(<&'a str>::from_tlv(reader, &field)?),
344                Some(5) => identifier = Some(<&'a str>::from_tlv(reader, &field)?),
345                Some(6) => type_ = Some(<ChannelTypeEnum>::from_tlv(reader, &field)?),
346                // A field this revision does not define. §7.19.2: a receiver
347                // ignores what it does not know rather than refusing the whole
348                // structure, which is what lets a newer peer talk to an older one.
349                _ => reader.skip_value(&field)?,
350            }
351        }
352        Ok(Self {
353            major_number: major_number.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
354            minor_number: minor_number.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
355            name,
356            call_sign,
357            affiliate_call_sign,
358            identifier,
359            type_,
360        })
361    }
362}
363
364/// `ChannelPagingStruct`.
365#[derive(Debug, Clone, Copy, PartialEq)]
366pub struct ChannelPagingStruct<'a> {
367    /// `PreviousToken`, field 0.
368    pub previous_token: Option<Nullable<PageTokenStruct<'a>>>,
369    /// `NextToken`, field 1.
370    pub next_token: Option<Nullable<PageTokenStruct<'a>>>,
371}
372
373impl<'a> ToTlv for ChannelPagingStruct<'a> {
374    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
375        w.start_structure(tag)?;
376        if let Some(value) = &self.previous_token {
377            value.to_tlv(w, Tag::Context(0))?;
378        }
379        if let Some(value) = &self.next_token {
380            value.to_tlv(w, Tag::Context(1))?;
381        }
382        w.end_container()
383    }
384}
385
386impl<'a> FromTlv<'a> for ChannelPagingStruct<'a> {
387    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
388        if element.value.container() != Some(ContainerKind::Structure) {
389            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
390        }
391        let mut previous_token = None;
392        let mut next_token = None;
393        loop {
394            let Some(field) = reader.next_element()? else {
395                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
396            };
397            if field.value == Value::EndOfContainer {
398                break;
399            }
400            match field.tag.context() {
401                Some(0) => {
402                    previous_token =
403                        Some(<Nullable<PageTokenStruct<'a>>>::from_tlv(reader, &field)?)
404                }
405                Some(1) => {
406                    next_token = Some(<Nullable<PageTokenStruct<'a>>>::from_tlv(reader, &field)?)
407                }
408                // A field this revision does not define. §7.19.2: a receiver
409                // ignores what it does not know rather than refusing the whole
410                // structure, which is what lets a newer peer talk to an older one.
411                _ => reader.skip_value(&field)?,
412            }
413        }
414        Ok(Self {
415            previous_token,
416            next_token,
417        })
418    }
419}
420
421/// `LineupInfoStruct`.
422#[derive(Debug, Clone, Copy, PartialEq)]
423pub struct LineupInfoStruct<'a> {
424    /// `OperatorName`, field 0.
425    pub operator_name: &'a str,
426    /// `LineupName`, field 1.
427    pub lineup_name: Option<&'a str>,
428    /// `PostalCode`, field 2.
429    pub postal_code: Option<&'a str>,
430    /// `LineupInfoType`, field 3.
431    pub lineup_info_type: LineupInfoTypeEnum,
432}
433
434impl<'a> ToTlv for LineupInfoStruct<'a> {
435    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
436        w.start_structure(tag)?;
437        self.operator_name.to_tlv(w, Tag::Context(0))?;
438        if let Some(value) = &self.lineup_name {
439            value.to_tlv(w, Tag::Context(1))?;
440        }
441        if let Some(value) = &self.postal_code {
442            value.to_tlv(w, Tag::Context(2))?;
443        }
444        self.lineup_info_type.to_tlv(w, Tag::Context(3))?;
445        w.end_container()
446    }
447}
448
449impl<'a> FromTlv<'a> for LineupInfoStruct<'a> {
450    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
451        if element.value.container() != Some(ContainerKind::Structure) {
452            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
453        }
454        let mut operator_name = None;
455        let mut lineup_name = None;
456        let mut postal_code = None;
457        let mut lineup_info_type = None;
458        loop {
459            let Some(field) = reader.next_element()? else {
460                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
461            };
462            if field.value == Value::EndOfContainer {
463                break;
464            }
465            match field.tag.context() {
466                Some(0) => operator_name = Some(<&'a str>::from_tlv(reader, &field)?),
467                Some(1) => lineup_name = Some(<&'a str>::from_tlv(reader, &field)?),
468                Some(2) => postal_code = Some(<&'a str>::from_tlv(reader, &field)?),
469                Some(3) => lineup_info_type = Some(<LineupInfoTypeEnum>::from_tlv(reader, &field)?),
470                // A field this revision does not define. §7.19.2: a receiver
471                // ignores what it does not know rather than refusing the whole
472                // structure, which is what lets a newer peer talk to an older one.
473                _ => reader.skip_value(&field)?,
474            }
475        }
476        Ok(Self {
477            operator_name: operator_name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
478            lineup_name,
479            postal_code,
480            lineup_info_type: lineup_info_type
481                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
482        })
483    }
484}
485
486/// `PageTokenStruct`.
487#[derive(Debug, Clone, Copy, PartialEq)]
488pub struct PageTokenStruct<'a> {
489    /// `Limit`, field 0.
490    pub limit: Option<u16>,
491    /// `After`, field 1.
492    pub after: Option<&'a str>,
493    /// `Before`, field 2.
494    pub before: Option<&'a str>,
495}
496
497impl<'a> ToTlv for PageTokenStruct<'a> {
498    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
499        w.start_structure(tag)?;
500        if let Some(value) = &self.limit {
501            value.to_tlv(w, Tag::Context(0))?;
502        }
503        if let Some(value) = &self.after {
504            value.to_tlv(w, Tag::Context(1))?;
505        }
506        if let Some(value) = &self.before {
507            value.to_tlv(w, Tag::Context(2))?;
508        }
509        w.end_container()
510    }
511}
512
513impl<'a> FromTlv<'a> for PageTokenStruct<'a> {
514    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
515        if element.value.container() != Some(ContainerKind::Structure) {
516            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
517        }
518        let mut limit = None;
519        let mut after = None;
520        let mut before = None;
521        loop {
522            let Some(field) = reader.next_element()? else {
523                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
524            };
525            if field.value == Value::EndOfContainer {
526                break;
527            }
528            match field.tag.context() {
529                Some(0) => limit = Some(<u16>::from_tlv(reader, &field)?),
530                Some(1) => after = Some(<&'a str>::from_tlv(reader, &field)?),
531                Some(2) => before = Some(<&'a str>::from_tlv(reader, &field)?),
532                // A field this revision does not define. §7.19.2: a receiver
533                // ignores what it does not know rather than refusing the whole
534                // structure, which is what lets a newer peer talk to an older one.
535                _ => reader.skip_value(&field)?,
536            }
537        }
538        Ok(Self {
539            limit,
540            after,
541            before,
542        })
543    }
544}
545
546/// `ProgramCastStruct`.
547#[derive(Debug, Clone, Copy, PartialEq)]
548pub struct ProgramCastStruct<'a> {
549    /// `Name`, field 0.
550    pub name: &'a str,
551    /// `Role`, field 1.
552    pub role: &'a str,
553}
554
555impl<'a> ToTlv for ProgramCastStruct<'a> {
556    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
557        w.start_structure(tag)?;
558        self.name.to_tlv(w, Tag::Context(0))?;
559        self.role.to_tlv(w, Tag::Context(1))?;
560        w.end_container()
561    }
562}
563
564impl<'a> FromTlv<'a> for ProgramCastStruct<'a> {
565    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
566        if element.value.container() != Some(ContainerKind::Structure) {
567            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
568        }
569        let mut name = None;
570        let mut role = None;
571        loop {
572            let Some(field) = reader.next_element()? else {
573                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
574            };
575            if field.value == Value::EndOfContainer {
576                break;
577            }
578            match field.tag.context() {
579                Some(0) => name = Some(<&'a str>::from_tlv(reader, &field)?),
580                Some(1) => role = Some(<&'a str>::from_tlv(reader, &field)?),
581                // A field this revision does not define. §7.19.2: a receiver
582                // ignores what it does not know rather than refusing the whole
583                // structure, which is what lets a newer peer talk to an older one.
584                _ => reader.skip_value(&field)?,
585            }
586        }
587        Ok(Self {
588            name: name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
589            role: role.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
590        })
591    }
592}
593
594/// `ProgramCategoryStruct`.
595#[derive(Debug, Clone, Copy, PartialEq)]
596pub struct ProgramCategoryStruct<'a> {
597    /// `Category`, field 0.
598    pub category: &'a str,
599    /// `SubCategory`, field 1.
600    pub sub_category: Option<&'a str>,
601}
602
603impl<'a> ToTlv for ProgramCategoryStruct<'a> {
604    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
605        w.start_structure(tag)?;
606        self.category.to_tlv(w, Tag::Context(0))?;
607        if let Some(value) = &self.sub_category {
608            value.to_tlv(w, Tag::Context(1))?;
609        }
610        w.end_container()
611    }
612}
613
614impl<'a> FromTlv<'a> for ProgramCategoryStruct<'a> {
615    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
616        if element.value.container() != Some(ContainerKind::Structure) {
617            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
618        }
619        let mut category = None;
620        let mut sub_category = None;
621        loop {
622            let Some(field) = reader.next_element()? else {
623                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
624            };
625            if field.value == Value::EndOfContainer {
626                break;
627            }
628            match field.tag.context() {
629                Some(0) => category = Some(<&'a str>::from_tlv(reader, &field)?),
630                Some(1) => sub_category = Some(<&'a str>::from_tlv(reader, &field)?),
631                // A field this revision does not define. §7.19.2: a receiver
632                // ignores what it does not know rather than refusing the whole
633                // structure, which is what lets a newer peer talk to an older one.
634                _ => reader.skip_value(&field)?,
635            }
636        }
637        Ok(Self {
638            category: category.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
639            sub_category,
640        })
641    }
642}
643
644/// `ProgramStruct`.
645#[derive(Debug, Clone, Copy, PartialEq)]
646pub struct ProgramStruct<'a> {
647    /// `Identifier`, field 0.
648    pub identifier: &'a str,
649    /// `Channel`, field 1.
650    pub channel: ChannelInfoStruct<'a>,
651    /// `StartTime`, field 2.
652    pub start_time: u32,
653    /// `EndTime`, field 3.
654    pub end_time: u32,
655    /// `Title`, field 4.
656    pub title: &'a str,
657    /// `Subtitle`, field 5.
658    pub subtitle: Option<&'a str>,
659    /// `Description`, field 6.
660    pub description: Option<&'a str>,
661    /// `AudioLanguages`, field 7.
662    pub audio_languages: Option<TlvList<'a, &'a str>>,
663    /// `Ratings`, field 8.
664    pub ratings: Option<TlvList<'a, &'a str>>,
665    /// `ThumbnailUrl`, field 9.
666    pub thumbnail_url: Option<&'a str>,
667    /// `PosterArtUrl`, field 10.
668    pub poster_art_url: Option<&'a str>,
669    /// `DvbiUrl`, field 11.
670    pub dvbi_url: Option<&'a str>,
671    /// `ReleaseDate`, field 12.
672    pub release_date: Option<&'a str>,
673    /// `ParentalGuidanceText`, field 13.
674    pub parental_guidance_text: Option<&'a str>,
675    /// `RecordingFlag`, field 14.
676    pub recording_flag: Option<RecordingFlagBitmap>,
677    /// `SeriesInfo`, field 15.
678    pub series_info: Option<Nullable<SeriesInfoStruct<'a>>>,
679    /// `CategoryList`, field 16.
680    pub category_list: Option<TlvList<'a, ProgramCategoryStruct<'a>>>,
681    /// `CastList`, field 17.
682    pub cast_list: Option<TlvList<'a, ProgramCastStruct<'a>>>,
683    /// `ExternalIDList`, field 18.
684    pub external_id_list:
685        Option<TlvList<'a, crate::clusters::generated::content_launcher::AdditionalInfoStruct<'a>>>,
686}
687
688impl<'a> ToTlv for ProgramStruct<'a> {
689    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
690        w.start_structure(tag)?;
691        self.identifier.to_tlv(w, Tag::Context(0))?;
692        self.channel.to_tlv(w, Tag::Context(1))?;
693        self.start_time.to_tlv(w, Tag::Context(2))?;
694        self.end_time.to_tlv(w, Tag::Context(3))?;
695        self.title.to_tlv(w, Tag::Context(4))?;
696        if let Some(value) = &self.subtitle {
697            value.to_tlv(w, Tag::Context(5))?;
698        }
699        if let Some(value) = &self.description {
700            value.to_tlv(w, Tag::Context(6))?;
701        }
702        if let Some(value) = &self.audio_languages {
703            value.to_tlv(w, Tag::Context(7))?;
704        }
705        if let Some(value) = &self.ratings {
706            value.to_tlv(w, Tag::Context(8))?;
707        }
708        if let Some(value) = &self.thumbnail_url {
709            value.to_tlv(w, Tag::Context(9))?;
710        }
711        if let Some(value) = &self.poster_art_url {
712            value.to_tlv(w, Tag::Context(10))?;
713        }
714        if let Some(value) = &self.dvbi_url {
715            value.to_tlv(w, Tag::Context(11))?;
716        }
717        if let Some(value) = &self.release_date {
718            value.to_tlv(w, Tag::Context(12))?;
719        }
720        if let Some(value) = &self.parental_guidance_text {
721            value.to_tlv(w, Tag::Context(13))?;
722        }
723        if let Some(value) = &self.recording_flag {
724            value.to_tlv(w, Tag::Context(14))?;
725        }
726        if let Some(value) = &self.series_info {
727            value.to_tlv(w, Tag::Context(15))?;
728        }
729        if let Some(value) = &self.category_list {
730            value.to_tlv(w, Tag::Context(16))?;
731        }
732        if let Some(value) = &self.cast_list {
733            value.to_tlv(w, Tag::Context(17))?;
734        }
735        if let Some(value) = &self.external_id_list {
736            value.to_tlv(w, Tag::Context(18))?;
737        }
738        w.end_container()
739    }
740}
741
742impl<'a> FromTlv<'a> for ProgramStruct<'a> {
743    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
744        if element.value.container() != Some(ContainerKind::Structure) {
745            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
746        }
747        let mut identifier = None;
748        let mut channel = None;
749        let mut start_time = None;
750        let mut end_time = None;
751        let mut title = None;
752        let mut subtitle = None;
753        let mut description = None;
754        let mut audio_languages = None;
755        let mut ratings = None;
756        let mut thumbnail_url = None;
757        let mut poster_art_url = None;
758        let mut dvbi_url = None;
759        let mut release_date = None;
760        let mut parental_guidance_text = None;
761        let mut recording_flag = None;
762        let mut series_info = None;
763        let mut category_list = None;
764        let mut cast_list = None;
765        let mut external_id_list = None;
766        loop {
767            let Some(field) = reader.next_element()? else {
768                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
769            };
770            if field.value == Value::EndOfContainer {
771                break;
772            }
773            match field.tag.context() {
774                Some(0) => identifier = Some(<&'a str>::from_tlv(reader, &field)?),
775                Some(1) => channel = Some(<ChannelInfoStruct<'a>>::from_tlv(reader, &field)?),
776                Some(2) => start_time = Some(<u32>::from_tlv(reader, &field)?),
777                Some(3) => end_time = Some(<u32>::from_tlv(reader, &field)?),
778                Some(4) => title = Some(<&'a str>::from_tlv(reader, &field)?),
779                Some(5) => subtitle = Some(<&'a str>::from_tlv(reader, &field)?),
780                Some(6) => description = Some(<&'a str>::from_tlv(reader, &field)?),
781                Some(7) => {
782                    audio_languages = Some(<TlvList<'a, &'a str>>::from_tlv(reader, &field)?)
783                }
784                Some(8) => ratings = Some(<TlvList<'a, &'a str>>::from_tlv(reader, &field)?),
785                Some(9) => thumbnail_url = Some(<&'a str>::from_tlv(reader, &field)?),
786                Some(10) => poster_art_url = Some(<&'a str>::from_tlv(reader, &field)?),
787                Some(11) => dvbi_url = Some(<&'a str>::from_tlv(reader, &field)?),
788                Some(12) => release_date = Some(<&'a str>::from_tlv(reader, &field)?),
789                Some(13) => parental_guidance_text = Some(<&'a str>::from_tlv(reader, &field)?),
790                Some(14) => recording_flag = Some(<RecordingFlagBitmap>::from_tlv(reader, &field)?),
791                Some(15) => {
792                    series_info = Some(<Nullable<SeriesInfoStruct<'a>>>::from_tlv(reader, &field)?)
793                }
794                Some(16) => {
795                    category_list = Some(<TlvList<'a, ProgramCategoryStruct<'a>>>::from_tlv(
796                        reader, &field,
797                    )?)
798                }
799                Some(17) => {
800                    cast_list = Some(<TlvList<'a, ProgramCastStruct<'a>>>::from_tlv(
801                        reader, &field,
802                    )?)
803                }
804                Some(18) => {
805                    external_id_list = Some(<TlvList<
806                        'a,
807                        crate::clusters::generated::content_launcher::AdditionalInfoStruct<'a>,
808                    >>::from_tlv(reader, &field)?)
809                }
810                // A field this revision does not define. §7.19.2: a receiver
811                // ignores what it does not know rather than refusing the whole
812                // structure, which is what lets a newer peer talk to an older one.
813                _ => reader.skip_value(&field)?,
814            }
815        }
816        Ok(Self {
817            identifier: identifier.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
818            channel: channel.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
819            start_time: start_time.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
820            end_time: end_time.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
821            title: title.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
822            subtitle,
823            description,
824            audio_languages,
825            ratings,
826            thumbnail_url,
827            poster_art_url,
828            dvbi_url,
829            release_date,
830            parental_guidance_text,
831            recording_flag,
832            series_info,
833            category_list,
834            cast_list,
835            external_id_list,
836        })
837    }
838}
839
840/// `SeriesInfoStruct`.
841#[derive(Debug, Clone, Copy, PartialEq)]
842pub struct SeriesInfoStruct<'a> {
843    /// `Season`, field 0.
844    pub season: &'a str,
845    /// `Episode`, field 1.
846    pub episode: &'a str,
847}
848
849impl<'a> ToTlv for SeriesInfoStruct<'a> {
850    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
851        w.start_structure(tag)?;
852        self.season.to_tlv(w, Tag::Context(0))?;
853        self.episode.to_tlv(w, Tag::Context(1))?;
854        w.end_container()
855    }
856}
857
858impl<'a> FromTlv<'a> for SeriesInfoStruct<'a> {
859    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
860        if element.value.container() != Some(ContainerKind::Structure) {
861            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
862        }
863        let mut season = None;
864        let mut episode = None;
865        loop {
866            let Some(field) = reader.next_element()? else {
867                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
868            };
869            if field.value == Value::EndOfContainer {
870                break;
871            }
872            match field.tag.context() {
873                Some(0) => season = Some(<&'a str>::from_tlv(reader, &field)?),
874                Some(1) => episode = Some(<&'a str>::from_tlv(reader, &field)?),
875                // A field this revision does not define. §7.19.2: a receiver
876                // ignores what it does not know rather than refusing the whole
877                // structure, which is what lets a newer peer talk to an older one.
878                _ => reader.skip_value(&field)?,
879            }
880        }
881        Ok(Self {
882            season: season.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
883            episode: episode.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
884        })
885    }
886}
887
888/// The fields of `ChangeChannel` (command `0x00`).
889#[derive(Debug, Clone, Copy, PartialEq)]
890pub struct ChangeChannelFields<'a> {
891    /// `Match`, field 0.
892    pub match_: &'a str,
893}
894
895impl<'a> ToTlv for ChangeChannelFields<'a> {
896    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
897        w.start_structure(tag)?;
898        self.match_.to_tlv(w, Tag::Context(0))?;
899        w.end_container()
900    }
901}
902
903impl<'a> FromTlv<'a> for ChangeChannelFields<'a> {
904    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
905        if element.value.container() != Some(ContainerKind::Structure) {
906            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
907        }
908        let mut match_ = None;
909        loop {
910            let Some(field) = reader.next_element()? else {
911                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
912            };
913            if field.value == Value::EndOfContainer {
914                break;
915            }
916            match field.tag.context() {
917                Some(0) => match_ = Some(<&'a str>::from_tlv(reader, &field)?),
918                // A field this revision does not define. §7.19.2: a receiver
919                // ignores what it does not know rather than refusing the whole
920                // structure, which is what lets a newer peer talk to an older one.
921                _ => reader.skip_value(&field)?,
922            }
923        }
924        Ok(Self {
925            match_: match_.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
926        })
927    }
928}
929
930/// The fields of `ChangeChannelResponse` (command `0x01`).
931#[derive(Debug, Clone, Copy, PartialEq)]
932pub struct ChangeChannelResponseFields<'a> {
933    /// `Status`, field 0.
934    pub status: StatusEnum,
935    /// `Data`, field 1.
936    pub data: Option<&'a str>,
937}
938
939impl<'a> ToTlv for ChangeChannelResponseFields<'a> {
940    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
941        w.start_structure(tag)?;
942        self.status.to_tlv(w, Tag::Context(0))?;
943        if let Some(value) = &self.data {
944            value.to_tlv(w, Tag::Context(1))?;
945        }
946        w.end_container()
947    }
948}
949
950impl<'a> FromTlv<'a> for ChangeChannelResponseFields<'a> {
951    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
952        if element.value.container() != Some(ContainerKind::Structure) {
953            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
954        }
955        let mut status = None;
956        let mut data = None;
957        loop {
958            let Some(field) = reader.next_element()? else {
959                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
960            };
961            if field.value == Value::EndOfContainer {
962                break;
963            }
964            match field.tag.context() {
965                Some(0) => status = Some(<StatusEnum>::from_tlv(reader, &field)?),
966                Some(1) => data = Some(<&'a str>::from_tlv(reader, &field)?),
967                // A field this revision does not define. §7.19.2: a receiver
968                // ignores what it does not know rather than refusing the whole
969                // structure, which is what lets a newer peer talk to an older one.
970                _ => reader.skip_value(&field)?,
971            }
972        }
973        Ok(Self {
974            status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
975            data,
976        })
977    }
978}
979
980/// The fields of `ChangeChannelByNumber` (command `0x02`).
981#[derive(Debug, Clone, Copy, PartialEq)]
982pub struct ChangeChannelByNumberFields {
983    /// `MajorNumber`, field 0.
984    pub major_number: u16,
985    /// `MinorNumber`, field 1.
986    pub minor_number: u16,
987}
988
989impl ToTlv for ChangeChannelByNumberFields {
990    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
991        w.start_structure(tag)?;
992        self.major_number.to_tlv(w, Tag::Context(0))?;
993        self.minor_number.to_tlv(w, Tag::Context(1))?;
994        w.end_container()
995    }
996}
997
998impl<'a> FromTlv<'a> for ChangeChannelByNumberFields {
999    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1000        if element.value.container() != Some(ContainerKind::Structure) {
1001            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1002        }
1003        let mut major_number = None;
1004        let mut minor_number = None;
1005        loop {
1006            let Some(field) = reader.next_element()? else {
1007                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1008            };
1009            if field.value == Value::EndOfContainer {
1010                break;
1011            }
1012            match field.tag.context() {
1013                Some(0) => major_number = Some(<u16>::from_tlv(reader, &field)?),
1014                Some(1) => minor_number = Some(<u16>::from_tlv(reader, &field)?),
1015                // A field this revision does not define. §7.19.2: a receiver
1016                // ignores what it does not know rather than refusing the whole
1017                // structure, which is what lets a newer peer talk to an older one.
1018                _ => reader.skip_value(&field)?,
1019            }
1020        }
1021        Ok(Self {
1022            major_number: major_number.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1023            minor_number: minor_number.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1024        })
1025    }
1026}
1027
1028/// The fields of `SkipChannel` (command `0x03`).
1029#[derive(Debug, Clone, Copy, PartialEq)]
1030pub struct SkipChannelFields {
1031    /// `Count`, field 0.
1032    pub count: i16,
1033}
1034
1035impl ToTlv for SkipChannelFields {
1036    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1037        w.start_structure(tag)?;
1038        self.count.to_tlv(w, Tag::Context(0))?;
1039        w.end_container()
1040    }
1041}
1042
1043impl<'a> FromTlv<'a> for SkipChannelFields {
1044    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1045        if element.value.container() != Some(ContainerKind::Structure) {
1046            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1047        }
1048        let mut count = None;
1049        loop {
1050            let Some(field) = reader.next_element()? else {
1051                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1052            };
1053            if field.value == Value::EndOfContainer {
1054                break;
1055            }
1056            match field.tag.context() {
1057                Some(0) => count = Some(<i16>::from_tlv(reader, &field)?),
1058                // A field this revision does not define. §7.19.2: a receiver
1059                // ignores what it does not know rather than refusing the whole
1060                // structure, which is what lets a newer peer talk to an older one.
1061                _ => reader.skip_value(&field)?,
1062            }
1063        }
1064        Ok(Self {
1065            count: count.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1066        })
1067    }
1068}
1069
1070/// The fields of `GetProgramGuide` (command `0x04`).
1071#[derive(Debug, Clone, Copy, PartialEq)]
1072pub struct GetProgramGuideFields<'a> {
1073    /// `StartTime`, field 0.
1074    pub start_time: u32,
1075    /// `EndTime`, field 1.
1076    pub end_time: u32,
1077    /// `ChannelList`, field 2.
1078    pub channel_list: Option<TlvList<'a, ChannelInfoStruct<'a>>>,
1079    /// `PageToken`, field 3.
1080    pub page_token: Option<Nullable<PageTokenStruct<'a>>>,
1081    /// `RecordingFlag`, field 5.
1082    pub recording_flag: Option<Nullable<RecordingFlagBitmap>>,
1083    /// `ExternalIDList`, field 6.
1084    pub external_id_list:
1085        Option<TlvList<'a, crate::clusters::generated::content_launcher::AdditionalInfoStruct<'a>>>,
1086    /// `Data`, field 7.
1087    pub data: Option<&'a [u8]>,
1088}
1089
1090impl<'a> ToTlv for GetProgramGuideFields<'a> {
1091    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1092        w.start_structure(tag)?;
1093        self.start_time.to_tlv(w, Tag::Context(0))?;
1094        self.end_time.to_tlv(w, Tag::Context(1))?;
1095        if let Some(value) = &self.channel_list {
1096            value.to_tlv(w, Tag::Context(2))?;
1097        }
1098        if let Some(value) = &self.page_token {
1099            value.to_tlv(w, Tag::Context(3))?;
1100        }
1101        if let Some(value) = &self.recording_flag {
1102            value.to_tlv(w, Tag::Context(5))?;
1103        }
1104        if let Some(value) = &self.external_id_list {
1105            value.to_tlv(w, Tag::Context(6))?;
1106        }
1107        if let Some(value) = &self.data {
1108            value.to_tlv(w, Tag::Context(7))?;
1109        }
1110        w.end_container()
1111    }
1112}
1113
1114impl<'a> FromTlv<'a> for GetProgramGuideFields<'a> {
1115    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1116        if element.value.container() != Some(ContainerKind::Structure) {
1117            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1118        }
1119        let mut start_time = None;
1120        let mut end_time = None;
1121        let mut channel_list = None;
1122        let mut page_token = None;
1123        let mut recording_flag = None;
1124        let mut external_id_list = None;
1125        let mut data = None;
1126        loop {
1127            let Some(field) = reader.next_element()? else {
1128                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1129            };
1130            if field.value == Value::EndOfContainer {
1131                break;
1132            }
1133            match field.tag.context() {
1134                Some(0) => start_time = Some(<u32>::from_tlv(reader, &field)?),
1135                Some(1) => end_time = Some(<u32>::from_tlv(reader, &field)?),
1136                Some(2) => {
1137                    channel_list = Some(<TlvList<'a, ChannelInfoStruct<'a>>>::from_tlv(
1138                        reader, &field,
1139                    )?)
1140                }
1141                Some(3) => {
1142                    page_token = Some(<Nullable<PageTokenStruct<'a>>>::from_tlv(reader, &field)?)
1143                }
1144                Some(5) => {
1145                    recording_flag =
1146                        Some(<Nullable<RecordingFlagBitmap>>::from_tlv(reader, &field)?)
1147                }
1148                Some(6) => {
1149                    external_id_list = Some(<TlvList<
1150                        'a,
1151                        crate::clusters::generated::content_launcher::AdditionalInfoStruct<'a>,
1152                    >>::from_tlv(reader, &field)?)
1153                }
1154                Some(7) => data = Some(<&'a [u8]>::from_tlv(reader, &field)?),
1155                // A field this revision does not define. §7.19.2: a receiver
1156                // ignores what it does not know rather than refusing the whole
1157                // structure, which is what lets a newer peer talk to an older one.
1158                _ => reader.skip_value(&field)?,
1159            }
1160        }
1161        Ok(Self {
1162            start_time: start_time.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1163            end_time: end_time.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1164            channel_list,
1165            page_token,
1166            recording_flag,
1167            external_id_list,
1168            data,
1169        })
1170    }
1171}
1172
1173/// The fields of `ProgramGuideResponse` (command `0x05`).
1174#[derive(Debug, Clone, Copy, PartialEq)]
1175pub struct ProgramGuideResponseFields<'a> {
1176    /// `Paging`, field 0.
1177    pub paging: ChannelPagingStruct<'a>,
1178    /// `ProgramList`, field 1.
1179    pub program_list: TlvList<'a, ProgramStruct<'a>>,
1180}
1181
1182impl<'a> ToTlv for ProgramGuideResponseFields<'a> {
1183    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1184        w.start_structure(tag)?;
1185        self.paging.to_tlv(w, Tag::Context(0))?;
1186        self.program_list.to_tlv(w, Tag::Context(1))?;
1187        w.end_container()
1188    }
1189}
1190
1191impl<'a> FromTlv<'a> for ProgramGuideResponseFields<'a> {
1192    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1193        if element.value.container() != Some(ContainerKind::Structure) {
1194            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1195        }
1196        let mut paging = None;
1197        let mut program_list = None;
1198        loop {
1199            let Some(field) = reader.next_element()? else {
1200                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1201            };
1202            if field.value == Value::EndOfContainer {
1203                break;
1204            }
1205            match field.tag.context() {
1206                Some(0) => paging = Some(<ChannelPagingStruct<'a>>::from_tlv(reader, &field)?),
1207                Some(1) => {
1208                    program_list = Some(<TlvList<'a, ProgramStruct<'a>>>::from_tlv(reader, &field)?)
1209                }
1210                // A field this revision does not define. §7.19.2: a receiver
1211                // ignores what it does not know rather than refusing the whole
1212                // structure, which is what lets a newer peer talk to an older one.
1213                _ => reader.skip_value(&field)?,
1214            }
1215        }
1216        Ok(Self {
1217            paging: paging.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1218            program_list: program_list.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1219        })
1220    }
1221}
1222
1223/// The fields of `RecordProgram` (command `0x06`).
1224#[derive(Debug, Clone, Copy, PartialEq)]
1225pub struct RecordProgramFields<'a> {
1226    /// `ProgramIdentifier`, field 0.
1227    pub program_identifier: &'a str,
1228    /// `ShouldRecordSeries`, field 1.
1229    pub should_record_series: bool,
1230    /// `ExternalIDList`, field 2.
1231    pub external_id_list:
1232        Option<TlvList<'a, crate::clusters::generated::content_launcher::AdditionalInfoStruct<'a>>>,
1233    /// `Data`, field 3.
1234    pub data: Option<&'a [u8]>,
1235}
1236
1237impl<'a> ToTlv for RecordProgramFields<'a> {
1238    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1239        w.start_structure(tag)?;
1240        self.program_identifier.to_tlv(w, Tag::Context(0))?;
1241        self.should_record_series.to_tlv(w, Tag::Context(1))?;
1242        if let Some(value) = &self.external_id_list {
1243            value.to_tlv(w, Tag::Context(2))?;
1244        }
1245        if let Some(value) = &self.data {
1246            value.to_tlv(w, Tag::Context(3))?;
1247        }
1248        w.end_container()
1249    }
1250}
1251
1252impl<'a> FromTlv<'a> for RecordProgramFields<'a> {
1253    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1254        if element.value.container() != Some(ContainerKind::Structure) {
1255            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1256        }
1257        let mut program_identifier = None;
1258        let mut should_record_series = None;
1259        let mut external_id_list = None;
1260        let mut data = None;
1261        loop {
1262            let Some(field) = reader.next_element()? else {
1263                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1264            };
1265            if field.value == Value::EndOfContainer {
1266                break;
1267            }
1268            match field.tag.context() {
1269                Some(0) => program_identifier = Some(<&'a str>::from_tlv(reader, &field)?),
1270                Some(1) => should_record_series = Some(<bool>::from_tlv(reader, &field)?),
1271                Some(2) => {
1272                    external_id_list = Some(<TlvList<
1273                        'a,
1274                        crate::clusters::generated::content_launcher::AdditionalInfoStruct<'a>,
1275                    >>::from_tlv(reader, &field)?)
1276                }
1277                Some(3) => data = Some(<&'a [u8]>::from_tlv(reader, &field)?),
1278                // A field this revision does not define. §7.19.2: a receiver
1279                // ignores what it does not know rather than refusing the whole
1280                // structure, which is what lets a newer peer talk to an older one.
1281                _ => reader.skip_value(&field)?,
1282            }
1283        }
1284        Ok(Self {
1285            program_identifier: program_identifier
1286                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1287            should_record_series: should_record_series
1288                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1289            external_id_list,
1290            data,
1291        })
1292    }
1293}
1294
1295/// The fields of `CancelRecordProgram` (command `0x07`).
1296#[derive(Debug, Clone, Copy, PartialEq)]
1297pub struct CancelRecordProgramFields<'a> {
1298    /// `ProgramIdentifier`, field 0.
1299    pub program_identifier: &'a str,
1300    /// `ShouldRecordSeries`, field 1.
1301    pub should_record_series: bool,
1302    /// `ExternalIDList`, field 2.
1303    pub external_id_list:
1304        Option<TlvList<'a, crate::clusters::generated::content_launcher::AdditionalInfoStruct<'a>>>,
1305    /// `Data`, field 3.
1306    pub data: Option<&'a [u8]>,
1307}
1308
1309impl<'a> ToTlv for CancelRecordProgramFields<'a> {
1310    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1311        w.start_structure(tag)?;
1312        self.program_identifier.to_tlv(w, Tag::Context(0))?;
1313        self.should_record_series.to_tlv(w, Tag::Context(1))?;
1314        if let Some(value) = &self.external_id_list {
1315            value.to_tlv(w, Tag::Context(2))?;
1316        }
1317        if let Some(value) = &self.data {
1318            value.to_tlv(w, Tag::Context(3))?;
1319        }
1320        w.end_container()
1321    }
1322}
1323
1324impl<'a> FromTlv<'a> for CancelRecordProgramFields<'a> {
1325    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1326        if element.value.container() != Some(ContainerKind::Structure) {
1327            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1328        }
1329        let mut program_identifier = None;
1330        let mut should_record_series = None;
1331        let mut external_id_list = None;
1332        let mut data = None;
1333        loop {
1334            let Some(field) = reader.next_element()? else {
1335                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1336            };
1337            if field.value == Value::EndOfContainer {
1338                break;
1339            }
1340            match field.tag.context() {
1341                Some(0) => program_identifier = Some(<&'a str>::from_tlv(reader, &field)?),
1342                Some(1) => should_record_series = Some(<bool>::from_tlv(reader, &field)?),
1343                Some(2) => {
1344                    external_id_list = Some(<TlvList<
1345                        'a,
1346                        crate::clusters::generated::content_launcher::AdditionalInfoStruct<'a>,
1347                    >>::from_tlv(reader, &field)?)
1348                }
1349                Some(3) => data = Some(<&'a [u8]>::from_tlv(reader, &field)?),
1350                // A field this revision does not define. §7.19.2: a receiver
1351                // ignores what it does not know rather than refusing the whole
1352                // structure, which is what lets a newer peer talk to an older one.
1353                _ => reader.skip_value(&field)?,
1354            }
1355        }
1356        Ok(Self {
1357            program_identifier: program_identifier
1358                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1359            should_record_series: should_record_series
1360                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1361            external_id_list,
1362            data,
1363        })
1364    }
1365}
1366
1367/// Every attribute the specification defines, with its conformance.
1368pub const ATTRIBUTES: &[Attribute] = &[
1369    Attribute {
1370        id: 0x0000,
1371        name: "ChannelList",
1372        kind: "list[ChannelInfoStruct]",
1373        access: Access::read_only(Privilege::View),
1374        qualities: AttributeQualities::empty(),
1375        reporting: Reporting::OnChange,
1376        conform: Conform {
1377            clauses: &[Clause {
1378                verdict: Conformance::Mandatory,
1379                when: Condition::Feature(0),
1380            }],
1381        },
1382    },
1383    Attribute {
1384        id: 0x0001,
1385        name: "Lineup",
1386        kind: "LineupInfoStruct",
1387        access: Access::read_only(Privilege::View),
1388        qualities: AttributeQualities::NULLABLE,
1389        reporting: Reporting::OnChange,
1390        conform: Conform {
1391            clauses: &[Clause {
1392                verdict: Conformance::Mandatory,
1393                when: Condition::Feature(1),
1394            }],
1395        },
1396    },
1397    Attribute {
1398        id: 0x0002,
1399        name: "CurrentChannel",
1400        kind: "ChannelInfoStruct",
1401        access: Access::read_only(Privilege::View),
1402        qualities: AttributeQualities::NULLABLE,
1403        reporting: Reporting::OnChange,
1404        conform: Conform::OPTIONAL,
1405    },
1406];
1407
1408/// Every command, with its conformance.
1409pub const COMMANDS: &[Command] = &[
1410    Command {
1411        id: 0x00,
1412        name: "ChangeChannel",
1413        to_server: true,
1414        response: Some(0x01),
1415        access: Access::invoke(Privilege::Operate),
1416        conform: Conform {
1417            clauses: &[Clause {
1418                verdict: Conformance::Mandatory,
1419                when: Condition::Any(&[Condition::Feature(0), Condition::Feature(1)]),
1420            }],
1421        },
1422    },
1423    Command {
1424        id: 0x01,
1425        name: "ChangeChannelResponse",
1426        to_server: false,
1427        response: None,
1428        access: Access::invoke(Privilege::Operate),
1429        conform: Conform {
1430            clauses: &[Clause {
1431                verdict: Conformance::Mandatory,
1432                when: Condition::Any(&[Condition::Feature(0), Condition::Feature(1)]),
1433            }],
1434        },
1435    },
1436    Command {
1437        id: 0x02,
1438        name: "ChangeChannelByNumber",
1439        to_server: true,
1440        response: None,
1441        access: Access::invoke(Privilege::Operate),
1442        conform: Conform::MANDATORY,
1443    },
1444    Command {
1445        id: 0x03,
1446        name: "SkipChannel",
1447        to_server: true,
1448        response: None,
1449        access: Access::invoke(Privilege::Operate),
1450        conform: Conform::MANDATORY,
1451    },
1452    Command {
1453        id: 0x04,
1454        name: "GetProgramGuide",
1455        to_server: true,
1456        response: Some(0x05),
1457        access: Access::invoke(Privilege::Operate),
1458        conform: Conform {
1459            clauses: &[Clause {
1460                verdict: Conformance::Mandatory,
1461                when: Condition::Feature(2),
1462            }],
1463        },
1464    },
1465    Command {
1466        id: 0x05,
1467        name: "ProgramGuideResponse",
1468        to_server: false,
1469        response: None,
1470        access: Access::invoke(Privilege::Operate),
1471        conform: Conform {
1472            clauses: &[Clause {
1473                verdict: Conformance::Mandatory,
1474                when: Condition::Feature(2),
1475            }],
1476        },
1477    },
1478    Command {
1479        id: 0x06,
1480        name: "RecordProgram",
1481        to_server: true,
1482        response: None,
1483        access: Access::invoke(Privilege::Operate),
1484        conform: Conform {
1485            clauses: &[Clause {
1486                verdict: Conformance::Mandatory,
1487                when: Condition::All(&[Condition::Feature(3), Condition::Feature(2)]),
1488            }],
1489        },
1490    },
1491    Command {
1492        id: 0x07,
1493        name: "CancelRecordProgram",
1494        to_server: true,
1495        response: None,
1496        access: Access::invoke(Privilege::Operate),
1497        conform: Conform {
1498            clauses: &[Clause {
1499                verdict: Conformance::Mandatory,
1500                when: Condition::All(&[Condition::Feature(3), Condition::Feature(2)]),
1501            }],
1502        },
1503    },
1504];
1505
1506/// Every event, with its conformance.
1507pub const EVENTS: &[Event] = &[];
1508
1509/// The whole cluster, as the specification defines it.
1510pub const CLUSTER: Cluster = Cluster {
1511    id: ID,
1512    name: "Channel",
1513    revision: REVISION,
1514    pics: "CHANNEL",
1515    derived_from: None,
1516    features: FEATURES,
1517    attributes: ATTRIBUTES,
1518    commands: COMMANDS,
1519    events: EVENTS,
1520};