TlvReader

Struct TlvReader 

Source
pub struct TlvReader { /* private fields */ }
Expand description

Zero-copy TLV reader over a Bytes buffer.

Every slice returned by this reader is a sub-slice of the original Bytes, sharing the same reference-counted allocation — no copies.

Implementations§

Source§

impl TlvReader

Source

pub fn new(buf: Bytes) -> Self

Source

pub fn remaining(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn position(&self) -> usize

Current byte position within the original buffer.

Source

pub fn read_type(&mut self) -> Result<u64, TlvError>

Read the next TLV type code.

Source

pub fn read_length(&mut self) -> Result<usize, TlvError>

Read the next TLV length field.

Source

pub fn read_bytes(&mut self, len: usize) -> Result<Bytes, TlvError>

Read exactly len bytes as a zero-copy Bytes slice.

Source

pub fn read_tlv(&mut self) -> Result<(u64, Bytes), TlvError>

Read a complete TLV element: returns (type, value_bytes).

Source

pub fn peek_type(&self) -> Result<u64, TlvError>

Peek at the next TLV type without advancing the position.

Source

pub fn skip_unknown(&mut self, typ: u64) -> Result<(), TlvError>

Skip an unknown TLV element, respecting the critical-bit rule.

Types 0–31 are always critical (grandfathered, NDN Packet Format v0.3 §1.3). For types >= 32, odd numbers are critical and even are non-critical.

Source

pub fn scoped(&mut self, len: usize) -> Result<TlvReader, TlvError>

Return a sub-reader scoped to len bytes from the current position.

Source

pub fn as_bytes(&self) -> Bytes

Return the full remaining buffer as a Bytes slice without advancing.

Auto Trait Implementations§

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> 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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.