Skip to main content

Tlv8Writer

Struct Tlv8Writer 

Source
pub struct Tlv8Writer<'a> { /* private fields */ }
Expand description

A TLV8 encoder that appends to a borrowed Vec<u8>.

The writer borrows the output buffer mutably for its lifetime; drop the writer to release the borrow.

Implementations§

Source§

impl<'a> Tlv8Writer<'a>

Source

pub fn new(out: &'a mut Vec<u8>) -> Self

Construct a writer that appends to out.

Source

pub fn push(&mut self, ty: u8, value: &[u8])

Write a logical value as one or more TLV8 items, fragmenting any value longer than 255 bytes into consecutive items of the same type.

A 255-byte item means “more of this type follows”, so when the value’s length is a non-zero exact multiple of 255 a terminating zero-length item of the same type is appended to mark the end of the run. The matching reader (crate::Tlv8Reader::parse) reverses this.

Source

pub fn push_u8(&mut self, ty: u8, v: u8)

Write an unsigned 8-bit integer as a 1-byte item.

Source

pub fn push_u16(&mut self, ty: u8, v: u16)

Write an unsigned 16-bit integer as a 2-byte little-endian item.

Source

pub fn push_u32(&mut self, ty: u8, v: u32)

Write an unsigned 32-bit integer as a 4-byte little-endian item.

Source

pub fn push_u64(&mut self, ty: u8, v: u64)

Write an unsigned 64-bit integer as an 8-byte little-endian item.

Source

pub fn push_str(&mut self, ty: u8, v: &str)

Write a string as its UTF-8 bytes. Long strings fragment via push.

Source

pub fn push_separator(&mut self)

Write a zero-length separator item (crate::SEPARATOR, 0xFF) used to delimit repeated structures such as a list of pairings.

Auto Trait Implementations§

§

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

§

impl<'a> Freeze for Tlv8Writer<'a>

§

impl<'a> RefUnwindSafe for Tlv8Writer<'a>

§

impl<'a> Send for Tlv8Writer<'a>

§

impl<'a> Sync for Tlv8Writer<'a>

§

impl<'a> Unpin for Tlv8Writer<'a>

§

impl<'a> UnsafeUnpin for Tlv8Writer<'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> 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.