#[allow(unused_imports)]
use super::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct EthernetFlags(u8);
impl EthernetFlags {
pub const TX: u8 = 0x01;
pub const FCS_VALID: u8 = 0x02;
pub const TRUNCATED: u8 = 0x04;
pub const CRC_ERROR: u8 = 0x08;
pub const VLAN_TAGGED: u8 = 0x10;
pub fn from_byte(value: u8) -> Self {
Self(value)
}
pub fn to_byte(self) -> u8 {
self.0
}
pub fn rx() -> Self {
Self(0)
}
pub fn tx() -> Self {
Self(Self::TX)
}
pub fn is_tx(self) -> bool {
self.0 & Self::TX != 0
}
pub fn is_rx(self) -> bool {
!self.is_tx()
}
pub fn fcs_valid(self) -> bool {
self.0 & Self::FCS_VALID != 0
}
pub fn is_truncated(self) -> bool {
self.0 & Self::TRUNCATED != 0
}
pub fn has_crc_error(self) -> bool {
self.0 & Self::CRC_ERROR != 0
}
pub fn has_vlan_tag(self) -> bool {
self.0 & Self::VLAN_TAGGED != 0
}
pub fn with_tx(self, tx: bool) -> Self {
if tx {
Self(self.0 | Self::TX)
} else {
Self(self.0 & !Self::TX)
}
}
pub fn with_fcs_valid(self, valid: bool) -> Self {
if valid {
Self(self.0 | Self::FCS_VALID)
} else {
Self(self.0 & !Self::FCS_VALID)
}
}
pub fn with_vlan_tagged(self, tagged: bool) -> Self {
if tagged {
Self(self.0 | Self::VLAN_TAGGED)
} else {
Self(self.0 & !Self::VLAN_TAGGED)
}
}
}