#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ProtocolVersion {
V1_21,
}
impl ProtocolVersion {
pub fn protocol_number(&self) -> i32 {
match self {
Self::V1_21 => 767,
}
}
pub fn from_protocol_number(number: i32) -> Option<Self> {
match number {
767 => Some(Self::V1_21),
_ => None,
}
}
}
impl std::fmt::Display for ProtocolVersion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::V1_21 => f.write_str("1.21"),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn protocol_number_v1_21() {
assert_eq!(ProtocolVersion::V1_21.protocol_number(), 767);
}
#[test]
fn from_protocol_number_valid() {
assert_eq!(
ProtocolVersion::from_protocol_number(767),
Some(ProtocolVersion::V1_21)
);
}
#[test]
fn from_protocol_number_unknown() {
assert_eq!(ProtocolVersion::from_protocol_number(999), None);
}
#[test]
fn display() {
assert_eq!(ProtocolVersion::V1_21.to_string(), "1.21");
}
}