TlvWriter

Struct TlvWriter 

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

TLV encoder backed by a growable BytesMut buffer.

Implementations§

Source§

impl TlvWriter

Source

pub fn new() -> Self

Source

pub fn with_capacity(cap: usize) -> Self

Source

pub fn write_tlv(&mut self, typ: u64, value: &[u8])

Write a flat TLV element (type + length + value bytes).

Source

pub fn write_nested<F>(&mut self, typ: u64, f: F)
where F: FnOnce(&mut TlvWriter),

Write a nested TLV element. The closure encodes the inner content; this method wraps it with the correct outer type and length.

Inner content is written to a temporary writer, then the type, minimal length, and content are appended to the main buffer.

Source

pub fn write_varu64(&mut self, value: u64)

Write a raw VarNumber (type or length field) without TLV framing.

Source

pub fn write_raw(&mut self, data: &[u8])

Write raw bytes directly into the buffer (no TLV framing).

Used when embedding a pre-encoded signed region into an outer TLV.

Source

pub fn slice_from(&self, start: usize) -> &[u8]

Return a zero-copy view of the bytes written since start offset.

Used to read back a signed region written incrementally — e.g. to pass it to a signing function or to copy it into an outer TLV. No allocation.

Source

pub fn snapshot(&self, start: usize) -> Vec<u8>

👎Deprecated: use slice_from for a zero-copy &u8

Return a copy of the bytes written since start offset.

Prefer [slice_from] when a borrowed slice is sufficient.

Source

pub fn finish(self) -> Bytes

Freeze and return the encoded bytes.

Source

pub fn len(&self) -> usize

Current encoded length in bytes.

Source

pub fn is_empty(&self) -> bool

Trait Implementations§

Source§

impl Default for TlvWriter

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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.