Skip to content

Commit 2beedad

Browse files
committed
Merge branch 'feature/0.5.3-fixes'
2 parents e7a28a7 + 0afe13c commit 2beedad

File tree

3 files changed

+109
-8
lines changed

3 files changed

+109
-8
lines changed

hdf5-sys/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ mod windows {
342342

343343
use serde::de::Error;
344344
use serde::{Deserialize, Deserializer};
345-
use serde_derive::Deserialize;
345+
use serde_derive::Deserialize as DeriveDeserialize;
346346
use winreg::enums::HKEY_LOCAL_MACHINE;
347347
use winreg::RegKey;
348348

@@ -356,7 +356,7 @@ mod windows {
356356
}
357357
}
358358

359-
#[derive(Clone, Deserialize)]
359+
#[derive(Clone, DeriveDeserialize)]
360360
struct App {
361361
#[serde(rename = "DisplayName")]
362362
name: String,

src/hl/dataset.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use std::ops::Deref;
44

55
use num_integer::div_floor;
66

7+
#[cfg(hdf5_1_10_5)]
8+
use hdf5_sys::h5d::{H5Dget_chunk_info, H5Dget_num_chunks};
79
use hdf5_sys::{
810
h5::HADDR_UNDEF,
911
h5d::{
@@ -62,6 +64,32 @@ pub enum Chunk {
6264
Manual(Vec<Ix>),
6365
}
6466

67+
#[cfg(hdf5_1_10_5)]
68+
#[derive(Clone, Debug, PartialEq, Eq)]
69+
pub struct ChunkInfo {
70+
/// Array with a size equal to the dataset’s rank whose elements contain 0-based
71+
/// logical positions of the chunk’s first element in each dimension.
72+
pub offset: Vec<u64>,
73+
/// Filter mask that indicates which filters were used with the chunk when written.
74+
/// A zero value indicates that all enabled filters are applied on the chunk.
75+
/// A filter is skipped if the bit corresponding to the filter’s position in
76+
/// the pipeline (0 ≤ position < 32) is turned on.
77+
pub filter_mask: u32,
78+
/// Chunk address in the file.
79+
pub addr: u64,
80+
/// Chunk size in bytes.
81+
pub size: u64,
82+
}
83+
84+
#[cfg(hdf5_1_10_5)]
85+
impl ChunkInfo {
86+
pub(crate) fn new(ndim: usize) -> Self {
87+
let mut offset = Vec::with_capacity(ndim);
88+
unsafe { offset.set_len(ndim) };
89+
Self { offset, filter_mask: 0, addr: 0, size: 0 }
90+
}
91+
}
92+
6593
impl Dataset {
6694
/// Returns whether this dataset is resizable along some axis.
6795
pub fn is_resizable(&self) -> bool {
@@ -77,6 +105,40 @@ impl Dataset {
77105
})
78106
}
79107

108+
#[cfg(hdf5_1_10_5)]
109+
/// Returns number of chunks if the dataset is chunked.
110+
pub fn num_chunks(&self) -> Option<usize> {
111+
if !self.is_chunked() {
112+
return None;
113+
}
114+
h5lock!(self.space().map_or(None, |s| {
115+
let mut n: hsize_t = 0;
116+
h5check(H5Dget_num_chunks(self.id(), s.id(), &mut n)).map(|_| n as _).ok()
117+
}))
118+
}
119+
120+
#[cfg(hdf5_1_10_5)]
121+
/// Retrieves the chunk information for the chunk specified by its index.
122+
pub fn chunk_info(&self, index: usize) -> Option<ChunkInfo> {
123+
if !self.is_chunked() {
124+
return None;
125+
}
126+
h5lock!(self.space().map_or(None, |s| {
127+
let mut chunk_info = ChunkInfo::new(self.ndim());
128+
h5check(H5Dget_chunk_info(
129+
self.id(),
130+
s.id(),
131+
index as _,
132+
chunk_info.offset.as_mut_ptr(),
133+
&mut chunk_info.filter_mask,
134+
&mut chunk_info.addr,
135+
&mut chunk_info.size,
136+
))
137+
.map(|_| chunk_info)
138+
.ok()
139+
}))
140+
}
141+
80142
/// Returns the chunk shape if the dataset is chunked.
81143
pub fn chunks(&self) -> Option<Vec<Ix>> {
82144
h5lock!({

src/hl/datatype.rs

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ use std::fmt::{self, Debug, Display};
44
use std::ops::Deref;
55

66
use hdf5_sys::h5t::{
7-
H5T_cdata_t, H5T_class_t, H5T_cset_t, H5T_str_t, H5Tarray_create2, H5Tcompiler_conv, H5Tcopy,
8-
H5Tcreate, H5Tenum_create, H5Tenum_insert, H5Tequal, H5Tfind, H5Tget_array_dims2,
9-
H5Tget_array_ndims, H5Tget_class, H5Tget_cset, H5Tget_member_name, H5Tget_member_offset,
10-
H5Tget_member_type, H5Tget_member_value, H5Tget_nmembers, H5Tget_sign, H5Tget_size,
11-
H5Tget_super, H5Tinsert, H5Tis_variable_str, H5Tset_cset, H5Tset_size, H5Tset_strpad,
12-
H5Tvlen_create, H5T_VARIABLE,
7+
H5T_cdata_t, H5T_class_t, H5T_cset_t, H5T_order_t, H5T_str_t, H5Tarray_create2,
8+
H5Tcompiler_conv, H5Tcopy, H5Tcreate, H5Tenum_create, H5Tenum_insert, H5Tequal, H5Tfind,
9+
H5Tget_array_dims2, H5Tget_array_ndims, H5Tget_class, H5Tget_cset, H5Tget_member_name,
10+
H5Tget_member_offset, H5Tget_member_type, H5Tget_member_value, H5Tget_nmembers, H5Tget_order,
11+
H5Tget_sign, H5Tget_size, H5Tget_super, H5Tinsert, H5Tis_variable_str, H5Tset_cset,
12+
H5Tset_size, H5Tset_strpad, H5Tvlen_create, H5T_VARIABLE,
1313
};
1414
use hdf5_types::{
1515
CompoundField, CompoundType, EnumMember, EnumType, FloatSize, H5Type, IntSize, TypeDescriptor,
@@ -119,12 +119,51 @@ impl Default for Conversion {
119119
}
120120
}
121121

122+
#[derive(Copy, Debug, Clone, PartialEq, Eq)]
123+
pub enum ByteOrder {
124+
LittleEndian,
125+
BigEndian,
126+
Vax,
127+
Mixed,
128+
None,
129+
}
130+
131+
#[cfg(hdf5_1_8_6)]
132+
impl From<H5T_order_t> for ByteOrder {
133+
fn from(order: H5T_order_t) -> Self {
134+
match order {
135+
H5T_order_t::H5T_ORDER_LE => ByteOrder::LittleEndian,
136+
H5T_order_t::H5T_ORDER_BE => ByteOrder::BigEndian,
137+
H5T_order_t::H5T_ORDER_VAX => ByteOrder::Vax,
138+
H5T_order_t::H5T_ORDER_MIXED => ByteOrder::Mixed,
139+
_ => ByteOrder::None,
140+
}
141+
}
142+
}
143+
144+
#[cfg(not(hdf5_1_8_6))]
145+
impl From<H5T_order_t> for ByteOrder {
146+
fn from(order: H5T_order_t) -> Self {
147+
match order {
148+
H5T_order_t::H5T_ORDER_LE => ByteOrder::LittleEndian,
149+
H5T_order_t::H5T_ORDER_BE => ByteOrder::BigEndian,
150+
H5T_order_t::H5T_ORDER_VAX => ByteOrder::Vax,
151+
_ => ByteOrder::None,
152+
}
153+
}
154+
}
155+
122156
impl Datatype {
123157
/// Get the total size of the datatype in bytes.
124158
pub fn size(&self) -> usize {
125159
h5call!(H5Tget_size(self.id())).unwrap_or(0) as usize
126160
}
127161

162+
/// Get the byte order of the datatype.
163+
pub fn byte_order(&self) -> ByteOrder {
164+
h5lock!(H5Tget_order(self.id())).into()
165+
}
166+
128167
pub fn conv_path<D>(&self, dst: D) -> Option<Conversion>
129168
where
130169
D: Borrow<Self>,

0 commit comments

Comments
 (0)