pub struct Formatter<'b> { /* private fields */ }Expand description
A TTLV formatter.
§Panics
TTLV uses 32-bit fields to express the size of serialized data, in units of
bytes. To guarantee panic-free operation, only the first 4GiB of a given
input buffer will be used. A write that would overflow a length field is
guaranteed to return TruncationError instead.
Implementations§
Source§impl<'b> Formatter<'b>
impl<'b> Formatter<'b>
Sourcepub const fn new(buffer: &'b mut [MaybeUninit<u8>]) -> Self
pub const fn new(buffer: &'b mut [MaybeUninit<u8>]) -> Self
Construct a new Formatter.
The input will be truncated to the first 4GiB, and to a multiple of 8 bytes, as per limitations of the TTLV format. It should ideally be aligned to an 8-byte address boundary (for better performance).
Sourcepub const unsafe fn from_raw_parts(
buffer: &'b mut [MaybeUninit<[u8; 8]>],
position: usize,
) -> Self
pub const unsafe fn from_raw_parts( buffer: &'b mut [MaybeUninit<[u8; 8]>], position: usize, ) -> Self
pub fn clear(&mut self)
Sourcepub fn filled_mut(&mut self) -> &mut [[u8; 8]]
pub fn filled_mut(&mut self) -> &mut [[u8; 8]]
The filled part of the buffer, mutably.
Sourcepub fn remaining(&mut self) -> &mut [MaybeUninit<[u8; 8]>]
pub fn remaining(&mut self) -> &mut [MaybeUninit<[u8; 8]>]
The remaining part of the buffer.
Sourcepub const fn into_raw_parts(self) -> (&'b mut [MaybeUninit<[u8; 8]>], usize)
pub const fn into_raw_parts(self) -> (&'b mut [MaybeUninit<[u8; 8]>], usize)
Source§impl<'b> Formatter<'b>
impl<'b> Formatter<'b>
Sourcepub fn format_struct(
&mut self,
tag: Tag,
) -> Result<FieldFormatter<'_>, TruncationError>
pub fn format_struct( &mut self, tag: Tag, ) -> Result<FieldFormatter<'_>, TruncationError>
Format a structure.
The returned sub-formatter should be used to format the fields of the
struct; once it is finished, self can continue.
Sourcepub fn format_int(&mut self, tag: Tag, value: i32) -> FormatResult
pub fn format_int(&mut self, tag: Tag, value: i32) -> FormatResult
Format an integer.
Sourcepub fn format_long_int(&mut self, tag: Tag, value: i64) -> FormatResult
pub fn format_long_int(&mut self, tag: Tag, value: i64) -> FormatResult
Format a long integer.
Sourcepub fn format_big_int(&mut self, tag: Tag, value: &[u8]) -> FormatResult
pub fn format_big_int(&mut self, tag: Tag, value: &[u8]) -> FormatResult
Format a big integer.
value should be the bytewise digits of a signed (two’s complement)
big-endian integer. It will be padded (with leading sign-extension
bytes) into a multiple of 8 bytes before being stored.
§Panics
Panics if the length of value (when rounded up to a multiple of 8
bytes) does not fit in a u32.
Sourcepub fn format_enum(&mut self, tag: Tag, value: u32) -> FormatResult
pub fn format_enum(&mut self, tag: Tag, value: u32) -> FormatResult
Format an enumeration.
Sourcepub fn format_bool(&mut self, tag: Tag, value: bool) -> FormatResult
pub fn format_bool(&mut self, tag: Tag, value: bool) -> FormatResult
Format a boolean.
Sourcepub fn format_text(&mut self, tag: Tag, value: &str) -> FormatResult
pub fn format_text(&mut self, tag: Tag, value: &str) -> FormatResult
Format a text string.
Sourcepub fn format_bytes(&mut self, tag: Tag, value: &[u8]) -> FormatResult
pub fn format_bytes(&mut self, tag: Tag, value: &[u8]) -> FormatResult
Format a byte string.
Sourcepub fn format_date_time(&mut self, tag: Tag, value: i64) -> FormatResult
pub fn format_date_time(&mut self, tag: Tag, value: i64) -> FormatResult
Format a date-time.
Sourcepub fn format_interval(&mut self, tag: Tag, value: u32) -> FormatResult
pub fn format_interval(&mut self, tag: Tag, value: u32) -> FormatResult
Format an interval.