// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
//
// Content Launcher — cluster 0x050A.
//
// Regenerate with `cargo xtask clusters --dm <checkout>/data_model/1.6`; `cargo xtask check`
// is the CI gate that keeps this file honest. The XML itself is not vendored here — it
// carries the CSA's own copyright notice and is not redistributable.
//! Content Launcher (cluster `0x050A`, revision 2).
//!
//! 5 identifiers, 5 feature bits, and the specification's own conformance for
//! every element. `CLUSTER` is the whole table.
#![allow(unused_imports)]
use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
use crate::dm::meta::{EventPriority, Reporting};
use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
use crate::error::Result;
use crate::im::{AttributeId, ClusterId, CommandId, EventId};
use crate::tlv::{
ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
};
/// The cluster id.
pub const ID: ClusterId = 0x050A;
/// The highest revision the specification's history defines — what `ClusterRevision`
/// must report (Core §7.13.1).
pub const REVISION: u16 = 2;
/// The PICS code, which a certification declaration names the cluster by.
pub const PICS: &str = "CONTENTLAUNCHER";
/// The `FeatureMap` bits (Core §7.13.2).
///
/// A feature has conformance of its own: a device may not claim one the
/// specification forbids it alongside another.
pub mod feature {
/// Device supports content search (non-app specific)
///
/// Code `CS`, bit 0.
pub const CONTENT_SEARCH: u32 = 1 << 0;
/// Device supports basic URL-based file playback
///
/// Code `UP`, bit 1.
pub const URL_PLAYBACK: u32 = 1 << 1;
/// Enables clients to implement more advanced media seeking behavior in their user interface, such as for example a "seek bar".
///
/// Code `AS`, bit 2.
pub const ADVANCED_SEEK: u32 = 1 << 2;
/// Device or app supports Text Tracks.
///
/// Code `TT`, bit 3.
pub const TEXT_TRACKS: u32 = 1 << 3;
/// Device or app supports Audio Tracks.
///
/// Code `AT`, bit 4.
pub const AUDIO_TRACKS: u32 = 1 << 4;
}
/// Every feature bit, with its conformance.
pub const FEATURES: &[Feature] = &[
Feature {
bit: 0,
code: "CS",
name: "ContentSearch",
conform: Conform::OPTIONAL,
},
Feature {
bit: 1,
code: "UP",
name: "URLPlayback",
conform: Conform::OPTIONAL,
},
Feature {
bit: 2,
code: "AS",
name: "AdvancedSeek",
conform: Conform::OPTIONAL,
},
Feature {
bit: 3,
code: "TT",
name: "TextTracks",
conform: Conform::OPTIONAL,
},
Feature {
bit: 4,
code: "AT",
name: "AudioTracks",
conform: Conform::OPTIONAL,
},
];
/// The attribute ids.
pub mod attribute {
use crate::im::AttributeId;
/// `AcceptHeader`.
pub const ACCEPT_HEADER: AttributeId = 0x00;
/// `SupportedStreamingProtocols`.
pub const SUPPORTED_STREAMING_PROTOCOLS: AttributeId = 0x01;
}
/// The command ids.
pub mod command {
use crate::im::CommandId;
/// `LaunchContent`.
pub const LAUNCH_CONTENT: CommandId = 0x00;
/// `LaunchURL`.
pub const LAUNCH_URL: CommandId = 0x01;
/// `LauncherResponse`.
pub const LAUNCHER_RESPONSE: CommandId = 0x02;
}
/// `MetricTypeEnum`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum MetricTypeEnum {
/// Dimensions defined in a number of Pixels
Pixels = 0,
/// Dimensions defined as a percentage
Percentage = 1,
}
impl MetricTypeEnum {
/// Reads a wire value, or `None` for one this revision does not define.
#[must_use]
pub const fn from_value(value: u8) -> Option<Self> {
match value {
0 => Some(Self::Pixels),
1 => Some(Self::Percentage),
_ => None,
}
}
/// Its wire value.
#[must_use]
pub const fn value(self) -> u8 {
self as u8
}
}
impl ToTlv for MetricTypeEnum {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.value().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for MetricTypeEnum {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
}
}
/// `ParameterEnum`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum ParameterEnum {
/// Actor represents an actor credited in video media content; for example, “Gaby Hoffman”
Actor = 0,
/// Channel represents the identifying data for a television channel; for example, "PBS"
Channel = 1,
/// A character represented in video media content; for example, “Snow White”
Character = 2,
/// A director of the video media content; for example, “Spike Lee”
Director = 3,
/// 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.
Event = 4,
/// 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.
Franchise = 5,
/// Genre represents the genre of video media content such as action, drama or comedy.
Genre = 6,
/// League represents the categorical information for a sporting league; for example, "NCAA"
League = 7,
/// Popularity indicates whether the user asks for popular content.
Popularity = 8,
/// The provider (MSP) the user wants this media to be played on; for example, "Netflix".
Provider = 9,
/// Sport represents the categorical information of a sport; for example, football
Sport = 10,
/// SportsTeam represents the categorical information of a professional sports team; for example, "University of Washington Huskies"
SportsTeam = 11,
/// The type of content requested. Supported types are "Movie", "MovieSeries", "TVSeries", "TVSeason", "TVEpisode", "Trailer", "SportsEvent", "LiveEvent", and "Video"
Type = 12,
/// Video represents the identifying data for a specific piece of video content; for example, "Manchester by the Sea".
Video = 13,
/// Season represents the specific season number within a TV series.
Season = 14,
/// Episode represents a specific episode number within a Season in a TV series.
Episode = 15,
/// Represents a search text input across many parameter types or even outside of the defined param types.
Any = 16,
}
impl ParameterEnum {
/// Reads a wire value, or `None` for one this revision does not define.
#[must_use]
pub const fn from_value(value: u8) -> Option<Self> {
match value {
0 => Some(Self::Actor),
1 => Some(Self::Channel),
2 => Some(Self::Character),
3 => Some(Self::Director),
4 => Some(Self::Event),
5 => Some(Self::Franchise),
6 => Some(Self::Genre),
7 => Some(Self::League),
8 => Some(Self::Popularity),
9 => Some(Self::Provider),
10 => Some(Self::Sport),
11 => Some(Self::SportsTeam),
12 => Some(Self::Type),
13 => Some(Self::Video),
14 => Some(Self::Season),
15 => Some(Self::Episode),
16 => Some(Self::Any),
_ => None,
}
}
/// Its wire value.
#[must_use]
pub const fn value(self) -> u8 {
self as u8
}
}
impl ToTlv for ParameterEnum {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.value().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for ParameterEnum {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
}
}
/// `StatusEnum`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum StatusEnum {
/// Command succeeded
Success = 0,
/// Requested URL could not be reached by device.
URLNotAvailable = 1,
/// Requested URL returned 401 error code.
AuthFailed = 2,
/// Requested Text Track (in PlaybackPreferences) not available
TextTrackNotAvailable = 3,
/// Requested Audio Track (in PlaybackPreferences) not available
AudioTrackNotAvailable = 4,
}
impl StatusEnum {
/// Reads a wire value, or `None` for one this revision does not define.
#[must_use]
pub const fn from_value(value: u8) -> Option<Self> {
match value {
0 => Some(Self::Success),
1 => Some(Self::URLNotAvailable),
2 => Some(Self::AuthFailed),
3 => Some(Self::TextTrackNotAvailable),
4 => Some(Self::AudioTrackNotAvailable),
_ => None,
}
}
/// Its wire value.
#[must_use]
pub const fn value(self) -> u8 {
self as u8
}
}
impl ToTlv for StatusEnum {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.value().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for StatusEnum {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
}
}
bitflags::bitflags! {
/// `SupportedProtocolsBitmap`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct SupportedProtocolsBitmap: u8 {
/// Device supports Dynamic Adaptive Streaming over HTTP (DASH)
const DASH = 1 << 0;
/// Device supports HTTP Live Streaming (HLS)
const HLS = 1 << 1;
}
}
impl ToTlv for SupportedProtocolsBitmap {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.bits().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for SupportedProtocolsBitmap {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
}
}
/// `AdditionalInfoStruct`.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct AdditionalInfoStruct<'a> {
/// `Name`, field 0.
pub name: &'a str,
/// `Value`, field 1.
pub value: &'a str,
}
impl<'a> ToTlv for AdditionalInfoStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.name.to_tlv(w, Tag::Context(0))?;
self.value.to_tlv(w, Tag::Context(1))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for AdditionalInfoStruct<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut name = None;
let mut value = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => name = Some(<&'a str>::from_tlv(reader, &field)?),
Some(1) => value = Some(<&'a str>::from_tlv(reader, &field)?),
// A field this revision does not define. §7.19.2: a receiver
// ignores what it does not know rather than refusing the whole
// structure, which is what lets a newer peer talk to an older one.
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
name: name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
value: value.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
/// `BrandingInformationStruct`.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct BrandingInformationStruct<'a> {
/// `ProviderName`, field 0.
pub provider_name: &'a str,
/// `Background`, field 1.
pub background: Option<StyleInformationStruct<'a>>,
/// `Logo`, field 2.
pub logo: Option<StyleInformationStruct<'a>>,
/// `ProgressBar`, field 3.
pub progress_bar: Option<StyleInformationStruct<'a>>,
/// `Splash`, field 4.
pub splash: Option<StyleInformationStruct<'a>>,
/// `WaterMark`, field 5.
pub water_mark: Option<StyleInformationStruct<'a>>,
}
impl<'a> ToTlv for BrandingInformationStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.provider_name.to_tlv(w, Tag::Context(0))?;
if let Some(value) = &self.background {
value.to_tlv(w, Tag::Context(1))?;
}
if let Some(value) = &self.logo {
value.to_tlv(w, Tag::Context(2))?;
}
if let Some(value) = &self.progress_bar {
value.to_tlv(w, Tag::Context(3))?;
}
if let Some(value) = &self.splash {
value.to_tlv(w, Tag::Context(4))?;
}
if let Some(value) = &self.water_mark {
value.to_tlv(w, Tag::Context(5))?;
}
w.end_container()
}
}
impl<'a> FromTlv<'a> for BrandingInformationStruct<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut provider_name = None;
let mut background = None;
let mut logo = None;
let mut progress_bar = None;
let mut splash = None;
let mut water_mark = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => provider_name = Some(<&'a str>::from_tlv(reader, &field)?),
Some(1) => {
background = Some(<StyleInformationStruct<'a>>::from_tlv(reader, &field)?)
}
Some(2) => logo = Some(<StyleInformationStruct<'a>>::from_tlv(reader, &field)?),
Some(3) => {
progress_bar = Some(<StyleInformationStruct<'a>>::from_tlv(reader, &field)?)
}
Some(4) => splash = Some(<StyleInformationStruct<'a>>::from_tlv(reader, &field)?),
Some(5) => {
water_mark = Some(<StyleInformationStruct<'a>>::from_tlv(reader, &field)?)
}
// A field this revision does not define. §7.19.2: a receiver
// ignores what it does not know rather than refusing the whole
// structure, which is what lets a newer peer talk to an older one.
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
provider_name: provider_name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
background,
logo,
progress_bar,
splash,
water_mark,
})
}
}
/// `ContentSearchStruct`.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ContentSearchStruct<'a> {
/// `ParameterList`, field 0.
pub parameter_list: TlvList<'a, ParameterStruct<'a>>,
}
impl<'a> ToTlv for ContentSearchStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.parameter_list.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for ContentSearchStruct<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut parameter_list = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => {
parameter_list = Some(<TlvList<'a, ParameterStruct<'a>>>::from_tlv(
reader, &field,
)?)
}
// A field this revision does not define. §7.19.2: a receiver
// ignores what it does not know rather than refusing the whole
// structure, which is what lets a newer peer talk to an older one.
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
parameter_list: parameter_list
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
/// `DimensionStruct`.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct DimensionStruct {
/// `Width`, field 0.
pub width: f64,
/// `Height`, field 1.
pub height: f64,
/// `Metric`, field 2.
pub metric: MetricTypeEnum,
}
impl ToTlv for DimensionStruct {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.width.to_tlv(w, Tag::Context(0))?;
self.height.to_tlv(w, Tag::Context(1))?;
self.metric.to_tlv(w, Tag::Context(2))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for DimensionStruct {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut width = None;
let mut height = None;
let mut metric = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => width = Some(<f64>::from_tlv(reader, &field)?),
Some(1) => height = Some(<f64>::from_tlv(reader, &field)?),
Some(2) => metric = Some(<MetricTypeEnum>::from_tlv(reader, &field)?),
// A field this revision does not define. §7.19.2: a receiver
// ignores what it does not know rather than refusing the whole
// structure, which is what lets a newer peer talk to an older one.
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
width: width.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
height: height.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
metric: metric.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
/// `ParameterStruct`.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ParameterStruct<'a> {
/// `Type`, field 0.
pub type_: ParameterEnum,
/// `Value`, field 1.
pub value: &'a str,
/// `ExternalIDList`, field 2.
pub external_id_list: Option<TlvList<'a, AdditionalInfoStruct<'a>>>,
}
impl<'a> ToTlv for ParameterStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.type_.to_tlv(w, Tag::Context(0))?;
self.value.to_tlv(w, Tag::Context(1))?;
if let Some(value) = &self.external_id_list {
value.to_tlv(w, Tag::Context(2))?;
}
w.end_container()
}
}
impl<'a> FromTlv<'a> for ParameterStruct<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut type_ = None;
let mut value = None;
let mut external_id_list = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => type_ = Some(<ParameterEnum>::from_tlv(reader, &field)?),
Some(1) => value = Some(<&'a str>::from_tlv(reader, &field)?),
Some(2) => {
external_id_list = Some(<TlvList<'a, AdditionalInfoStruct<'a>>>::from_tlv(
reader, &field,
)?)
}
// A field this revision does not define. §7.19.2: a receiver
// ignores what it does not know rather than refusing the whole
// structure, which is what lets a newer peer talk to an older one.
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
type_: type_.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
value: value.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
external_id_list,
})
}
}
/// `PlaybackPreferencesStruct`.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct PlaybackPreferencesStruct<'a> {
/// `PlaybackPosition`, field 0.
pub playback_position: Option<Nullable<u64>>,
/// `TextTrack`, field 1.
pub text_track: Option<Nullable<TrackPreferenceStruct<'a>>>,
/// `AudioTracks`, field 2.
pub audio_tracks: Option<Nullable<TlvList<'a, TrackPreferenceStruct<'a>>>>,
}
impl<'a> ToTlv for PlaybackPreferencesStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
if let Some(value) = &self.playback_position {
value.to_tlv(w, Tag::Context(0))?;
}
if let Some(value) = &self.text_track {
value.to_tlv(w, Tag::Context(1))?;
}
if let Some(value) = &self.audio_tracks {
value.to_tlv(w, Tag::Context(2))?;
}
w.end_container()
}
}
impl<'a> FromTlv<'a> for PlaybackPreferencesStruct<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut playback_position = None;
let mut text_track = None;
let mut audio_tracks = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => playback_position = Some(<Nullable<u64>>::from_tlv(reader, &field)?),
Some(1) => {
text_track = Some(<Nullable<TrackPreferenceStruct<'a>>>::from_tlv(
reader, &field,
)?)
}
Some(2) => {
audio_tracks = Some(
<Nullable<TlvList<'a, TrackPreferenceStruct<'a>>>>::from_tlv(
reader, &field,
)?,
)
}
// A field this revision does not define. §7.19.2: a receiver
// ignores what it does not know rather than refusing the whole
// structure, which is what lets a newer peer talk to an older one.
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
playback_position,
text_track,
audio_tracks,
})
}
}
/// `StyleInformationStruct`.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct StyleInformationStruct<'a> {
/// `ImageURL`, field 0.
pub image_url: Option<&'a str>,
/// `Color`, field 1.
pub color: Option<&'a str>,
/// `Size`, field 2.
pub size: Option<DimensionStruct>,
}
impl<'a> ToTlv for StyleInformationStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
if let Some(value) = &self.image_url {
value.to_tlv(w, Tag::Context(0))?;
}
if let Some(value) = &self.color {
value.to_tlv(w, Tag::Context(1))?;
}
if let Some(value) = &self.size {
value.to_tlv(w, Tag::Context(2))?;
}
w.end_container()
}
}
impl<'a> FromTlv<'a> for StyleInformationStruct<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut image_url = None;
let mut color = None;
let mut size = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => image_url = Some(<&'a str>::from_tlv(reader, &field)?),
Some(1) => color = Some(<&'a str>::from_tlv(reader, &field)?),
Some(2) => size = Some(<DimensionStruct>::from_tlv(reader, &field)?),
// A field this revision does not define. §7.19.2: a receiver
// ignores what it does not know rather than refusing the whole
// structure, which is what lets a newer peer talk to an older one.
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
image_url,
color,
size,
})
}
}
/// `TrackPreferenceStruct`.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct TrackPreferenceStruct<'a> {
/// `LanguageCode`, field 0.
pub language_code: &'a str,
/// `Characteristics`, field 1.
pub characteristics: Option<
Nullable<TlvList<'a, crate::clusters::generated::media_playback::CharacteristicEnum>>,
>,
/// `AudioOutputIndex`, field 2.
pub audio_output_index: Option<Nullable<u8>>,
}
impl<'a> ToTlv for TrackPreferenceStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.language_code.to_tlv(w, Tag::Context(0))?;
if let Some(value) = &self.characteristics {
value.to_tlv(w, Tag::Context(1))?;
}
if let Some(value) = &self.audio_output_index {
value.to_tlv(w, Tag::Context(2))?;
}
w.end_container()
}
}
impl<'a> FromTlv<'a> for TrackPreferenceStruct<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut language_code = None;
let mut characteristics = None;
let mut audio_output_index = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => language_code = Some(<&'a str>::from_tlv(reader, &field)?),
Some(1) => {
characteristics = Some(<Nullable<
TlvList<'a, crate::clusters::generated::media_playback::CharacteristicEnum>,
>>::from_tlv(reader, &field)?)
}
Some(2) => audio_output_index = Some(<Nullable<u8>>::from_tlv(reader, &field)?),
// A field this revision does not define. §7.19.2: a receiver
// ignores what it does not know rather than refusing the whole
// structure, which is what lets a newer peer talk to an older one.
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
language_code: language_code.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
characteristics,
audio_output_index,
})
}
}
/// The fields of `LaunchContent` (command `0x00`).
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct LaunchContentFields<'a> {
/// `Search`, field 0.
pub search: ContentSearchStruct<'a>,
/// `AutoPlay`, field 1.
pub auto_play: bool,
/// `Data`, field 2.
pub data: Option<&'a str>,
/// `PlaybackPreferences`, field 3.
pub playback_preferences: Option<PlaybackPreferencesStruct<'a>>,
/// `UseCurrentContext`, field 4.
pub use_current_context: Option<bool>,
}
impl<'a> ToTlv for LaunchContentFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.search.to_tlv(w, Tag::Context(0))?;
self.auto_play.to_tlv(w, Tag::Context(1))?;
if let Some(value) = &self.data {
value.to_tlv(w, Tag::Context(2))?;
}
if let Some(value) = &self.playback_preferences {
value.to_tlv(w, Tag::Context(3))?;
}
if let Some(value) = &self.use_current_context {
value.to_tlv(w, Tag::Context(4))?;
}
w.end_container()
}
}
impl<'a> FromTlv<'a> for LaunchContentFields<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut search = None;
let mut auto_play = None;
let mut data = None;
let mut playback_preferences = None;
let mut use_current_context = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => search = Some(<ContentSearchStruct<'a>>::from_tlv(reader, &field)?),
Some(1) => auto_play = Some(<bool>::from_tlv(reader, &field)?),
Some(2) => data = Some(<&'a str>::from_tlv(reader, &field)?),
Some(3) => {
playback_preferences =
Some(<PlaybackPreferencesStruct<'a>>::from_tlv(reader, &field)?)
}
Some(4) => use_current_context = Some(<bool>::from_tlv(reader, &field)?),
// A field this revision does not define. §7.19.2: a receiver
// ignores what it does not know rather than refusing the whole
// structure, which is what lets a newer peer talk to an older one.
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
search: search.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
auto_play: auto_play.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
data,
playback_preferences,
use_current_context,
})
}
}
/// The fields of `LaunchURL` (command `0x01`).
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct LaunchURLFields<'a> {
/// `ContentURL`, field 0.
pub content_url: &'a str,
/// `DisplayString`, field 1.
pub display_string: Option<&'a str>,
/// `BrandingInformation`, field 2.
pub branding_information: Option<BrandingInformationStruct<'a>>,
/// `PlaybackPreferences`, field 3.
pub playback_preferences: Option<PlaybackPreferencesStruct<'a>>,
}
impl<'a> ToTlv for LaunchURLFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.content_url.to_tlv(w, Tag::Context(0))?;
if let Some(value) = &self.display_string {
value.to_tlv(w, Tag::Context(1))?;
}
if let Some(value) = &self.branding_information {
value.to_tlv(w, Tag::Context(2))?;
}
if let Some(value) = &self.playback_preferences {
value.to_tlv(w, Tag::Context(3))?;
}
w.end_container()
}
}
impl<'a> FromTlv<'a> for LaunchURLFields<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut content_url = None;
let mut display_string = None;
let mut branding_information = None;
let mut playback_preferences = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => content_url = Some(<&'a str>::from_tlv(reader, &field)?),
Some(1) => display_string = Some(<&'a str>::from_tlv(reader, &field)?),
Some(2) => {
branding_information =
Some(<BrandingInformationStruct<'a>>::from_tlv(reader, &field)?)
}
Some(3) => {
playback_preferences =
Some(<PlaybackPreferencesStruct<'a>>::from_tlv(reader, &field)?)
}
// A field this revision does not define. §7.19.2: a receiver
// ignores what it does not know rather than refusing the whole
// structure, which is what lets a newer peer talk to an older one.
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
content_url: content_url.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
display_string,
branding_information,
playback_preferences,
})
}
}
/// The fields of `LauncherResponse` (command `0x02`).
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct LauncherResponseFields<'a> {
/// `Status`, field 0.
pub status: StatusEnum,
/// `Data`, field 1.
pub data: Option<&'a str>,
}
impl<'a> ToTlv for LauncherResponseFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.status.to_tlv(w, Tag::Context(0))?;
if let Some(value) = &self.data {
value.to_tlv(w, Tag::Context(1))?;
}
w.end_container()
}
}
impl<'a> FromTlv<'a> for LauncherResponseFields<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut status = None;
let mut data = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => status = Some(<StatusEnum>::from_tlv(reader, &field)?),
Some(1) => data = Some(<&'a str>::from_tlv(reader, &field)?),
// A field this revision does not define. §7.19.2: a receiver
// ignores what it does not know rather than refusing the whole
// structure, which is what lets a newer peer talk to an older one.
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
data,
})
}
}
/// Every attribute the specification defines, with its conformance.
pub const ATTRIBUTES: &[Attribute] = &[
Attribute {
id: 0x0000,
name: "AcceptHeader",
kind: "list[string]",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NON_VOLATILE,
reporting: Reporting::OnChange,
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(1),
}],
},
},
Attribute {
id: 0x0001,
name: "SupportedStreamingProtocols",
kind: "SupportedProtocolsBitmap",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NON_VOLATILE,
reporting: Reporting::OnChange,
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(1),
}],
},
},
];
/// Every command, with its conformance.
pub const COMMANDS: &[Command] = &[
Command {
id: 0x00,
name: "LaunchContent",
to_server: true,
response: Some(0x02),
access: Access::invoke(Privilege::Operate),
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(0),
}],
},
},
Command {
id: 0x01,
name: "LaunchURL",
to_server: true,
response: Some(0x02),
access: Access::invoke(Privilege::Operate),
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(1),
}],
},
},
Command {
id: 0x02,
name: "LauncherResponse",
to_server: false,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Any(&[Condition::Feature(0), Condition::Feature(1)]),
}],
},
},
];
/// Every event, with its conformance.
pub const EVENTS: &[Event] = &[];
/// The whole cluster, as the specification defines it.
pub const CLUSTER: Cluster = Cluster {
id: ID,
name: "Content Launcher",
revision: REVISION,
pics: "CONTENTLAUNCHER",
derived_from: None,
features: FEATURES,
attributes: ATTRIBUTES,
commands: COMMANDS,
events: EVENTS,
};