pub struct ByteWriter<'a> { /* private fields */ }Expand description
Destination of an encoding.
A writer either appends to a Vec<u8> or only counts octets (ByteWriter::counter), which is how
encoded lengths are computed with the very same code that encodes.
Typed encoders cannot return errors; the rare failures (an array with more than i32::MAX elements)
are recorded with ByteWriter::fail and reported by ByteWriter::status.
Implementations§
Source§impl<'a> ByteWriter<'a>
impl<'a> ByteWriter<'a>
Sourcepub fn new(buffer: &'a mut Vec<u8>) -> Self
pub fn new(buffer: &'a mut Vec<u8>) -> Self
Starts a new outermost value at the current end of buffer.
Sourcepub fn counter() -> ByteWriter<'static>
pub fn counter() -> ByteWriter<'static>
A writer that stores nothing and only counts the octets written.
Sourcepub fn align(&mut self, boundary: usize)
pub fn align(&mut self, boundary: usize)
Writes zero octets until the position is a multiple of boundary.
Sourcepub fn put_count(&mut self, count: usize)
pub fn put_count(&mut self, count: usize)
Writes the element count of a variable array (HLAinteger32BE, no alignment is performed).
A count above i32::MAX records EncoderError::TooManyElements.
Sourcepub fn fail(&mut self, error: EncoderError)
pub fn fail(&mut self, error: EncoderError)
Records that the value being written cannot be encoded. The first error wins.
Sourcepub fn status(&self) -> Result<(), EncoderError>
pub fn status(&self) -> Result<(), EncoderError>
Err with the first recorded error, Ok if the encoding is sound so far.