pub struct ByteReader<'a> { /* private fields */ }Expand description
Source of a decoding: a cursor over a byte slice.
Every read is bounds checked and returns DecoderError::Truncated instead of panicking.
Implementations§
Source§impl<'a> ByteReader<'a>
impl<'a> ByteReader<'a>
Sourcepub fn new(data: &'a [u8]) -> Self
pub fn new(data: &'a [u8]) -> Self
Starts decoding an outermost value at the beginning of data.
Sourcepub fn align(&mut self, boundary: usize) -> Result<(), DecoderError>
pub fn align(&mut self, boundary: usize) -> Result<(), DecoderError>
Skips padding octets until the position is a multiple of boundary, whatever they hold.
IEEE 1516.2 4.14.10 requires zero padding from the sender (and ByteWriter::align writes
zeros); it says nothing of a receiver that finds other octets there. They are ignored, so a value
decodes the same whatever its padding holds.
Sourcepub fn take_array<const N: usize>(&mut self) -> Result<[u8; N], DecoderError>
pub fn take_array<const N: usize>(&mut self) -> Result<[u8; N], DecoderError>
Consumes exactly N octets.
Sourcepub fn read_u8(&mut self) -> Result<u8, DecoderError>
pub fn read_u8(&mut self) -> Result<u8, DecoderError>
Consumes one octet.
Sourcepub fn read_count(&mut self) -> Result<usize, DecoderError>
pub fn read_count(&mut self) -> Result<usize, DecoderError>
Reads the element count of a variable array (HLAinteger32BE, IEEE 1516.2 4.14.10.5; no alignment
is performed).
Negative counts are rejected, and so are counts larger than the number of octets left: an element
of almost every datatype takes at least one octet, and refusing early keeps hostile counts from
driving allocations. The price is a limit of this implementation, not of the standard: an array of
zero-length elements (HLAtoken, empty fixed arrays) only decodes while its count does not exceed
the octets that follow it.
Sourcepub fn window(&mut self, len: usize) -> Result<ByteReader<'a>, DecoderError>
pub fn window(&mut self, len: usize) -> Result<ByteReader<'a>, DecoderError>
Splits off the next len octets as a reader of their own. Offsets (and therefore padding) stay
relative to the outermost value.
Sourcepub fn expect_end(&self) -> Result<(), DecoderError>
pub fn expect_end(&self) -> Result<(), DecoderError>
Fails with DecoderError::TrailingBytes unless every octet has been consumed.