feat(facade): Dataset::raw_datatype returns the full stored datatype

dtype() simplifies the type (no byte order, string padding or member
offsets), so callers could not decode read_selection's bytes for types
the typed read_* methods skip. raw_datatype() returns the parsed
Datatype, committed types resolved, for use with data_read.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
osobh
2026-09-25 23:51:20 -05:00
co-authored by Claude Opus 5.5
parent bb78d70b99
commit e815eb922f
2 changed files with 38 additions and 0 deletions
+29
View File
@@ -144,6 +144,35 @@ mod tests {
assert_eq!(ds.dtype().unwrap(), DType::I32);
}
#[test]
fn dataset_raw_datatype() {
use clawhdf5_format::datatype::Datatype;
let bytes = make_simple_file();
let file = File::from_bytes(bytes).unwrap();
let dt = file.dataset("counts").unwrap().raw_datatype().unwrap();
assert!(
matches!(
dt,
Datatype::FixedPoint {
size: 4,
signed: true,
..
}
),
"{dt:?}"
);
// The full type pairs with read_selection's bytes.
let raw = file
.dataset("counts")
.unwrap()
.read_selection(&Selection::All)
.unwrap();
assert_eq!(
clawhdf5_format::data_read::read_as_i64(&raw, &dt).unwrap(),
vec![10, 20, 30]
);
}
#[test]
fn root_group_datasets() {
let bytes = make_simple_file();
+9
View File
@@ -416,6 +416,15 @@ impl<'f> Dataset<'f> {
Ok(classify_datatype(&dt))
}
/// Returns the dataset's full datatype as stored in the file (byte order,
/// string padding, compound layout, ...), with a committed datatype
/// resolved. Use it with the `clawhdf5_format::data_read` converters on
/// the bytes [`read_selection`](Self::read_selection) returns, for types
/// the typed `read_*` methods do not cover.
pub fn raw_datatype(&self) -> Result<Datatype, Error> {
self.datatype()
}
/// Read all data as `f64` values.
pub fn read_f64(&self) -> Result<Vec<f64>, Error> {
let dt = self.datatype()?;