#[cfg(feature = "std")]
use crate::protocol::sd;
use crate::protocol::{self, MessageId, sd::Flags};
#[cfg(feature = "std")]
pub struct OfferedEndpoint {
pub service_id: u16,
pub instance_id: u16,
pub major_version: u8,
pub minor_version: u32,
pub addr: Option<std::net::SocketAddrV4>,
pub is_offer: bool,
}
pub trait WireFormat: Send + Sized + Sync {
fn required_size(&self) -> usize;
fn encode<T: embedded_io::Write>(&self, writer: &mut T) -> Result<usize, protocol::Error>;
fn encode_to_slice(&self, buf: &mut [u8]) -> Result<usize, protocol::Error> {
self.encode(&mut &mut *buf)
}
#[cfg(feature = "std")]
fn encode_to_vec(&self) -> Result<std::vec::Vec<u8>, protocol::Error> {
let mut buf = std::vec![0u8; self.required_size()];
self.encode_to_slice(&mut buf)?;
Ok(buf)
}
}
pub trait PayloadWireFormat: core::fmt::Debug + Send + Sized + Sync {
type SdHeader: WireFormat + Clone + core::fmt::Debug + Eq;
fn message_id(&self) -> MessageId;
fn as_sd_header(&self) -> Option<&Self::SdHeader>;
fn from_payload_bytes(message_id: MessageId, payload: &[u8]) -> Result<Self, protocol::Error>;
fn new_sd_payload(header: &Self::SdHeader) -> Self;
fn sd_flags(&self) -> Option<Flags>;
fn required_size(&self) -> usize;
fn encode<T: embedded_io::Write>(&self, writer: &mut T) -> Result<usize, protocol::Error>;
#[cfg(feature = "std")]
#[allow(clippy::too_many_arguments)]
fn new_subscription_sd_header(
service_id: u16,
instance_id: u16,
major_version: u8,
ttl: u32,
event_group_id: u16,
client_ip: std::net::Ipv4Addr,
protocol: sd::TransportProtocol,
client_port: u16,
reboot_flag: sd::RebootFlag,
) -> Self::SdHeader;
#[cfg(feature = "std")]
fn set_reboot_flag(header: &mut Self::SdHeader, reboot: sd::RebootFlag);
#[cfg(feature = "std")]
fn offered_endpoints(&self) -> std::vec::Vec<OfferedEndpoint> {
std::vec::Vec::new()
}
#[cfg(feature = "std")]
fn service_instances(&self) -> std::vec::Vec<(u16, u16)> {
std::vec::Vec::new()
}
}