pub struct NodeStream<'a> { /* private fields */ }Expand description
A cursor over one node’s wire bytes; see the module docs.
Implementations§
Source§impl<'a> NodeStream<'a>
impl<'a> NodeStream<'a>
Sourcepub fn from_packed(packed: &'a [u8]) -> Result<Self>
pub fn from_packed(packed: &'a [u8]) -> Result<Self>
A stream over a packed payload: the format byte and, behind it, node bytes that are inflated on demand when the byte says they are compressed.
This is what the receive path holds after decryption. A compressed payload checks out the thread’s pooled inflate state for the life of the stream.
Sourcepub fn from_node_bytes(node_bytes: &'a [u8]) -> Self
pub fn from_node_bytes(node_bytes: &'a [u8]) -> Self
A stream over node bytes already in memory (no format byte): the
buffer behind an OwnedNodeRef, for a consumer
that walks a node it was handed whole.
Sourcepub fn is_compressed(&self) -> bool
pub fn is_compressed(&self) -> bool
Whether the bytes are being inflated as they are read.
Sourcepub fn open(&mut self) -> Result<Option<OpenNode<'_>>>
pub fn open(&mut self) -> Result<Option<OpenNode<'_>>>
Decode the head of the next node and descend into it.
At depth 0 that is the root; inside an open node it is that node’s next
child, which then becomes the open node. None when the open node has
no children left (or, at depth 0, once the root has been read).
Sourcepub fn next_child(&mut self) -> Result<Option<NodeRef<'_>>>
pub fn next_child(&mut self) -> Result<Option<NodeRef<'_>>>
Decode the open node’s next child whole, subtree and all.
None once the open node has no children left, or at depth 0 once the
root has been read.
Sourcepub fn close(&mut self) -> Result<()>
pub fn close(&mut self) -> Result<()>
Leave the open node, decoding and discarding any children not yet read, so the cursor stands at the parent’s next child.
Sourcepub fn finish(&mut self) -> Result<()>
pub fn finish(&mut self) -> Result<()>
Consume everything after the cursor and check that the bytes end where the node does: nothing left over behind the root, and for a compressed payload a properly terminated stream (the checksum in the trailer is what says every inflated byte was the one the peer sent).
The strictness unmarshal_ref applies to a tree
(it rejects leftover data), applied to a stream that was only partly
read. Only worth calling once what was wanted has been read: a stream
abandoned on a parse error is simply dropped.
Sourcepub fn into_inflated(self) -> Option<Result<Vec<u8>>>
pub fn into_inflated(self) -> Option<Result<Vec<u8>>>
The whole node as one buffer, the way unpack
would have produced it, for a caller that looked at the root’s head and
decided the node is one to hold as a tree after all.
Only for a compressed payload, and only before anything was consumed
(an open of the root consumes nothing until the next
call): the bytes of a plain payload are the caller’s own, and a
consumed prefix is gone. Both return None.