Skip to main content

ByteReader

Struct ByteReader 

Source
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>

Source

pub fn new(data: &'a [u8]) -> Self

Starts decoding an outermost value at the beginning of data.

Source

pub fn position(&self) -> usize

Octets consumed since the start of the outermost value.

Source

pub fn remaining(&self) -> usize

Octets left.

Source

pub fn is_empty(&self) -> bool

True when every octet has been consumed.

Source

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.

Source

pub fn take(&mut self, len: usize) -> Result<&'a [u8], DecoderError>

Consumes len octets.

Source

pub fn take_array<const N: usize>(&mut self) -> Result<[u8; N], DecoderError>

Consumes exactly N octets.

Source

pub fn read_u8(&mut self) -> Result<u8, DecoderError>

Consumes one octet.

Source

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.

Source

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.

Source

pub fn expect_end(&self) -> Result<(), DecoderError>

Fails with DecoderError::TrailingBytes unless every octet has been consumed.

Trait Implementations§

Source§

impl<'a> Clone for ByteReader<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for ByteReader<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Forget for ByteReader<'a>

§

impl<'a> Freeze for ByteReader<'a>
where &'a [u8]: Freeze,

§

impl<'a> Move for ByteReader<'a>

§

impl<'a> RefUnwindSafe for ByteReader<'a>

§

impl<'a> Send for ByteReader<'a>
where &'a [u8]: Send,

§

impl<'a> Sync for ByteReader<'a>

§

impl<'a> Unpin for ByteReader<'a>
where &'a [u8]: Unpin,

§

impl<'a> UnsafeUnpin for ByteReader<'a>
where &'a [u8]: UnsafeUnpin,

§

impl<'a> UnwindSafe for ByteReader<'a>
where &'a [u8]: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.