qualia_core_db/bundle/stream/index/
probe.rs1use super::{admit_header, ExtentLimit, IndexError, IndexReadLimits};
3use crate::bundle::format::{BUNDLE_HEADER_SIZE, BundleError};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub struct HmcHeaderProbe {
8 pub version: u16,
9 pub flags: u16,
10 pub entry_count: u32,
11 pub index_offset: u64,
12 pub index_length: u64,
13 pub total_length: u64,
14 pub whole_file_crc32c: u32,
15}
16
17impl HmcHeaderProbe {
18 pub fn parse_header_range(header_bytes: &[u8]) -> Result<Self, BundleError> {
20 if header_bytes.len() < BUNDLE_HEADER_SIZE {
21 return Err(BundleError::TooShort);
22 }
23 let mut extent = [0u8; 8];
24 extent.copy_from_slice(&header_bytes[28..36]);
25 let checked = admit_header(
26 &header_bytes[..BUNDLE_HEADER_SIZE],
27 u64::from_le_bytes(extent),
28 ExtentLimit::default(),
29 IndexReadLimits::default(),
30 )
31 .map_err(IndexError::into_bundle_error)?;
32 Ok(checked.probe())
33 }
34
35 #[inline]
37 pub fn index_footer_range(&self) -> (u64, u64) {
38 (self.index_offset, self.index_length)
39 }
40}
41