#![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,
};
pub const ID: ClusterId = 0x0510;
pub const REVISION: u16 = 1;
pub const PICS: &str = "APPOBSERVER";
pub const FEATURES: &[Feature] = &[];
pub mod command {
use crate::im::CommandId;
pub const CONTENT_APP_MESSAGE: CommandId = 0x00;
pub const CONTENT_APP_MESSAGE_RESPONSE: CommandId = 0x01;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum StatusEnum {
Success = 0,
UnexpectedData = 1,
}
impl StatusEnum {
#[must_use]
pub const fn from_value(value: u8) -> Option<Self> {
match value {
0 => Some(Self::Success),
1 => Some(Self::UnexpectedData),
_ => None,
}
}
#[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))
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ContentAppMessageFields<'a> {
pub data: &'a str,
pub encoding_hint: Option<&'a str>,
}
impl<'a> ToTlv for ContentAppMessageFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.data.to_tlv(w, Tag::Context(0))?;
if let Some(value) = &self.encoding_hint {
value.to_tlv(w, Tag::Context(1))?;
}
w.end_container()
}
}
impl<'a> FromTlv<'a> for ContentAppMessageFields<'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 data = None;
let mut encoding_hint = 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) => data = Some(<&'a str>::from_tlv(reader, &field)?),
Some(1) => encoding_hint = Some(<&'a str>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
data: data.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
encoding_hint,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ContentAppMessageResponseFields<'a> {
pub status: StatusEnum,
pub data: Option<&'a str>,
pub encoding_hint: Option<&'a str>,
}
impl<'a> ToTlv for ContentAppMessageResponseFields<'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))?;
}
if let Some(value) = &self.encoding_hint {
value.to_tlv(w, Tag::Context(2))?;
}
w.end_container()
}
}
impl<'a> FromTlv<'a> for ContentAppMessageResponseFields<'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;
let mut encoding_hint = 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)?),
Some(2) => encoding_hint = Some(<&'a str>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
data,
encoding_hint,
})
}
}
pub const ATTRIBUTES: &[Attribute] = &[];
pub const COMMANDS: &[Command] = &[
Command {
id: 0x00,
name: "ContentAppMessage",
to_server: true,
response: Some(0x01),
access: Access::invoke(Privilege::Operate),
conform: Conform::MANDATORY,
},
Command {
id: 0x01,
name: "ContentAppMessageResponse",
to_server: false,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform::MANDATORY,
},
];
pub const EVENTS: &[Event] = &[];
pub const CLUSTER: Cluster = Cluster {
id: ID,
name: "Content App Observer",
revision: REVISION,
pics: "APPOBSERVER",
derived_from: None,
features: FEATURES,
attributes: ATTRIBUTES,
commands: COMMANDS,
events: EVENTS,
};