use crate::Error;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Protocol {
V3,
V4,
V5,
}
impl From<Protocol> for u8 {
fn from(value: Protocol) -> Self {
match value {
Protocol::V3 => 0x03,
Protocol::V4 => 0x04,
Protocol::V5 => 0x05,
}
}
}
impl TryFrom<u8> for Protocol {
type Error = Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
0x03 => Ok(Protocol::V3),
0x04 => Ok(Protocol::V4),
0x05 => Ok(Protocol::V5),
_ => Err(Error::InvalidProtocolLevel(value)),
}
}
}
impl Protocol {
pub fn name(self) -> &'static str {
match self {
Protocol::V3 => "MQIsdp",
_ => "MQTT",
}
}
}