use crate::data::reader::DataReader;
use crate::hardware::error::NotAvailableError;

pub struct Header {
    pub length: u16,
    pub channel: u8,
    pub sequence_number: u8,
}

impl Header {
    pub const SIZE: usize = size_of::<u16>() + size_of::<u8>() + size_of::<u8>();

    pub fn parse(bytes: &mut impl DataReader) -> Result<Self> {
        let length = bytes.read_le::<u16>().ok_or(NotAvailableError)?;
        let channel = bytes.read_le::<u8>().ok_or(NotAvailableError)?;
        let sequence_number = bytes.read_le::<u8>().ok_or(NotAvailableError)?;

        Ok(Self {
            length,
            channel,
            sequence_number,
        })
    }
}

