SliceReader

Struct SliceReader 

Source
pub struct SliceReader<'a> { /* private fields */ }
Expand description

Reader which consumes an input byte slice.

Implementations§

Source§

impl<'a> SliceReader<'a>

Source

pub fn new(bytes: &'a [u8]) -> Result<Self>

Create a new slice reader for the given byte slice.

Source

pub fn error(&mut self, kind: ErrorKind) -> Error

Return an error with the given ErrorKind, annotating it with context about where the error occurred.

Source

pub fn value_error(&mut self, tag: Tag) -> Error

Return an error for an invalid value with the given tag.

Source

pub fn is_failed(&self) -> bool

Did the decoding operation fail due to an error?

Trait Implementations§

Source§

impl<'a> Clone for SliceReader<'a>

Source§

fn clone(&self) -> SliceReader<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for SliceReader<'a>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'a> Reader<'a> for SliceReader<'a>

Source§

fn input_len(&self) -> Length

Get the length of the input.
Source§

fn peek_byte(&self) -> Option<u8>

Peek at the next byte of input without modifying the cursor.
Source§

fn peek_header(&self) -> Result<Header>

Peek forward in the input data, attempting to decode a Header from the data at the current position in the decoder. Read more
Source§

fn position(&self) -> Length

Get the position within the buffer.
Source§

fn read_slice(&mut self, len: Length) -> Result<&'a [u8]>

Attempt to read data borrowed directly from the input as a slice, updating the internal cursor position. Read more
Source§

fn decode<T: Decode<'a>>(&mut self) -> Result<T>

Decode a value which impls the Decode trait.
Source§

fn error(&mut self, kind: ErrorKind) -> Error

Return an error with the given ErrorKind, annotating it with context about where the error occurred.
Source§

fn finish<T>(self, value: T) -> Result<T>

Finish decoding, returning the given value if there is no remaining data, or an error otherwise
Source§

fn remaining_len(&self) -> Length

Get the number of bytes still remaining in the buffer.
Source§

fn context_specific<T>( &mut self, tag_number: TagNumber, tag_mode: TagMode, ) -> Result<Option<T>>
where T: DecodeValue<'r> + FixedTag,

Attempt to decode an ASN.1 CONTEXT-SPECIFIC field with the provided TagNumber.
Source§

fn is_finished(&self) -> bool

Have we read all of the input data?
Source§

fn offset(&self) -> Length

Offset within the original input stream. Read more
Source§

fn peek_tag(&self) -> Result<Tag>

Peek at the next byte in the decoder and attempt to decode it as a Tag value. Read more
Source§

fn read_byte(&mut self) -> Result<u8>

Read a single byte.
Source§

fn read_into<'o>(&mut self, buf: &'o mut [u8]) -> Result<&'o [u8]>

Attempt to read input data, writing it into the provided buffer, and returning a slice on success. Read more
Source§

fn read_nested<'n, T, F>(&'n mut self, len: Length, f: F) -> Result<T>
where F: FnOnce(&mut NestedReader<'n, Self>) -> Result<T>,

Read nested data of the given length.
Source§

fn read_vec(&mut self, len: Length) -> Result<Vec<u8>>

Available on crate feature alloc only.
Read a byte vector of the given length.
Source§

fn sequence<'n, F, T>(&'n mut self, f: F) -> Result<T>
where F: FnOnce(&mut NestedReader<'n, Self>) -> Result<T>,

Read an ASN.1 SEQUENCE, creating a nested Reader for the body and calling the provided closure with it.
Source§

fn tlv_bytes(&mut self) -> Result<&'r [u8]>

Obtain a slice of bytes contain a complete TLV production suitable for parsing later.

Auto Trait Implementations§

§

impl<'a> Freeze for SliceReader<'a>

§

impl<'a> RefUnwindSafe for SliceReader<'a>

§

impl<'a> Send for SliceReader<'a>

§

impl<'a> Sync for SliceReader<'a>

§

impl<'a> Unpin for SliceReader<'a>

§

impl<'a> UnwindSafe for SliceReader<'a>

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 32 bytes