Skip to main content

hurray_file_writer_write_composite

Function hurray_file_writer_write_composite 

Source
#[unsafe(no_mangle)]
pub unsafe extern "C" fn hurray_file_writer_write_composite( handle: *mut HurrayFileWriter, nodes: *const HurrayCompositeNode, count: usize, ) -> HurrayStatus
Expand description

Writes a composite: its head, then every member in order, each with its own name and its own footer-index entry.

nodes is the composite in preorder: nodes[0] is the head, and each node declares how many of the nodes after it are its direct members. crate::composite has the shape and an example layout. Unlike the stream surface, every node’s name is required — a reader recovers membership from the head’s member_count and the file order of the entries after it, so each tensor needs an entry to be found by.

The whole tree is validated and flattened into write order before a byte goes out, so an invalid composite never reaches the sink.

Returns:

  • HURRAY_OK — the composite is entirely written and the payload pointers are no longer held.
  • HURRAY_ERR_NOT_COMPOSITE — count is 0, or nodes[0] is not a composite head. Use hurray_file_writer_write_tensor for a tensor.
  • HURRAY_ERR_INDEX_OUT_OF_BOUNDS — the member counts do not describe the array: a head declares members the array does not carry, or nodes trail after the head’s subtree is complete.
  • HURRAY_ERR_INVALID_FILE — a name is empty, too long, or already used in this file. The head’s name is checked before any byte goes out, so the file is still completable; a member’s name is checked when that member is submitted, by which point the head is on the sink, so the writer is poisoned — the group can no longer be completed and no index may be written over it. Check names before calling if that distinction matters.
  • HURRAY_ERR_INVALID_LAYOUT — the tree is not a valid composite: a member count that disagrees with its head, a partition that does not cover its index space, an overlay whose base is not first.
  • HURRAY_ERR_SINK_CLOSED — the sink stopped accepting bytes, or a write callback failed, once part of the group was already out. The writer is poisoned: a head with fewer members after it than it declares is not a file any reader may open, and a forward-only writer cannot go back to fix it.
  • Whatever status the write callback returned, if it failed before any byte of the group reached the sink. Nothing was emitted, so the call MAY be retried and the file is still completable (ADR-041 § 6b).

§Safety

  • handle MUST point to a live HurrayFileWriter.
  • If count is non-zero, nodes MUST point to count readable HurrayCompositeNode values, each satisfying that type’s own pointer contract.
  • All of that memory MUST stay valid and unmodified until this call returns.