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>
impl<'a> Tlv8Writer<'a>
Sourcepub fn push(&mut self, ty: u8, value: &[u8])
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.
Sourcepub fn push_u16(&mut self, ty: u8, v: u16)
pub fn push_u16(&mut self, ty: u8, v: u16)
Write an unsigned 16-bit integer as a 2-byte little-endian item.
Sourcepub fn push_u32(&mut self, ty: u8, v: u32)
pub fn push_u32(&mut self, ty: u8, v: u32)
Write an unsigned 32-bit integer as a 4-byte little-endian item.
Sourcepub fn push_u64(&mut self, ty: u8, v: u64)
pub fn push_u64(&mut self, ty: u8, v: u64)
Write an unsigned 64-bit integer as an 8-byte little-endian item.
Sourcepub fn push_str(&mut self, ty: u8, v: &str)
pub fn push_str(&mut self, ty: u8, v: &str)
Write a string as its UTF-8 bytes. Long strings fragment via push.
Sourcepub fn push_separator(&mut self)
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.