Merge branch 'feat/p3-storage-trait' into feat/p3-range-zfp-edit
# Conflicts: # CHANGELOG.md # crates/clawhdf5-format/src/attribute.rs # crates/clawhdf5-format/src/btree_v1.rs # crates/clawhdf5-format/src/data_layout.rs # crates/clawhdf5-format/src/extensible_array.rs # crates/clawhdf5-format/src/fixed_array.rs # crates/clawhdf5-format/src/fractal_heap.rs # crates/clawhdf5-format/src/local_heap.rs # crates/clawhdf5-format/src/shared_message.rs
This commit is contained in:
@@ -117,9 +117,21 @@ pub fn dataset_fill_value_in(
|
||||
messages: &[HeaderMessage],
|
||||
offset_size: u8,
|
||||
length_size: u8,
|
||||
) -> Result<Option<Vec<u8>>, FormatError> {
|
||||
dataset_fill_value_from_storage(&file_data, messages, offset_size, length_size)
|
||||
}
|
||||
|
||||
/// [`dataset_fill_value_in`] with the file behind any
|
||||
/// [`Storage`](crate::storage::Storage). (The trait is not imported here:
|
||||
/// its `len` would shadow the slice method in this module.)
|
||||
pub fn dataset_fill_value_from_storage(
|
||||
file: &dyn crate::storage::Storage,
|
||||
messages: &[HeaderMessage],
|
||||
offset_size: u8,
|
||||
length_size: u8,
|
||||
) -> Result<Option<Vec<u8>>, FormatError> {
|
||||
fill_value_from(messages, |msg| {
|
||||
crate::shared_message::message_data_with_sohm(file_data, msg, offset_size, length_size)
|
||||
crate::shared_message::message_data_with_sohm_in(file, msg, offset_size, length_size)
|
||||
.map(|data| data.into_owned())
|
||||
})
|
||||
}
|
||||
@@ -444,4 +456,37 @@ mod tests {
|
||||
.collect();
|
||||
assert_eq!(filled, [2, 3, 7, 8]);
|
||||
}
|
||||
|
||||
/// Fill values, shared ones in the SOHM heap included, resolve
|
||||
/// identically through a read_at-only CountingStorage.
|
||||
#[test]
|
||||
fn storage_reads_match_slice_reads() {
|
||||
use crate::object_header::ObjectHeader;
|
||||
use crate::storage::CountingStorage;
|
||||
let file: &[u8] = include_bytes!("../tests/fixtures/shared_fill_value.h5");
|
||||
let sb = crate::superblock::Superblock::parse(file, 0).unwrap();
|
||||
let (os, ls) = (sb.offset_size, sb.length_size);
|
||||
let storage = CountingStorage::new(file.to_vec());
|
||||
let mut shared = 0;
|
||||
let children =
|
||||
crate::group_v2::resolve_group_children(file, &sb, sb.root_group_address).unwrap();
|
||||
assert!(children.len() >= 3);
|
||||
for child in children {
|
||||
let h =
|
||||
ObjectHeader::parse(file, child.object_header_address as usize, os, ls).unwrap();
|
||||
shared += h
|
||||
.messages
|
||||
.iter()
|
||||
.filter(|m| {
|
||||
m.msg_type == MessageType::FillValue
|
||||
&& crate::shared_message::is_shared(m.flags)
|
||||
})
|
||||
.count();
|
||||
let want = dataset_fill_value_in(file, &h.messages, os, ls);
|
||||
assert_eq!(want, Ok(Some((-7i32).to_le_bytes().to_vec())));
|
||||
let got = dataset_fill_value_from_storage(&storage, &h.messages, os, ls);
|
||||
assert_eq!(got, want, "{}", child.name);
|
||||
}
|
||||
assert!(shared >= 2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user