#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum PacketType {
Data,
Ack,
Ping,
Pong,
}
impl PacketType {
pub const DATA_CODE: u8 = 0x00;
pub const ACK_CODE: u8 = 0x01;
pub const PING_CODE: u8 = 0x02;
pub const PONG_CODE: u8 = 0x03;
#[must_use]
pub const fn code(self) -> u8 {
match self {
Self::Data => Self::DATA_CODE,
Self::Ack => Self::ACK_CODE,
Self::Ping => Self::PING_CODE,
Self::Pong => Self::PONG_CODE,
}
}
#[must_use]
pub const fn from_code(code: u8) -> Option<Self> {
match code {
Self::DATA_CODE => Some(Self::Data),
Self::ACK_CODE => Some(Self::Ack),
Self::PING_CODE => Some(Self::Ping),
Self::PONG_CODE => Some(Self::Pong),
_ => None,
}
}
}