Skip to main content

ObjectHeader

Struct ObjectHeader 

Source
pub struct ObjectHeader {
    pub flags: u8,
    pub times: Option<ObjectTimes>,
    pub messages: Vec<ObjectHeaderMessage>,
}
Expand description

Object Header v2.

Fields§

§flags: u8

Header flags byte. Bits 0-1 control chunk0 size encoding. Other bits control optional fields (attr thresholds, creation order).

Bit 5 (H5O_HDR_STORE_TIMES) is not held here: it is derived from times at encode and stripped at decode, so the flag and the four values it announces cannot disagree. Setting it by hand here does nothing — the encoder’s flag byte comes from times.

§times: Option<ObjectTimes>

The stored times, when this object tracks them.

§messages: Vec<ObjectHeaderMessage>

The ordered list of header messages.

Implementations§

Source§

impl ObjectHeader

Source

pub fn new() -> Self

Create a new, empty object header with default flags.

Defaults: bits 0-1 = 2 (4-byte chunk size encoding), no timestamps, no attribute creation order, no non-default thresholds.

Source

pub fn recorded_times(&self) -> Option<ObjectTimes>

The times this header records, wherever its version keeps them.

One answer for both versions, which store a different number of times in different places: version 2 keeps all four in the prefix under H5O_HDR_STORE_TIMES, and version 1 keeps at most one, in an H5O_MTIME_NEW message. None means the object was created with H5Pset_obj_track_times(false) — or is a version-1 group or committed datatype, whose header has nowhere to record a time even while the property is on, since only H5D__update_oh_info calls H5O_touch_oh with the force that creates the message (H5Dint.c:1022-1026).

The one time a version-1 header stores fills all four fields. Only ObjectTimes::change is written back for that version — it is the field H5O_touch_oh moves to now on both versions (H5Oint.c:1290-1345) — so the other three are there to keep one struct across both versions rather than to claim the file said anything about them.

Source

pub fn add_message(&mut self, msg_type: u8, flags: u8, data: Vec<u8>)

Append a message to the object header.

Source

pub fn add_message_indexed( &mut self, msg_type: u8, flags: u8, data: Vec<u8>, creation_index: u16, )

Append a message carrying a creation index.

The index reaches the file only when the header’s flags bit 2 says the creation order is tracked; libhdf5 does not encode the field otherwise (H5O_SIZEOF_MSGHDR_OH).

Source

pub fn set_attribute_creation_order(&mut self, order: CreationOrder)

Declare order as this object’s attribute creation-order policy.

H5Pget_attr_creation_order reads these two bits back out of the header, not out of the Attribute Info message (H5Pocpl.c), so they are what makes an object report its attributes as creation-ordered. Setting TRACKED also widens every message envelope by the two-byte creation index.

Source

pub fn attribute_creation_order(&self) -> CreationOrder

This object’s attribute creation-order policy, as its flag bits declare it — the reverse of set_attribute_creation_order, and what a reopen must consult so a rewrite re-declares what the file already says.

Source

pub fn has_creation_order(&self) -> bool

Whether attribute creation order tracking is enabled (flags bit 2).

Source

pub fn message_envelope_size(&self) -> usize

Bytes a message envelope takes: type, size and flags, plus the creation index when this header tracks one (H5O_SIZEOF_MSGHDR_OH).

Source

pub fn encode(&self) -> FormatResult<Vec<u8>>

Encode the object header to a byte vector, including “OHDR” signature and trailing checksum, with every message in chunk 0.

Fails when any message payload exceeds MAX_MESSAGE_SIZE — see check_message_sizes.

Source

pub fn plan_chunks( &self, capacity: usize, ctx: &FormatContext, ) -> FormatResult<ChunkPlan>

How this header divides between chunk 0 and its continuation chunk when chunk 0’s message area holds at most capacity bytes.

The whole point of a plan is that both sizes are known before either chunk has an address: the caller allocates the continuation from continuation_size and hands the address back to encode_chunked, which is the only way chunk 0 can name a block that does not exist yet.

Messages fill chunk 0 in order and the rest go to the continuation, so a message never moves ahead of one that was written before it.

Source

pub fn encode_chunked( &self, plan: &ChunkPlan, ctx: &FormatContext, continuation_addr: u64, ) -> FormatResult<(Vec<u8>, Option<Vec<u8>>)>

Encode this header as plan divides it, with the continuation chunk at continuation_addr.

Returns chunk 0 and, when the plan spills, the continuation chunk’s image. continuation_addr is ignored for a plan that does not spill.

Source

pub fn decode(buf: &[u8]) -> FormatResult<(Self, usize)>

Decode an object header from a byte buffer. Returns the parsed header and the number of bytes consumed from the buffer.

Source§

impl ObjectHeader

Source

pub fn encode_v1(&self, nlink: u32) -> FormatResult<Vec<u8>>

Encode this header in the version-1 format, with nlink as the object reference count.

The differences from encode are all H5O_ALIGN_OLD’s doing: no signature and no checksum, a two-byte message type, three reserved bytes where version 2 puts the optional creation index, and every message body padded out to eight bytes with the padded length in the size field (H5O_msg_flush writes mesg->raw_size, which H5O__alloc already aligned). The message count is the count of messages in the whole header, and this writer emits one chunk, so it is self.messages.len().

Refuses a header carrying attribute-creation-order flags: those bits live in the version-2 flags byte, which version 1 does not have, so encoding such a header would silently drop the policy the caller set.

Refuses a header carrying times for the same reason. The four times and the H5O_HDR_STORE_TIMES bit that announces them are version-2 prefix fields; a version-1 header records at most a modification time, in an H5O_MTIME_NEW message among the messages below. Refusing keeps the version gate at the one encoder that knows which prefix it is writing, instead of letting a v2-shaped header reach encode_v1 and come back out with its times gone.

Source

pub fn encode_for( &self, format: ObjectFormat, nlink: u32, ) -> FormatResult<Vec<u8>>

Encode this header in the version format calls for.

nlink reaches the file only in the version-1 layout; the version-2 header has no reference-count field (an object with more than one hard link carries an Object Reference Count message instead).

Source§

impl ObjectHeader

Source

pub fn decode_v1(buf: &[u8]) -> FormatResult<(Self, usize)>

Decode a v1 object header from a byte buffer.

v1 headers do NOT have the “OHDR” signature or a checksum. The layout is:

Byte 0: version = 1
Byte 1: reserved
Bytes 2-3: num_messages (u16 LE)
Bytes 4-7: obj_ref_count (u32 LE)
Bytes 8-11: header_data_size (u32 LE) — size of message data in first chunk
Messages follow, each:
  type: u16 LE
  data_size: u16 LE
  flags: u8
  reserved: 3 bytes
  data: data_size bytes (padded to 8-byte alignment)
Source

pub fn decode_any(buf: &[u8]) -> FormatResult<(Self, usize)>

Auto-detect and decode either v1 or v2 object header.

Checks for the “OHDR” signature to decide v2; otherwise tries v1.

Trait Implementations§

Source§

impl Clone for ObjectHeader

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ObjectHeader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ObjectHeader

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for ObjectHeader

Source§

impl PartialEq for ObjectHeader

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ObjectHeader

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.