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. Padding content is ignored.
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, no alignment is performed).
Negative counts are rejected, and so are counts larger than the number of octets left: an element of any real datatype takes at least one octet, and refusing early keeps hostile counts from driving allocations. The price is that an array of zero-length elements (an array of empty fixed arrays, say) 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.