use std::net::Ipv4Addr;
use crate::wire::ThirdPartyVendorFlag;
pub const THIRD_PARTY_PAYLOAD_MAX: usize = 1444;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ThirdPartyVendor {
pub flags: ThirdPartyVendorFlag,
pub id: [u8; 3],
}
impl ThirdPartyVendor {
pub const fn oui(oui: [u8; 3]) -> Self {
Self {
flags: ThirdPartyVendorFlag::NONE,
id: oui,
}
}
pub const fn private(id: [u8; 3]) -> Self {
Self {
flags: ThirdPartyVendorFlag::NOT_OUI,
id,
}
}
pub const fn same_vendor(self, other: Self) -> bool {
let a = self.id;
let b = other.id;
self.flags.has(ThirdPartyVendorFlag::NOT_OUI)
== other.flags.has(ThirdPartyVendorFlag::NOT_OUI)
&& a[0] == b[0]
&& a[1] == b[1]
&& a[2] == b[2]
}
pub(crate) const fn to_wire(self) -> [u8; 4] {
[self.flags.bits(), self.id[0], self.id[1], self.id[2]]
}
pub(crate) const fn from_wire(b: [u8; 4]) -> Self {
Self {
flags: ThirdPartyVendorFlag::from_bits(b[0]),
id: [b[1], b[2], b[3]],
}
}
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct ThirdPartyMessage {
pub vendor: ThirdPartyVendor,
pub payload: Vec<u8>,
pub address: Option<Ipv4Addr>,
}