Skip to main content

hdf5_reader/messages/
continuation.rs

1//! HDF5 Header Continuation message (type 0x0010).
2//!
3//! Indicates that additional header messages are stored at another location
4//! in the file. The parser follows these to read the complete object header.
5
6use crate::error::Result;
7use crate::io::Cursor;
8
9/// Parsed continuation message.
10#[derive(Debug, Clone)]
11pub struct ContinuationMessage {
12    /// Absolute file offset of the continuation block.
13    pub offset: u64,
14    /// Length in bytes of the continuation block.
15    pub length: u64,
16}
17
18/// Parse a header continuation message.
19pub fn parse(
20    cursor: &mut Cursor<'_>,
21    offset_size: u8,
22    length_size: u8,
23    _msg_size: usize,
24) -> Result<ContinuationMessage> {
25    let offset = cursor.read_offset(offset_size)?;
26    let length = cursor.read_length(length_size)?;
27
28    Ok(ContinuationMessage { offset, length })
29}
30
31#[cfg(test)]
32mod tests {
33    use super::*;
34
35    #[test]
36    fn test_parse_continuation() {
37        let mut data = Vec::new();
38        data.extend_from_slice(&0x4000u64.to_le_bytes());
39        data.extend_from_slice(&256u64.to_le_bytes());
40
41        let mut cursor = Cursor::new(&data);
42        let msg = parse(&mut cursor, 8, 8, data.len()).unwrap();
43        assert_eq!(msg.offset, 0x4000);
44        assert_eq!(msg.length, 256);
45    }
46}