pub(crate) mod ac_capability;
#[cfg(feature = "control")]
pub(crate) mod ac_control;
pub(crate) mod ac_status;
pub(crate) mod console_version;
mod control_status;
mod extended;
#[cfg(feature = "control")]
pub(crate) mod zone_control;
pub(crate) mod zone_name;
pub(crate) mod zone_status;
#[derive(Clone, Debug)]
pub struct Frame {
pub(crate) inner: crate::conn::frame::Frame,
}
#[derive(Clone, Debug)]
pub enum MessageError {
InvalidData,
IncorrectSubtype(Frame),
}
impl From<std::str::Utf8Error> for MessageError {
fn from(_value: std::str::Utf8Error) -> Self {
Self::InvalidData
}
}
impl From<std::io::Error> for MessageError {
fn from(_value: std::io::Error) -> Self {
Self::InvalidData
}
}
impl From<std::num::TryFromIntError> for MessageError {
fn from(_value: std::num::TryFromIntError) -> Self {
Self::InvalidData
}
}
impl From<MessageError> for std::io::Error {
fn from(value: MessageError) -> std::io::Error {
std::io::Error::other(value)
}
}
impl std::fmt::Display for MessageError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
Self::IncorrectSubtype(_) => "wrong message subtype",
Self::InvalidData => "invalid message data",
}
)
}
}
impl std::error::Error for MessageError {}
mod message_id {
use std::sync::atomic::{AtomicU8, Ordering};
static NEXT_MESSAGE_ID: AtomicU8 = AtomicU8::new(1);
pub fn next() -> u8 {
NEXT_MESSAGE_ID.fetch_add(1, Ordering::Relaxed)
}
}
pub use message_id::next as next_msg_id;