Skip to main content

hurray_writer_write_composite

Function hurray_writer_write_composite 

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

Writes a composite — its head, then every member, nested ones included — as one item.

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; names are ignored here, because the stream wire carries none.

The whole tree is validated before a byte reaches the sink — member counts at every level, partition exact-cover, overlay base-first ordering — so an invalid composite is refused rather than half written. Payload slices stay borrowed throughout: nothing is copied or concatenated (ADR-041 § 3).

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_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_LAYOUT — the tree is not a valid composite: a head that is not one, a member count that disagrees with the head, a partition that does not cover its index space, an overlay whose base is not first. Refused before a byte moved, so the writer stays usable.
  • HURRAY_ERR_SINK_CLOSED — the sink stopped accepting bytes mid-composite, so a truncated item is on the wire and the writer is poisoned. A composite is one item: there is no partially valid composite to resume from.
  • Whatever status the write callback returned, if it failed before any byte of this composite reached the sink. Nothing was emitted, so the call MAY be retried.

§Safety

  • handle MUST point to a live HurrayWriter.
  • 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.