use core::{
fmt::{Debug, Formatter},
num::NonZeroUsize,
};
use bytes::Bytes;
use smoltcp::{iface::SocketHandle, wire};
use crate::command;
pub enum Command {
Open {
ip_version: wire::IpVersion,
protocol: wire::IpProtocol,
},
Send {
buf: Bytes,
},
Recv {
max_len: Option<NonZeroUsize>,
},
Close,
}
impl From<Command> for command::Command {
fn from(value: Command) -> Self {
command::Command::Raw(value)
}
}
impl Debug for Command {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
match self {
Self::Open {
ip_version,
protocol,
} => f
.debug_struct("Open")
.field("ip_version", ip_version)
.field("protocol", protocol)
.finish(),
Self::Send { buf } => f.debug_struct("Send").field("buf_len", &buf.len()).finish(),
Self::Recv { max_len } => f.debug_struct("Recv").field("max_len", max_len).finish(),
Self::Close => f.write_str("Close"),
}
}
}
pub enum Response {
Opened {
handle: SocketHandle,
},
Recv {
buf: Bytes,
truncated: Option<usize>,
},
}
impl From<Response> for command::Response {
fn from(value: Response) -> Self {
Self::Raw(value)
}
}
impl Debug for Response {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
match self {
Self::Opened { handle } => f.debug_struct("Opened").field("handle", handle).finish(),
Self::Recv { buf, truncated } => f
.debug_struct("Recv")
.field("buf_len", &buf.len())
.field("truncated", truncated)
.finish(),
}
}
}