use crate::error::BioLibError;

pub struct StdoutAndStderr;

impl StdoutAndStderr {
    pub fn deserialize(bbf: &[u8]) -> crate::Result<Vec<u8>> {
        let mut pointer = 0usize;

        let version = bbf[pointer];
        pointer += 1;
        let package_type = bbf[pointer];
        pointer += 1;

        if version != 1 {
            return Err(BioLibError::BinaryFormat(format!(
                "Unsupported version: {version}"
            )));
        }
        if package_type != 10 {
            return Err(BioLibError::BinaryFormat(format!(
                "Unsupported package type: {package_type}"
            )));
        }

        let length = u64::from_be_bytes(bbf[pointer..pointer + 8].try_into().unwrap()) as usize;
        pointer += 8;

        Ok(bbf[pointer..pointer + length].to_vec())
    }
}
