use std::io::{Read, Write};
use crate::tbc::LfgType;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
pub struct LfgData {
pub entry: u16,
pub lfg_type: LfgType,
}
impl LfgData {
pub(crate) fn write_into_vec(&self, mut w: impl Write) -> Result<(), std::io::Error> {
w.write_all(&self.entry.to_le_bytes())?;
w.write_all(&u16::from(self.lfg_type.as_int()).to_le_bytes())?;
Ok(())
}
}
impl LfgData {
pub(crate) fn read<R: std::io::Read>(mut r: R) -> Result<Self, crate::errors::ParseErrorKind> {
let entry = crate::util::read_u16_le(&mut r)?;
let lfg_type = (crate::util::read_u16_le(&mut r)? as u8).try_into()?;
Ok(Self {
entry,
lfg_type,
})
}
}