use crate::parser::{ByteOrder, Invalid, Parser};
use crate::{Error, Head};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Type {
Unknown,
KeyboardControllerStyle,
ServerManagementInterfaceChip,
BlockTransfer,
}
impl Parser<Type> for &[u8] {
type Arg = ();
fn parse(&mut self, arg: Self::Arg) -> Result<Type, Invalid> {
match self.parse(arg)? {
0x00u8 => Ok(Type::Unknown),
0x01u8 => Ok(Type::KeyboardControllerStyle),
0x02u8 => Ok(Type::ServerManagementInterfaceChip),
0x03u8 => Ok(Type::BlockTransfer),
_ => Err(Invalid),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Bmc {
pub kind: Type,
pub addr: u64,
}
impl<'a> TryFrom<Head<'a>> for Bmc {
type Error = Error;
fn try_from(mut node: Head<'a>) -> Result<Self, Self::Error> {
Ok(Self {
kind: node.data.parse(())?,
addr: node.data.finish(ByteOrder::Little)?,
})
}
}