Skip to main content

NodeStream

Struct NodeStream 

Source
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>

Source

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.

Source

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.

Source

pub fn is_compressed(&self) -> bool

Whether the bytes are being inflated as they are read.

Source

pub fn depth(&self) -> usize

How deep the cursor is: 0 before the root is opened, 1 inside it.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for NodeStream<'a>

§

impl<'a> Forget for NodeStream<'a>

§

impl<'a> Freeze for NodeStream<'a>
where &'a [u8]: Freeze, *mut u8: Freeze, *mut i8: Freeze, &'static mut State<'static>: Freeze, *mut c_void: Freeze, PhantomData<&'static ()>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, PhantomData<Level>: Freeze,

§

impl<'a> Move for NodeStream<'a>

§

impl<'a> RefUnwindSafe for NodeStream<'a>

§

impl<'a> Send for NodeStream<'a>
where &'a [u8]: Send, InflateStream<'static>: Send, RawVecInner: Send,

§

impl<'a> Sync for NodeStream<'a>
where InflateStream<'static>: Sync, RawVecInner: Sync,

§

impl<'a> Unpin for NodeStream<'a>
where &'a [u8]: Unpin, *mut u8: Unpin, *mut i8: Unpin, &'static mut State<'static>: Unpin, *mut c_void: Unpin, &'static (): Unpin, *const u8 is !null: Unpin,

§

impl<'a> UnsafeUnpin for NodeStream<'a>

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> ErasedDestructor for T
where T: 'static,

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, 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.