use crate::error::CarDecodeError;
pub(crate) const CARV2_HEADER_SIZE: usize = 40;
pub(crate) const CARV2_PRAGMA_SIZE: usize = 11;
#[allow(dead_code)]
pub(crate) const CARV2_PRAGMA: [u8; CARV2_PRAGMA_SIZE] = [
0x0a, 0xa1, 0x67, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x02, ];
#[derive(Debug, PartialEq)]
pub(crate) struct CarV2Header {
pub characteristics: u128,
pub data_offset: u64,
pub data_size: u64,
pub index_offset: u64,
}
pub(crate) fn decode_carv2_header(
header: &[u8; CARV2_HEADER_SIZE],
) -> Result<CarV2Header, CarDecodeError> {
let characteristics = u128::from_be_bytes(header[0..16].try_into().unwrap());
let data_offset = u64::from_le_bytes(header[16..24].try_into().unwrap());
let data_size = u64::from_le_bytes(header[24..32].try_into().unwrap());
let index_offset = u64::from_le_bytes(header[32..40].try_into().unwrap());
Ok(CarV2Header {
characteristics,
data_offset,
data_size,
index_offset,
})
}