#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum ValueType {
VlanId,
VlanPcp,
MacsecAn,
MacsecShortLen,
IpFragmentOffset,
IpDscp,
IpEcn,
Ipv6FlowLabel,
Ipv4PayloadLength,
Ipv6PayloadLength,
UdpPayloadLengthIpv4,
UdpPayloadLengthIpv6,
TcpPayloadLengthIpv4,
TcpPayloadLengthIpv6,
Icmpv6PayloadLength,
LinuxSllType,
}
impl core::fmt::Display for ValueType {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
use ValueType::*;
match self {
VlanId => write!(f, "VLAN ID"),
VlanPcp => write!(f, "VLAN PCP (Priority Code Point)"),
MacsecAn => write!(f, "MACsec AN (Association Number)"),
MacsecShortLen => write!(f, "MACsec SL (Short Length)"),
IpFragmentOffset => write!(f, "IP Fragment Offset"),
IpDscp => write!(f, "IPv4 DSCP (Differentiated Services Code Point)"),
IpEcn => write!(f, "IPv4 ECN (Explicit Congestion Notification)"),
Ipv6FlowLabel => write!(f, "IPv6 Flow Label"),
Ipv4PayloadLength => write!(f, "IPv4 Header 'Payload Length' (sets 'Total Length')"),
Ipv6PayloadLength => write!(f, "IPv6 Header 'Payload Length'"),
UdpPayloadLengthIpv4 => write!(f, "UDP Payload Length (in IPv4 checksum calculation)"),
UdpPayloadLengthIpv6 => write!(f, "UDP Payload Length (in IPv6 checksum calculation)"),
TcpPayloadLengthIpv4 => write!(f, "TCP Payload Length (in IPv4 checksum calculation)"),
TcpPayloadLengthIpv6 => write!(f, "TCP Payload Length (in IPv6 checksum calculation)"),
Icmpv6PayloadLength => write!(f, "ICMPv6 Payload Length"),
LinuxSllType => write!(f, "Linux Cooked Capture v1 (SLL)"),
}
}
}
#[cfg(test)]
mod test {
use super::*;
use std::format;
#[test]
fn debug() {
assert_eq!(
format!("{:?}", ValueType::IpFragmentOffset),
"IpFragmentOffset"
);
}
#[test]
fn cmp_partial_cmp() {
use core::cmp::Ordering;
let a = ValueType::IpFragmentOffset;
let b = a;
assert_eq!(a.cmp(&b), Ordering::Equal);
assert_eq!(a.partial_cmp(&b), Some(Ordering::Equal));
}
#[test]
fn display() {
use ValueType::*;
assert_eq!("VLAN ID", &format!("{}", VlanId));
assert_eq!("VLAN PCP (Priority Code Point)", &format!("{}", VlanPcp));
assert_eq!("MACsec AN (Association Number)", &format!("{}", MacsecAn));
assert_eq!("MACsec SL (Short Length)", &format!("{}", MacsecShortLen));
assert_eq!("IP Fragment Offset", &format!("{}", IpFragmentOffset));
assert_eq!(
"IPv4 DSCP (Differentiated Services Code Point)",
&format!("{}", IpDscp)
);
assert_eq!(
"IPv4 ECN (Explicit Congestion Notification)",
&format!("{}", IpEcn)
);
assert_eq!("IPv6 Flow Label", &format!("{}", Ipv6FlowLabel));
assert_eq!(
"IPv4 Header 'Payload Length' (sets 'Total Length')",
&format!("{}", Ipv4PayloadLength)
);
assert_eq!(
"IPv6 Header 'Payload Length'",
&format!("{}", Ipv6PayloadLength)
);
assert_eq!(
"UDP Payload Length (in IPv4 checksum calculation)",
&format!("{}", UdpPayloadLengthIpv4)
);
assert_eq!(
"UDP Payload Length (in IPv6 checksum calculation)",
&format!("{}", UdpPayloadLengthIpv6)
);
assert_eq!(
"TCP Payload Length (in IPv4 checksum calculation)",
&format!("{}", TcpPayloadLengthIpv4)
);
assert_eq!(
"TCP Payload Length (in IPv6 checksum calculation)",
&format!("{}", TcpPayloadLengthIpv6)
);
assert_eq!("ICMPv6 Payload Length", &format!("{}", Icmpv6PayloadLength));
}
}