pub struct EncodeBuf { /* private fields */ }Expand description
Buffer for BER encoding that writes backwards.
This approach avoids needing to pre-calculate content lengths: we write the content first, then prepend the length and tag.
Implementations§
Source§impl EncodeBuf
impl EncodeBuf
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new encode buffer with specified capacity.
Sourcepub fn push_bytes(&mut self, bytes: &[u8])
pub fn push_bytes(&mut self, bytes: &[u8])
Push multiple bytes (prepends to front, reversed).
Sourcepub fn push_bytes_raw(&mut self, bytes: &[u8])
pub fn push_bytes_raw(&mut self, bytes: &[u8])
Push bytes without reversing (for content that’s already in correct order).
Sourcepub fn push_length(&mut self, len: usize)
pub fn push_length(&mut self, len: usize)
Push a BER length encoding.
Sourcepub fn push_constructed<F>(&mut self, tag: u8, f: F)where
F: FnOnce(&mut Self),
pub fn push_constructed<F>(&mut self, tag: u8, f: F)where
F: FnOnce(&mut Self),
Encode a constructed type (SEQUENCE, PDU, etc).
Calls the closure to encode contents, then wraps with length and tag.
Sourcepub fn push_sequence<F>(&mut self, f: F)where
F: FnOnce(&mut Self),
pub fn push_sequence<F>(&mut self, f: F)where
F: FnOnce(&mut Self),
Encode a SEQUENCE.
Sourcepub fn push_integer(&mut self, value: i32)
pub fn push_integer(&mut self, value: i32)
Encode an INTEGER.
Sourcepub fn push_integer64(&mut self, value: u64)
pub fn push_integer64(&mut self, value: u64)
Encode a 64-bit integer (for Counter64).
Sourcepub fn push_unsigned32(&mut self, tag: u8, value: u32)
pub fn push_unsigned32(&mut self, tag: u8, value: u32)
Encode an unsigned 32-bit integer with a specific tag.
Sourcepub fn push_octet_string(&mut self, data: &[u8])
pub fn push_octet_string(&mut self, data: &[u8])
Encode an OCTET STRING.
Sourcepub fn push_ip_address(&mut self, addr: [u8; 4])
pub fn push_ip_address(&mut self, addr: [u8; 4])
Encode an IP address.
Sourcepub fn finish(self) -> Bytes
pub fn finish(self) -> Bytes
Finalize and return the encoded bytes.
The buffer is reversed to produce the correct order.
Sourcepub fn finish_vec(self) -> Vec<u8> ⓘ
pub fn finish_vec(self) -> Vec<u8> ⓘ
Finalize and return as Vec<u8>.