Skip to main content

Module stream

Module stream 

Source
Expand description

Incremental decoding of one node: a cursor that walks a node’s children one at a time instead of building the whole tree.

The tree decoder (unmarshal_ref, OwnedNodeRef) needs every decompressed byte of a node in memory at once and one heap object per node and attribute list. For a stanza of a few thousand small children that is more memory than the payload by an order of magnitude, and on a microcontroller it is more memory than there is. A NodeStream decodes the same wire format from a source that produces bytes on demand, so a caller that wants a handful of children out of thousands keeps one child, and one inflate window, alive at a time.

The cursor moves through a node the way the bytes are laid out: open reads the head of the next node (tag, attributes, what its content is) and descends into it; next_child decodes the next child whole; close leaves the open node, skipping any children not yet read. What comes back borrows the stream’s buffer and is valid until the next call.

Structs§

NodeStream
A cursor over one node’s wire bytes; see the module docs.
OpenNode
The head of a node the stream has descended into.