pub mod btree_v1;
pub(crate) mod bytes;
pub mod checksum;
pub mod chunk_index;
pub mod creation_order;
pub mod dense_attr;
pub mod dense_link;
pub mod fractal_heap;
pub mod fractal_heap_write;
pub mod free_space;
pub mod global_heap;
pub mod local_heap;
pub mod messages;
pub mod nbit_scaleoffset;
pub mod object_header;
pub mod reference;
pub mod selection;
pub(crate) mod shuffle;
pub mod sohm;
pub mod sohm_write;
pub mod storage_kind;
pub mod superblock;
pub mod symbol_table;
pub mod szip;
#[derive(Debug, Clone, Copy)]
pub struct FormatContext {
pub sizeof_addr: u8,
pub sizeof_size: u8,
}
impl FormatContext {
pub fn default_v3() -> Self {
Self {
sizeof_addr: 8,
sizeof_size: 8,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default)]
pub enum LibverBound {
#[default]
Earliest,
V18,
V110,
V112,
V114,
V200,
}
impl LibverBound {
pub fn dtype_version(self) -> u8 {
match self {
Self::Earliest => 1,
Self::V18 | Self::V110 => 3,
Self::V112 | Self::V114 => 4,
Self::V200 => 5,
}
}
pub fn layout_version(self) -> u8 {
match self {
Self::Earliest => 1,
Self::V18 => 3,
Self::V110 | Self::V112 | Self::V114 => 4,
Self::V200 => 5,
}
}
pub fn superblock_version(self) -> u8 {
match self {
Self::Earliest => 0,
Self::V18 => 2,
Self::V110 | Self::V112 | Self::V114 | Self::V200 => 3,
}
}
pub fn from_superblock_version(version: u8) -> Self {
match version {
0 | 1 => Self::Earliest,
2 => Self::V18,
3 => Self::V110,
_ => Self::V200,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ObjectFormat {
Legacy,
#[default]
Modern,
}
impl ObjectFormat {
pub fn object_header_version(self) -> u8 {
match self {
Self::Legacy => 1,
Self::Modern => 2,
}
}
pub fn dataspace_version(self) -> u8 {
match self {
Self::Legacy => 1,
Self::Modern => 2,
}
}
pub fn fill_value_version(self) -> u8 {
match self {
Self::Legacy => 2,
Self::Modern => 3,
}
}
pub fn attribute_version(self) -> u8 {
match self {
Self::Legacy => 1,
Self::Modern => 3,
}
}
pub fn filter_pipeline_version(self) -> u8 {
match self {
Self::Legacy => 1,
Self::Modern => 2,
}
}
}
pub const UNDEF_ADDR: u64 = u64::MAX;
pub trait BlockReader {
fn read_block(&mut self, offset: u64, len: usize) -> FormatResult<Vec<u8>>;
}
#[derive(Debug)]
pub enum FormatError {
InvalidSignature,
InvalidVersion(u8),
BufferTooShort { needed: usize, available: usize },
ChecksumMismatch { expected: u32, computed: u32 },
UnsupportedFeature(String),
InvalidData(String),
}
impl std::fmt::Display for FormatError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::InvalidSignature => write!(f, "invalid HDF5 signature"),
Self::InvalidVersion(v) => write!(f, "unsupported version: {}", v),
Self::BufferTooShort { needed, available } => {
write!(
f,
"buffer too short: need {} bytes, have {}",
needed, available
)
}
Self::ChecksumMismatch { expected, computed } => {
write!(
f,
"checksum mismatch: expected 0x{:08x}, computed 0x{:08x}",
expected, computed
)
}
Self::UnsupportedFeature(s) => write!(f, "unsupported feature: {}", s),
Self::InvalidData(s) => write!(f, "invalid data: {}", s),
}
}
}
impl std::error::Error for FormatError {}
pub type FormatResult<T> = Result<T, FormatError>;