pub struct TlvWriter { /* private fields */ }Expand description
TLV encoder backed by a growable BytesMut buffer.
Implementations§
Source§impl TlvWriter
impl TlvWriter
pub fn new() -> Self
pub fn with_capacity(cap: usize) -> Self
Sourcepub fn write_tlv(&mut self, typ: u64, value: &[u8])
pub fn write_tlv(&mut self, typ: u64, value: &[u8])
Write a flat TLV element (type + length + value bytes).
Sourcepub fn write_nested<F>(&mut self, typ: u64, f: F)
pub fn write_nested<F>(&mut self, typ: u64, f: F)
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.
Sourcepub fn write_varu64(&mut self, value: u64)
pub fn write_varu64(&mut self, value: u64)
Write a raw VarNumber (type or length field) without TLV framing.
Sourcepub fn write_raw(&mut self, data: &[u8])
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.
Sourcepub fn slice_from(&self, start: usize) -> &[u8] ⓘ
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.
Sourcepub fn snapshot(&self, start: usize) -> Vec<u8> ⓘ
👎Deprecated: use slice_from for a zero-copy &u8
pub fn snapshot(&self, start: usize) -> Vec<u8> ⓘ
Return a copy of the bytes written since start offset.
Prefer [slice_from] when a borrowed slice is sufficient.