Skip to main content

matter_kit/clusters/generated/
content_launcher.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Content Launcher — cluster 0x050A.
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//! Content Launcher (cluster `0x050A`, revision 2).
10//!
11//! 5 identifiers, 5 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 = 0x050A;
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 = "CONTENTLAUNCHER";
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    /// Device supports content search (non-app specific)
42    ///
43    /// Code `CS`, bit 0.
44    pub const CONTENT_SEARCH: u32 = 1 << 0;
45    /// Device supports basic URL-based file playback
46    ///
47    /// Code `UP`, bit 1.
48    pub const URL_PLAYBACK: u32 = 1 << 1;
49    /// Enables clients to implement more advanced media seeking behavior in their user interface, such as for example a "seek bar".
50    ///
51    /// Code `AS`, bit 2.
52    pub const ADVANCED_SEEK: u32 = 1 << 2;
53    /// Device or app supports Text Tracks.
54    ///
55    /// Code `TT`, bit 3.
56    pub const TEXT_TRACKS: u32 = 1 << 3;
57    /// Device or app supports Audio Tracks.
58    ///
59    /// Code `AT`, bit 4.
60    pub const AUDIO_TRACKS: u32 = 1 << 4;
61}
62
63/// Every feature bit, with its conformance.
64pub const FEATURES: &[Feature] = &[
65    Feature {
66        bit: 0,
67        code: "CS",
68        name: "ContentSearch",
69        conform: Conform::OPTIONAL,
70    },
71    Feature {
72        bit: 1,
73        code: "UP",
74        name: "URLPlayback",
75        conform: Conform::OPTIONAL,
76    },
77    Feature {
78        bit: 2,
79        code: "AS",
80        name: "AdvancedSeek",
81        conform: Conform::OPTIONAL,
82    },
83    Feature {
84        bit: 3,
85        code: "TT",
86        name: "TextTracks",
87        conform: Conform::OPTIONAL,
88    },
89    Feature {
90        bit: 4,
91        code: "AT",
92        name: "AudioTracks",
93        conform: Conform::OPTIONAL,
94    },
95];
96
97/// The attribute ids.
98pub mod attribute {
99    use crate::im::AttributeId;
100
101    /// `AcceptHeader`.
102    pub const ACCEPT_HEADER: AttributeId = 0x00;
103    /// `SupportedStreamingProtocols`.
104    pub const SUPPORTED_STREAMING_PROTOCOLS: AttributeId = 0x01;
105}
106
107/// The command ids.
108pub mod command {
109    use crate::im::CommandId;
110
111    /// `LaunchContent`.
112    pub const LAUNCH_CONTENT: CommandId = 0x00;
113    /// `LaunchURL`.
114    pub const LAUNCH_URL: CommandId = 0x01;
115    /// `LauncherResponse`.
116    pub const LAUNCHER_RESPONSE: CommandId = 0x02;
117}
118
119/// `MetricTypeEnum`.
120#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
121#[repr(u8)]
122pub enum MetricTypeEnum {
123    /// Dimensions defined in a number of Pixels
124    Pixels = 0,
125    /// Dimensions defined as a percentage
126    Percentage = 1,
127}
128
129impl MetricTypeEnum {
130    /// Reads a wire value, or `None` for one this revision does not define.
131    #[must_use]
132    pub const fn from_value(value: u8) -> Option<Self> {
133        match value {
134            0 => Some(Self::Pixels),
135            1 => Some(Self::Percentage),
136            _ => None,
137        }
138    }
139
140    /// Its wire value.
141    #[must_use]
142    pub const fn value(self) -> u8 {
143        self as u8
144    }
145}
146
147impl ToTlv for MetricTypeEnum {
148    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
149        self.value().to_tlv(w, tag)
150    }
151}
152
153impl<'a> FromTlv<'a> for MetricTypeEnum {
154    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
155        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
156        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
157    }
158}
159
160/// `ParameterEnum`.
161#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
162#[repr(u8)]
163pub enum ParameterEnum {
164    /// Actor represents an actor credited in video media content; for example, “Gaby Hoffman”
165    Actor = 0,
166    /// Channel represents the identifying data for a television channel; for example, "PBS"
167    Channel = 1,
168    /// A character represented in video media content; for example, “Snow White”
169    Character = 2,
170    /// A director of the video media content; for example, “Spike Lee”
171    Director = 3,
172    /// An event is a reference to a type of event; examples would include sports, music, or other types of events. For example, searching for "Football games" would search for a 'game' event entity and a 'football' sport entity.
173    Event = 4,
174    /// A franchise is a video entity which can represent a number of video entities, like movies or TV shows. For example, take the fictional franchise "Intergalactic Wars" which represents a collection of movie trilogies, as well as animated and live action TV shows. This entity type was introduced to account for requests by customers such as "Find Intergalactic Wars movies", which would search for all 'Intergalactic Wars' programs of the MOVIE MediaType, rather than attempting to match to a single title.
175    Franchise = 5,
176    /// Genre represents the genre of video media content such as action, drama or comedy.
177    Genre = 6,
178    /// League represents the categorical information for a sporting league; for example, "NCAA"
179    League = 7,
180    /// Popularity indicates whether the user asks for popular content.
181    Popularity = 8,
182    /// The provider (MSP) the user wants this media to be played on; for example, "Netflix".
183    Provider = 9,
184    /// Sport represents the categorical information of a sport; for example, football
185    Sport = 10,
186    /// SportsTeam represents the categorical information of a professional sports team; for example, "University of Washington Huskies"
187    SportsTeam = 11,
188    /// The type of content requested. Supported types are "Movie", "MovieSeries", "TVSeries", "TVSeason", "TVEpisode", "Trailer", "SportsEvent", "LiveEvent", and "Video"
189    Type = 12,
190    /// Video represents the identifying data for a specific piece of video content; for example, "Manchester by the Sea".
191    Video = 13,
192    /// Season represents the specific season number within a TV series.
193    Season = 14,
194    /// Episode represents a specific episode number within a Season in a TV series.
195    Episode = 15,
196    /// Represents a search text input across many parameter types or even outside of the defined param types.
197    Any = 16,
198}
199
200impl ParameterEnum {
201    /// Reads a wire value, or `None` for one this revision does not define.
202    #[must_use]
203    pub const fn from_value(value: u8) -> Option<Self> {
204        match value {
205            0 => Some(Self::Actor),
206            1 => Some(Self::Channel),
207            2 => Some(Self::Character),
208            3 => Some(Self::Director),
209            4 => Some(Self::Event),
210            5 => Some(Self::Franchise),
211            6 => Some(Self::Genre),
212            7 => Some(Self::League),
213            8 => Some(Self::Popularity),
214            9 => Some(Self::Provider),
215            10 => Some(Self::Sport),
216            11 => Some(Self::SportsTeam),
217            12 => Some(Self::Type),
218            13 => Some(Self::Video),
219            14 => Some(Self::Season),
220            15 => Some(Self::Episode),
221            16 => Some(Self::Any),
222            _ => None,
223        }
224    }
225
226    /// Its wire value.
227    #[must_use]
228    pub const fn value(self) -> u8 {
229        self as u8
230    }
231}
232
233impl ToTlv for ParameterEnum {
234    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
235        self.value().to_tlv(w, tag)
236    }
237}
238
239impl<'a> FromTlv<'a> for ParameterEnum {
240    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
241        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
242        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
243    }
244}
245
246/// `StatusEnum`.
247#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
248#[repr(u8)]
249pub enum StatusEnum {
250    /// Command succeeded
251    Success = 0,
252    /// Requested URL could not be reached by device.
253    URLNotAvailable = 1,
254    /// Requested URL returned 401 error code.
255    AuthFailed = 2,
256    /// Requested Text Track (in PlaybackPreferences) not available
257    TextTrackNotAvailable = 3,
258    /// Requested Audio Track (in PlaybackPreferences) not available
259    AudioTrackNotAvailable = 4,
260}
261
262impl StatusEnum {
263    /// Reads a wire value, or `None` for one this revision does not define.
264    #[must_use]
265    pub const fn from_value(value: u8) -> Option<Self> {
266        match value {
267            0 => Some(Self::Success),
268            1 => Some(Self::URLNotAvailable),
269            2 => Some(Self::AuthFailed),
270            3 => Some(Self::TextTrackNotAvailable),
271            4 => Some(Self::AudioTrackNotAvailable),
272            _ => None,
273        }
274    }
275
276    /// Its wire value.
277    #[must_use]
278    pub const fn value(self) -> u8 {
279        self as u8
280    }
281}
282
283impl ToTlv for StatusEnum {
284    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
285        self.value().to_tlv(w, tag)
286    }
287}
288
289impl<'a> FromTlv<'a> for StatusEnum {
290    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
291        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
292        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
293    }
294}
295
296bitflags::bitflags! {
297    /// `SupportedProtocolsBitmap`.
298    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
299    pub struct SupportedProtocolsBitmap: u8 {
300        /// Device supports Dynamic Adaptive Streaming over HTTP (DASH)
301        const DASH = 1 << 0;
302        /// Device supports HTTP Live Streaming (HLS)
303        const HLS = 1 << 1;
304    }
305}
306
307impl ToTlv for SupportedProtocolsBitmap {
308    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
309        self.bits().to_tlv(w, tag)
310    }
311}
312
313impl<'a> FromTlv<'a> for SupportedProtocolsBitmap {
314    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
315        let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
316        Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
317    }
318}
319
320/// `AdditionalInfoStruct`.
321#[derive(Debug, Clone, Copy, PartialEq)]
322pub struct AdditionalInfoStruct<'a> {
323    /// `Name`, field 0.
324    pub name: &'a str,
325    /// `Value`, field 1.
326    pub value: &'a str,
327}
328
329impl<'a> ToTlv for AdditionalInfoStruct<'a> {
330    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
331        w.start_structure(tag)?;
332        self.name.to_tlv(w, Tag::Context(0))?;
333        self.value.to_tlv(w, Tag::Context(1))?;
334        w.end_container()
335    }
336}
337
338impl<'a> FromTlv<'a> for AdditionalInfoStruct<'a> {
339    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
340        if element.value.container() != Some(ContainerKind::Structure) {
341            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
342        }
343        let mut name = None;
344        let mut value = None;
345        loop {
346            let Some(field) = reader.next_element()? else {
347                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
348            };
349            if field.value == Value::EndOfContainer {
350                break;
351            }
352            match field.tag.context() {
353                Some(0) => name = Some(<&'a str>::from_tlv(reader, &field)?),
354                Some(1) => value = Some(<&'a str>::from_tlv(reader, &field)?),
355                // A field this revision does not define. §7.19.2: a receiver
356                // ignores what it does not know rather than refusing the whole
357                // structure, which is what lets a newer peer talk to an older one.
358                _ => reader.skip_value(&field)?,
359            }
360        }
361        Ok(Self {
362            name: name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
363            value: value.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
364        })
365    }
366}
367
368/// `BrandingInformationStruct`.
369#[derive(Debug, Clone, Copy, PartialEq)]
370pub struct BrandingInformationStruct<'a> {
371    /// `ProviderName`, field 0.
372    pub provider_name: &'a str,
373    /// `Background`, field 1.
374    pub background: Option<StyleInformationStruct<'a>>,
375    /// `Logo`, field 2.
376    pub logo: Option<StyleInformationStruct<'a>>,
377    /// `ProgressBar`, field 3.
378    pub progress_bar: Option<StyleInformationStruct<'a>>,
379    /// `Splash`, field 4.
380    pub splash: Option<StyleInformationStruct<'a>>,
381    /// `WaterMark`, field 5.
382    pub water_mark: Option<StyleInformationStruct<'a>>,
383}
384
385impl<'a> ToTlv for BrandingInformationStruct<'a> {
386    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
387        w.start_structure(tag)?;
388        self.provider_name.to_tlv(w, Tag::Context(0))?;
389        if let Some(value) = &self.background {
390            value.to_tlv(w, Tag::Context(1))?;
391        }
392        if let Some(value) = &self.logo {
393            value.to_tlv(w, Tag::Context(2))?;
394        }
395        if let Some(value) = &self.progress_bar {
396            value.to_tlv(w, Tag::Context(3))?;
397        }
398        if let Some(value) = &self.splash {
399            value.to_tlv(w, Tag::Context(4))?;
400        }
401        if let Some(value) = &self.water_mark {
402            value.to_tlv(w, Tag::Context(5))?;
403        }
404        w.end_container()
405    }
406}
407
408impl<'a> FromTlv<'a> for BrandingInformationStruct<'a> {
409    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
410        if element.value.container() != Some(ContainerKind::Structure) {
411            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
412        }
413        let mut provider_name = None;
414        let mut background = None;
415        let mut logo = None;
416        let mut progress_bar = None;
417        let mut splash = None;
418        let mut water_mark = None;
419        loop {
420            let Some(field) = reader.next_element()? else {
421                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
422            };
423            if field.value == Value::EndOfContainer {
424                break;
425            }
426            match field.tag.context() {
427                Some(0) => provider_name = Some(<&'a str>::from_tlv(reader, &field)?),
428                Some(1) => {
429                    background = Some(<StyleInformationStruct<'a>>::from_tlv(reader, &field)?)
430                }
431                Some(2) => logo = Some(<StyleInformationStruct<'a>>::from_tlv(reader, &field)?),
432                Some(3) => {
433                    progress_bar = Some(<StyleInformationStruct<'a>>::from_tlv(reader, &field)?)
434                }
435                Some(4) => splash = Some(<StyleInformationStruct<'a>>::from_tlv(reader, &field)?),
436                Some(5) => {
437                    water_mark = Some(<StyleInformationStruct<'a>>::from_tlv(reader, &field)?)
438                }
439                // A field this revision does not define. §7.19.2: a receiver
440                // ignores what it does not know rather than refusing the whole
441                // structure, which is what lets a newer peer talk to an older one.
442                _ => reader.skip_value(&field)?,
443            }
444        }
445        Ok(Self {
446            provider_name: provider_name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
447            background,
448            logo,
449            progress_bar,
450            splash,
451            water_mark,
452        })
453    }
454}
455
456/// `ContentSearchStruct`.
457#[derive(Debug, Clone, Copy, PartialEq)]
458pub struct ContentSearchStruct<'a> {
459    /// `ParameterList`, field 0.
460    pub parameter_list: TlvList<'a, ParameterStruct<'a>>,
461}
462
463impl<'a> ToTlv for ContentSearchStruct<'a> {
464    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
465        w.start_structure(tag)?;
466        self.parameter_list.to_tlv(w, Tag::Context(0))?;
467        w.end_container()
468    }
469}
470
471impl<'a> FromTlv<'a> for ContentSearchStruct<'a> {
472    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
473        if element.value.container() != Some(ContainerKind::Structure) {
474            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
475        }
476        let mut parameter_list = None;
477        loop {
478            let Some(field) = reader.next_element()? else {
479                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
480            };
481            if field.value == Value::EndOfContainer {
482                break;
483            }
484            match field.tag.context() {
485                Some(0) => {
486                    parameter_list = Some(<TlvList<'a, ParameterStruct<'a>>>::from_tlv(
487                        reader, &field,
488                    )?)
489                }
490                // A field this revision does not define. §7.19.2: a receiver
491                // ignores what it does not know rather than refusing the whole
492                // structure, which is what lets a newer peer talk to an older one.
493                _ => reader.skip_value(&field)?,
494            }
495        }
496        Ok(Self {
497            parameter_list: parameter_list
498                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
499        })
500    }
501}
502
503/// `DimensionStruct`.
504#[derive(Debug, Clone, Copy, PartialEq)]
505pub struct DimensionStruct {
506    /// `Width`, field 0.
507    pub width: f64,
508    /// `Height`, field 1.
509    pub height: f64,
510    /// `Metric`, field 2.
511    pub metric: MetricTypeEnum,
512}
513
514impl ToTlv for DimensionStruct {
515    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
516        w.start_structure(tag)?;
517        self.width.to_tlv(w, Tag::Context(0))?;
518        self.height.to_tlv(w, Tag::Context(1))?;
519        self.metric.to_tlv(w, Tag::Context(2))?;
520        w.end_container()
521    }
522}
523
524impl<'a> FromTlv<'a> for DimensionStruct {
525    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
526        if element.value.container() != Some(ContainerKind::Structure) {
527            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
528        }
529        let mut width = None;
530        let mut height = None;
531        let mut metric = None;
532        loop {
533            let Some(field) = reader.next_element()? else {
534                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
535            };
536            if field.value == Value::EndOfContainer {
537                break;
538            }
539            match field.tag.context() {
540                Some(0) => width = Some(<f64>::from_tlv(reader, &field)?),
541                Some(1) => height = Some(<f64>::from_tlv(reader, &field)?),
542                Some(2) => metric = Some(<MetricTypeEnum>::from_tlv(reader, &field)?),
543                // A field this revision does not define. §7.19.2: a receiver
544                // ignores what it does not know rather than refusing the whole
545                // structure, which is what lets a newer peer talk to an older one.
546                _ => reader.skip_value(&field)?,
547            }
548        }
549        Ok(Self {
550            width: width.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
551            height: height.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
552            metric: metric.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
553        })
554    }
555}
556
557/// `ParameterStruct`.
558#[derive(Debug, Clone, Copy, PartialEq)]
559pub struct ParameterStruct<'a> {
560    /// `Type`, field 0.
561    pub type_: ParameterEnum,
562    /// `Value`, field 1.
563    pub value: &'a str,
564    /// `ExternalIDList`, field 2.
565    pub external_id_list: Option<TlvList<'a, AdditionalInfoStruct<'a>>>,
566}
567
568impl<'a> ToTlv for ParameterStruct<'a> {
569    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
570        w.start_structure(tag)?;
571        self.type_.to_tlv(w, Tag::Context(0))?;
572        self.value.to_tlv(w, Tag::Context(1))?;
573        if let Some(value) = &self.external_id_list {
574            value.to_tlv(w, Tag::Context(2))?;
575        }
576        w.end_container()
577    }
578}
579
580impl<'a> FromTlv<'a> for ParameterStruct<'a> {
581    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
582        if element.value.container() != Some(ContainerKind::Structure) {
583            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
584        }
585        let mut type_ = None;
586        let mut value = None;
587        let mut external_id_list = None;
588        loop {
589            let Some(field) = reader.next_element()? else {
590                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
591            };
592            if field.value == Value::EndOfContainer {
593                break;
594            }
595            match field.tag.context() {
596                Some(0) => type_ = Some(<ParameterEnum>::from_tlv(reader, &field)?),
597                Some(1) => value = Some(<&'a str>::from_tlv(reader, &field)?),
598                Some(2) => {
599                    external_id_list = Some(<TlvList<'a, AdditionalInfoStruct<'a>>>::from_tlv(
600                        reader, &field,
601                    )?)
602                }
603                // A field this revision does not define. §7.19.2: a receiver
604                // ignores what it does not know rather than refusing the whole
605                // structure, which is what lets a newer peer talk to an older one.
606                _ => reader.skip_value(&field)?,
607            }
608        }
609        Ok(Self {
610            type_: type_.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
611            value: value.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
612            external_id_list,
613        })
614    }
615}
616
617/// `PlaybackPreferencesStruct`.
618#[derive(Debug, Clone, Copy, PartialEq)]
619pub struct PlaybackPreferencesStruct<'a> {
620    /// `PlaybackPosition`, field 0.
621    pub playback_position: Option<Nullable<u64>>,
622    /// `TextTrack`, field 1.
623    pub text_track: Option<Nullable<TrackPreferenceStruct<'a>>>,
624    /// `AudioTracks`, field 2.
625    pub audio_tracks: Option<Nullable<TlvList<'a, TrackPreferenceStruct<'a>>>>,
626}
627
628impl<'a> ToTlv for PlaybackPreferencesStruct<'a> {
629    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
630        w.start_structure(tag)?;
631        if let Some(value) = &self.playback_position {
632            value.to_tlv(w, Tag::Context(0))?;
633        }
634        if let Some(value) = &self.text_track {
635            value.to_tlv(w, Tag::Context(1))?;
636        }
637        if let Some(value) = &self.audio_tracks {
638            value.to_tlv(w, Tag::Context(2))?;
639        }
640        w.end_container()
641    }
642}
643
644impl<'a> FromTlv<'a> for PlaybackPreferencesStruct<'a> {
645    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
646        if element.value.container() != Some(ContainerKind::Structure) {
647            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
648        }
649        let mut playback_position = None;
650        let mut text_track = None;
651        let mut audio_tracks = None;
652        loop {
653            let Some(field) = reader.next_element()? else {
654                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
655            };
656            if field.value == Value::EndOfContainer {
657                break;
658            }
659            match field.tag.context() {
660                Some(0) => playback_position = Some(<Nullable<u64>>::from_tlv(reader, &field)?),
661                Some(1) => {
662                    text_track = Some(<Nullable<TrackPreferenceStruct<'a>>>::from_tlv(
663                        reader, &field,
664                    )?)
665                }
666                Some(2) => {
667                    audio_tracks = Some(
668                        <Nullable<TlvList<'a, TrackPreferenceStruct<'a>>>>::from_tlv(
669                            reader, &field,
670                        )?,
671                    )
672                }
673                // A field this revision does not define. §7.19.2: a receiver
674                // ignores what it does not know rather than refusing the whole
675                // structure, which is what lets a newer peer talk to an older one.
676                _ => reader.skip_value(&field)?,
677            }
678        }
679        Ok(Self {
680            playback_position,
681            text_track,
682            audio_tracks,
683        })
684    }
685}
686
687/// `StyleInformationStruct`.
688#[derive(Debug, Clone, Copy, PartialEq)]
689pub struct StyleInformationStruct<'a> {
690    /// `ImageURL`, field 0.
691    pub image_url: Option<&'a str>,
692    /// `Color`, field 1.
693    pub color: Option<&'a str>,
694    /// `Size`, field 2.
695    pub size: Option<DimensionStruct>,
696}
697
698impl<'a> ToTlv for StyleInformationStruct<'a> {
699    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
700        w.start_structure(tag)?;
701        if let Some(value) = &self.image_url {
702            value.to_tlv(w, Tag::Context(0))?;
703        }
704        if let Some(value) = &self.color {
705            value.to_tlv(w, Tag::Context(1))?;
706        }
707        if let Some(value) = &self.size {
708            value.to_tlv(w, Tag::Context(2))?;
709        }
710        w.end_container()
711    }
712}
713
714impl<'a> FromTlv<'a> for StyleInformationStruct<'a> {
715    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
716        if element.value.container() != Some(ContainerKind::Structure) {
717            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
718        }
719        let mut image_url = None;
720        let mut color = None;
721        let mut size = None;
722        loop {
723            let Some(field) = reader.next_element()? else {
724                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
725            };
726            if field.value == Value::EndOfContainer {
727                break;
728            }
729            match field.tag.context() {
730                Some(0) => image_url = Some(<&'a str>::from_tlv(reader, &field)?),
731                Some(1) => color = Some(<&'a str>::from_tlv(reader, &field)?),
732                Some(2) => size = Some(<DimensionStruct>::from_tlv(reader, &field)?),
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            image_url,
741            color,
742            size,
743        })
744    }
745}
746
747/// `TrackPreferenceStruct`.
748#[derive(Debug, Clone, Copy, PartialEq)]
749pub struct TrackPreferenceStruct<'a> {
750    /// `LanguageCode`, field 0.
751    pub language_code: &'a str,
752    /// `Characteristics`, field 1.
753    pub characteristics: Option<
754        Nullable<TlvList<'a, crate::clusters::generated::media_playback::CharacteristicEnum>>,
755    >,
756    /// `AudioOutputIndex`, field 2.
757    pub audio_output_index: Option<Nullable<u8>>,
758}
759
760impl<'a> ToTlv for TrackPreferenceStruct<'a> {
761    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
762        w.start_structure(tag)?;
763        self.language_code.to_tlv(w, Tag::Context(0))?;
764        if let Some(value) = &self.characteristics {
765            value.to_tlv(w, Tag::Context(1))?;
766        }
767        if let Some(value) = &self.audio_output_index {
768            value.to_tlv(w, Tag::Context(2))?;
769        }
770        w.end_container()
771    }
772}
773
774impl<'a> FromTlv<'a> for TrackPreferenceStruct<'a> {
775    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
776        if element.value.container() != Some(ContainerKind::Structure) {
777            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
778        }
779        let mut language_code = None;
780        let mut characteristics = None;
781        let mut audio_output_index = 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) => language_code = Some(<&'a str>::from_tlv(reader, &field)?),
791                Some(1) => {
792                    characteristics = Some(<Nullable<
793                        TlvList<'a, crate::clusters::generated::media_playback::CharacteristicEnum>,
794                    >>::from_tlv(reader, &field)?)
795                }
796                Some(2) => audio_output_index = Some(<Nullable<u8>>::from_tlv(reader, &field)?),
797                // A field this revision does not define. §7.19.2: a receiver
798                // ignores what it does not know rather than refusing the whole
799                // structure, which is what lets a newer peer talk to an older one.
800                _ => reader.skip_value(&field)?,
801            }
802        }
803        Ok(Self {
804            language_code: language_code.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
805            characteristics,
806            audio_output_index,
807        })
808    }
809}
810
811/// The fields of `LaunchContent` (command `0x00`).
812#[derive(Debug, Clone, Copy, PartialEq)]
813pub struct LaunchContentFields<'a> {
814    /// `Search`, field 0.
815    pub search: ContentSearchStruct<'a>,
816    /// `AutoPlay`, field 1.
817    pub auto_play: bool,
818    /// `Data`, field 2.
819    pub data: Option<&'a str>,
820    /// `PlaybackPreferences`, field 3.
821    pub playback_preferences: Option<PlaybackPreferencesStruct<'a>>,
822    /// `UseCurrentContext`, field 4.
823    pub use_current_context: Option<bool>,
824}
825
826impl<'a> ToTlv for LaunchContentFields<'a> {
827    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
828        w.start_structure(tag)?;
829        self.search.to_tlv(w, Tag::Context(0))?;
830        self.auto_play.to_tlv(w, Tag::Context(1))?;
831        if let Some(value) = &self.data {
832            value.to_tlv(w, Tag::Context(2))?;
833        }
834        if let Some(value) = &self.playback_preferences {
835            value.to_tlv(w, Tag::Context(3))?;
836        }
837        if let Some(value) = &self.use_current_context {
838            value.to_tlv(w, Tag::Context(4))?;
839        }
840        w.end_container()
841    }
842}
843
844impl<'a> FromTlv<'a> for LaunchContentFields<'a> {
845    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
846        if element.value.container() != Some(ContainerKind::Structure) {
847            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
848        }
849        let mut search = None;
850        let mut auto_play = None;
851        let mut data = None;
852        let mut playback_preferences = None;
853        let mut use_current_context = None;
854        loop {
855            let Some(field) = reader.next_element()? else {
856                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
857            };
858            if field.value == Value::EndOfContainer {
859                break;
860            }
861            match field.tag.context() {
862                Some(0) => search = Some(<ContentSearchStruct<'a>>::from_tlv(reader, &field)?),
863                Some(1) => auto_play = Some(<bool>::from_tlv(reader, &field)?),
864                Some(2) => data = Some(<&'a str>::from_tlv(reader, &field)?),
865                Some(3) => {
866                    playback_preferences =
867                        Some(<PlaybackPreferencesStruct<'a>>::from_tlv(reader, &field)?)
868                }
869                Some(4) => use_current_context = Some(<bool>::from_tlv(reader, &field)?),
870                // A field this revision does not define. §7.19.2: a receiver
871                // ignores what it does not know rather than refusing the whole
872                // structure, which is what lets a newer peer talk to an older one.
873                _ => reader.skip_value(&field)?,
874            }
875        }
876        Ok(Self {
877            search: search.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
878            auto_play: auto_play.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
879            data,
880            playback_preferences,
881            use_current_context,
882        })
883    }
884}
885
886/// The fields of `LaunchURL` (command `0x01`).
887#[derive(Debug, Clone, Copy, PartialEq)]
888pub struct LaunchURLFields<'a> {
889    /// `ContentURL`, field 0.
890    pub content_url: &'a str,
891    /// `DisplayString`, field 1.
892    pub display_string: Option<&'a str>,
893    /// `BrandingInformation`, field 2.
894    pub branding_information: Option<BrandingInformationStruct<'a>>,
895    /// `PlaybackPreferences`, field 3.
896    pub playback_preferences: Option<PlaybackPreferencesStruct<'a>>,
897}
898
899impl<'a> ToTlv for LaunchURLFields<'a> {
900    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
901        w.start_structure(tag)?;
902        self.content_url.to_tlv(w, Tag::Context(0))?;
903        if let Some(value) = &self.display_string {
904            value.to_tlv(w, Tag::Context(1))?;
905        }
906        if let Some(value) = &self.branding_information {
907            value.to_tlv(w, Tag::Context(2))?;
908        }
909        if let Some(value) = &self.playback_preferences {
910            value.to_tlv(w, Tag::Context(3))?;
911        }
912        w.end_container()
913    }
914}
915
916impl<'a> FromTlv<'a> for LaunchURLFields<'a> {
917    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
918        if element.value.container() != Some(ContainerKind::Structure) {
919            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
920        }
921        let mut content_url = None;
922        let mut display_string = None;
923        let mut branding_information = None;
924        let mut playback_preferences = None;
925        loop {
926            let Some(field) = reader.next_element()? else {
927                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
928            };
929            if field.value == Value::EndOfContainer {
930                break;
931            }
932            match field.tag.context() {
933                Some(0) => content_url = Some(<&'a str>::from_tlv(reader, &field)?),
934                Some(1) => display_string = Some(<&'a str>::from_tlv(reader, &field)?),
935                Some(2) => {
936                    branding_information =
937                        Some(<BrandingInformationStruct<'a>>::from_tlv(reader, &field)?)
938                }
939                Some(3) => {
940                    playback_preferences =
941                        Some(<PlaybackPreferencesStruct<'a>>::from_tlv(reader, &field)?)
942                }
943                // A field this revision does not define. §7.19.2: a receiver
944                // ignores what it does not know rather than refusing the whole
945                // structure, which is what lets a newer peer talk to an older one.
946                _ => reader.skip_value(&field)?,
947            }
948        }
949        Ok(Self {
950            content_url: content_url.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
951            display_string,
952            branding_information,
953            playback_preferences,
954        })
955    }
956}
957
958/// The fields of `LauncherResponse` (command `0x02`).
959#[derive(Debug, Clone, Copy, PartialEq)]
960pub struct LauncherResponseFields<'a> {
961    /// `Status`, field 0.
962    pub status: StatusEnum,
963    /// `Data`, field 1.
964    pub data: Option<&'a str>,
965}
966
967impl<'a> ToTlv for LauncherResponseFields<'a> {
968    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
969        w.start_structure(tag)?;
970        self.status.to_tlv(w, Tag::Context(0))?;
971        if let Some(value) = &self.data {
972            value.to_tlv(w, Tag::Context(1))?;
973        }
974        w.end_container()
975    }
976}
977
978impl<'a> FromTlv<'a> for LauncherResponseFields<'a> {
979    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
980        if element.value.container() != Some(ContainerKind::Structure) {
981            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
982        }
983        let mut status = None;
984        let mut data = None;
985        loop {
986            let Some(field) = reader.next_element()? else {
987                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
988            };
989            if field.value == Value::EndOfContainer {
990                break;
991            }
992            match field.tag.context() {
993                Some(0) => status = Some(<StatusEnum>::from_tlv(reader, &field)?),
994                Some(1) => data = Some(<&'a str>::from_tlv(reader, &field)?),
995                // A field this revision does not define. §7.19.2: a receiver
996                // ignores what it does not know rather than refusing the whole
997                // structure, which is what lets a newer peer talk to an older one.
998                _ => reader.skip_value(&field)?,
999            }
1000        }
1001        Ok(Self {
1002            status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1003            data,
1004        })
1005    }
1006}
1007
1008/// Every attribute the specification defines, with its conformance.
1009pub const ATTRIBUTES: &[Attribute] = &[
1010    Attribute {
1011        id: 0x0000,
1012        name: "AcceptHeader",
1013        kind: "list[string]",
1014        access: Access::read_only(Privilege::View),
1015        qualities: AttributeQualities::NON_VOLATILE,
1016        reporting: Reporting::OnChange,
1017        conform: Conform {
1018            clauses: &[Clause {
1019                verdict: Conformance::Mandatory,
1020                when: Condition::Feature(1),
1021            }],
1022        },
1023    },
1024    Attribute {
1025        id: 0x0001,
1026        name: "SupportedStreamingProtocols",
1027        kind: "SupportedProtocolsBitmap",
1028        access: Access::read_only(Privilege::View),
1029        qualities: AttributeQualities::NON_VOLATILE,
1030        reporting: Reporting::OnChange,
1031        conform: Conform {
1032            clauses: &[Clause {
1033                verdict: Conformance::Mandatory,
1034                when: Condition::Feature(1),
1035            }],
1036        },
1037    },
1038];
1039
1040/// Every command, with its conformance.
1041pub const COMMANDS: &[Command] = &[
1042    Command {
1043        id: 0x00,
1044        name: "LaunchContent",
1045        to_server: true,
1046        response: Some(0x02),
1047        access: Access::invoke(Privilege::Operate),
1048        conform: Conform {
1049            clauses: &[Clause {
1050                verdict: Conformance::Mandatory,
1051                when: Condition::Feature(0),
1052            }],
1053        },
1054    },
1055    Command {
1056        id: 0x01,
1057        name: "LaunchURL",
1058        to_server: true,
1059        response: Some(0x02),
1060        access: Access::invoke(Privilege::Operate),
1061        conform: Conform {
1062            clauses: &[Clause {
1063                verdict: Conformance::Mandatory,
1064                when: Condition::Feature(1),
1065            }],
1066        },
1067    },
1068    Command {
1069        id: 0x02,
1070        name: "LauncherResponse",
1071        to_server: false,
1072        response: None,
1073        access: Access::invoke(Privilege::Operate),
1074        conform: Conform {
1075            clauses: &[Clause {
1076                verdict: Conformance::Mandatory,
1077                when: Condition::Any(&[Condition::Feature(0), Condition::Feature(1)]),
1078            }],
1079        },
1080    },
1081];
1082
1083/// Every event, with its conformance.
1084pub const EVENTS: &[Event] = &[];
1085
1086/// The whole cluster, as the specification defines it.
1087pub const CLUSTER: Cluster = Cluster {
1088    id: ID,
1089    name: "Content Launcher",
1090    revision: REVISION,
1091    pics: "CONTENTLAUNCHER",
1092    derived_from: None,
1093    features: FEATURES,
1094    attributes: ATTRIBUTES,
1095    commands: COMMANDS,
1096    events: EVENTS,
1097};