pub struct OwnedNodeRef { /* private fields */ }Expand description
A decoded node that owns its decompressed buffer. The inner NodeRef
borrows string/byte payloads directly from the buffer, avoiding copies.
Container allocations (attribute Vec, child Vec) still occur during decode.
Wrap in Arc<OwnedNodeRef> for cheap sharing across handlers.
Implementations§
Source§impl OwnedNodeRef
impl OwnedNodeRef
Sourcepub fn new(buffer: impl Into<Bytes>) -> Result<Self>
pub fn new(buffer: impl Into<Bytes>) -> Result<Self>
Decode a node from an owned buffer of node bytes: after decompression and
without the format byte, which unpack strips.
A buffer that still carries it goes through unpack first.
Sourcepub fn to_owned_node(&self) -> Node
pub fn to_owned_node(&self) -> Node
Convert to an owned Node, cloning all data out of the buffer.
Use sparingly — this is the allocation path that yoke is designed to avoid.
Sourcepub fn backing_bytes(&self) -> Bytes
pub fn backing_bytes(&self) -> Bytes
The whole backing buffer, verbatim: exactly what Self::new consumed.
A refcount bump, not a copy — the yoke already retains this buffer, and
Self::slice_bytes hands out views into the same allocation.
These are node bytes, so they are not a sendable frame: send paths
take a packed payload, one format byte in front of the node bytes, which
unpack stripped on the way in. Put it back with
pack before forwarding these bytes anywhere that
expects marshal output.
Re-encoding through marshal_ref is the alternative and a worse one
for anything that forwards a stanza onward — to another process, a
recording, a replay harness. Re-encoding costs a second pass and is only
faithful while the token dictionaries match the ones that decoded it;
these bytes stay true whatever the dictionaries do.
Sourcepub fn slice_bytes(&self, slice: &[u8]) -> Bytes
pub fn slice_bytes(&self, slice: &[u8]) -> Bytes
Return a zero-copy Bytes sub-view for a slice that borrows from this
node’s backing buffer. Panics if slice does not point within the buffer.
Sourcepub fn attrs(&self) -> AttrParserRef<'_>
pub fn attrs(&self) -> AttrParserRef<'_>
Get an attribute parser for this node.
Sourcepub fn get_optional_child(&self, tag: &str) -> Option<&NodeRef<'_>>
pub fn get_optional_child(&self, tag: &str) -> Option<&NodeRef<'_>>
Find a child node by tag.
Sourcepub fn get_optional_child_by_tag(&self, tags: &[&str]) -> Option<&NodeRef<'_>>
pub fn get_optional_child_by_tag(&self, tags: &[&str]) -> Option<&NodeRef<'_>>
Find a child by traversing a path of tags.
Sourcepub fn get_children_by_tag<'b>(
&'b self,
tag: &'b str,
) -> impl Iterator<Item = &'b NodeRef<'b>>
pub fn get_children_by_tag<'b>( &'b self, tag: &'b str, ) -> impl Iterator<Item = &'b NodeRef<'b>>
Get children matching a tag.
Sourcepub fn content_bytes(&self) -> Option<&[u8]>
pub fn content_bytes(&self) -> Option<&[u8]>
Zero-copy byte content, if this node has Bytes content.
Sourcepub fn content_str(&self) -> Option<&str>
pub fn content_str(&self) -> Option<&str>
Zero-copy string content, if this node has String content.
Sourcepub fn content_nodes(&self) -> Option<&[NodeRef<'_>]>
pub fn content_nodes(&self) -> Option<&[NodeRef<'_>]>
Child nodes from content, if this node has Nodes content.
Sourcepub fn content_as_string(&self) -> Option<CompactString>
pub fn content_as_string(&self) -> Option<CompactString>
Extract text content, handling both String and Bytes (lossy UTF-8).