Struct Parser

Source
pub struct Parser<'a> {
    pub bytes: &'a [u8],
}
Expand description

A byte-oriented parser, for use in decoding CodeView records.

Fields§

§bytes: &'a [u8]

The bytes that have not yet been parsed.

Implementations§

Source§

impl<'a> Parser<'a>

Source

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

Starts a new parser.

Source

pub fn peek_rest(&self) -> &'a [u8]

Gets the rest of the unparsed bytes in the parser. The parser still retains a reference to the same data.

Source

pub fn take_rest(&mut self) -> &'a [u8]

Gets the rest of the unparsed

Source

pub fn into_rest(self) -> &'a [u8]

Consumes this Parser and returns the unparsed bytes within it.

This should be used in situations where there is no valid reason to use the Parser after taking the rest of the bytes within it. In situations where a parse() method only has access to &mut Parser, then this function cannot be used, and the caller should use Parser::take_rest.

Source

pub fn is_empty(&self) -> bool

Indicates whether there are any bytes left to parse.

Source

pub fn len(&self) -> usize

Returns the number of unparsed bytes in the parser.

Source

pub fn needs(&self, n: usize) -> Result<(), ParserError>

Checks that the buffer has at least n bytes.

This can be used as an optimization improvement in some situations. Ordinarily, code like this will compile to a series of bounds checks:

let mut p = Parser::new(bytes);
let a = p.u32()?;
let b = p.u16()?;
let c = p.u16()?;
let d = p.u32()?;

Inserting a a.needs(12)? statement can sometimes enable the compiler to collapse a series of bounds checks (4, in this case) to a single bounds check.

Source

pub fn bytes(&mut self, n: usize) -> Result<&'a [u8], ParserError>

Takes the next n bytes of input and returns a slice to it. The parser is advanced by n.

Source

pub fn skip(&mut self, n: usize) -> Result<(), ParserError>

Skips n bytes.

Source

pub fn get<T: FromBytes + Unaligned + KnownLayout + Immutable>( &mut self, ) -> Result<&'a T, ParserError>

Parses a reference to a structure. The input must contain at least size_of::<T>() bytes.

Source

pub fn copy<T: FromBytes + Unaligned>(&mut self) -> Result<T, ParserError>

Parses a copy of a structure. The input must contain at least size_of::<T>() bytes.

Source

pub fn parse<T: Parse<'a>>(&mut self) -> Result<T, ParserError>

Parses a T from the input, if T knows how to read from a Parser.

This exists mainly to allow more succinct calls, using type inference.

Source

pub fn slice<T: FromBytes + Unaligned + Immutable>( &mut self, len: usize, ) -> Result<&'a [T], ParserError>

Parses a slice of items. The input must contain at least [size_of::<T>() * n] bytes.

Source

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

Copies an array of items with a constant size and advances the parser.

Source

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

Reads one byte and advances.

Source

pub fn i8(&mut self) -> Result<i8, ParserError>

Reads one signed byte and advances.

Source

pub fn i16(&mut self) -> Result<i16, ParserError>

Reads an i16 (in little-endian order) and advances.

Source

pub fn i32(&mut self) -> Result<i32, ParserError>

Reads an i32 (in little-endian order) and advances.

Source

pub fn i64(&mut self) -> Result<i64, ParserError>

Reads an i64 (in little-endian order) and advances.

Source

pub fn u16(&mut self) -> Result<u16, ParserError>

Reads an u16 (in little-endian order) and advances.

Source

pub fn u32(&mut self) -> Result<u32, ParserError>

Reads an u32 (in little-endian order) and advances.

Source

pub fn u64(&mut self) -> Result<u64, ParserError>

Reads an u64 (in little-endian order) and advances.

Source

pub fn u128(&mut self) -> Result<u128, ParserError>

Reads an u128 (in little-endian order) and advances.

Source

pub fn i128(&mut self) -> Result<i128, ParserError>

Reads an i128 (in little-endian order) and advances.

Source

pub fn f32(&mut self) -> Result<f32, ParserError>

Reads an f32 (in little-endian order) and advances.

Source

pub fn f64(&mut self) -> Result<f64, ParserError>

Reads an f64 (in little-endian order) and advances.

Source

pub fn skip_strz(&mut self) -> Result<(), ParserError>

Skips over a NUL-terminated string.

Source

pub fn strz(&mut self) -> Result<&'a BStr, ParserError>

Reads a NUL-terminated string, without checking that it is UTF-8 encoded.

Source

pub fn strt_raw(&mut self) -> Result<&'a BStr, ParserError>

Reads a length-prefixed string, without checking that it is UTF-8 encoded.

Source

pub fn strt(&mut self) -> Result<&'a str, ParserError>

Reads a length-prefixed string.

Source

pub fn type_index(&mut self) -> Result<TypeIndex, ParserError>

Parses a 32-bit TypeIndex.

Source

pub fn number(&mut self) -> Result<Number<'a>, ParserError>

Parses a generic number value.

See Section 4, numeric leaves

Trait Implementations§

Source§

impl<'a> Clone for Parser<'a>

Source§

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

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

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Parser<'a>

§

impl<'a> RefUnwindSafe for Parser<'a>

§

impl<'a> Send for Parser<'a>

§

impl<'a> Sync for Parser<'a>

§

impl<'a> Unpin for Parser<'a>

§

impl<'a> UnwindSafe for Parser<'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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more