use core::{
fmt::{Debug, Formatter},
net::SocketAddr,
num::NonZeroUsize,
};
use bytes::Bytes;
use smoltcp::iface::SocketHandle;
use crate::command;
pub enum Command {
Bind {
endpoint: SocketAddr,
},
Send {
endpoint: SocketAddr,
buf: Bytes,
},
Recv {
max_len: Option<NonZeroUsize>,
},
Close,
}
impl Debug for Command {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
match self {
Self::Bind { endpoint } => f.debug_struct("Bind").field("endpoint", endpoint).finish(),
Self::Send { endpoint, buf } => f
.debug_struct("Send")
.field("endpoint", endpoint)
.field("buf_len", &buf.len())
.finish(),
Self::Recv { max_len } => f.debug_struct("Recv").field("max_len", max_len).finish(),
Self::Close => f.debug_struct("Close").finish(),
}
}
}
impl From<Command> for command::Command {
fn from(value: Command) -> Self {
command::Command::Udp(value)
}
}
pub enum Response {
Bound {
handle: SocketHandle,
local: SocketAddr,
},
RecvFrom {
remote: SocketAddr,
buf: Bytes,
truncated: Option<usize>,
},
}
impl From<Response> for command::Response {
fn from(value: Response) -> Self {
Self::Udp(value)
}
}
impl Debug for Response {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
match self {
Self::Bound { handle, local } => f
.debug_struct("Bound")
.field("handle", handle)
.field("local", local)
.finish(),
Self::RecvFrom {
remote,
buf,
truncated,
} => f
.debug_struct("RecvFrom")
.field("remote", remote)
.field("buf_len", &buf.len())
.field("truncated", truncated)
.finish(),
}
}
}