1use crate::error::Error;
8use alloc::vec::Vec;
9
10#[derive(Debug, Clone, PartialEq, Eq)]
12pub struct Mfg {
13 pub oui: [u8; 3],
15 pub payload: Vec<u8>,
17}
18
19impl Mfg {
20 pub fn encode(&self) -> Result<Vec<u8>, Error> {
22 let mut out = Vec::with_capacity(3 + self.payload.len());
23 out.extend_from_slice(&self.oui);
24 out.extend_from_slice(&self.payload);
25 Ok(out)
26 }
27
28 pub fn decode(data: &[u8]) -> Result<Self, Error> {
30 if data.len() < 3 {
31 return Err(Error::MalformedPayload {
32 code: 0x80,
33 reason: "MFG requires 3-byte OUI",
34 });
35 }
36 let mut oui = [0u8; 3];
37 oui.copy_from_slice(&data[..3]);
38 Ok(Self {
39 oui,
40 payload: data[3..].to_vec(),
41 })
42 }
43}