pub struct RawParser<'data> { /* private fields */ }
Expand description

Raw parser.

  • provides basic and intermediate parsing functions used by Parser and PacketParser;
  • works at byte-level.

Implementations

Basic functions.

Constructor.

  • data: input bytes to parse;
  • offset offset from the start of the original input. Used by PacketParser, which works on a slice of the original input, for consistent error-reporting.

Data accessor.

Consumes some bytes from the input, move the cursor at the end of these bytes.

Position related functions.

Position accessor.

Retrieves the byte at some position.

Backtracks the parser to a previous position.

Panics
  • when pos is greater than the current position.

RawParser helpers.

True if the parser is at the end of its input.

Yields the current position and the total length of the input text.

Yields a single-line, concise description of the current position.

Basic parsers.

Parses a string.

Parses a u8.

Examples
let data = 213u8.to_le_bytes();
let mut parser = RawParser::new(&data, 0);
assert_eq!(parser.u8_le().unwrap(), 213);
assert!(parser.is_eof());

Parses a u8.

Examples
let data = 213u8.to_be_bytes();
let mut parser = RawParser::new(&data, 0);
assert_eq!(parser.u8_be().unwrap(), 213);
assert!(parser.is_eof());

Parses a u16.

Examples
let data = 1_213u16.to_le_bytes();
let mut parser = RawParser::new(&data, 0);
assert_eq!(parser.u16_le().unwrap(), 1_213);
assert!(parser.is_eof());

Parses a u16.

Examples
let data = 1_213u16.to_be_bytes();
let mut parser = RawParser::new(&data, 0);
assert_eq!(parser.u16_be().unwrap(), 1_213);
assert!(parser.is_eof());

Parses a u32.

Examples
let data = 1_701_213u32.to_le_bytes();
let mut parser = RawParser::new(&data, 0);
assert_eq!(parser.u32_le().unwrap(), 1_701_213);
assert!(parser.is_eof());

Parses a u32.

Examples
let data = 1_701_213u32.to_be_bytes();
let mut parser = RawParser::new(&data, 0);
assert_eq!(parser.u32_be().unwrap(), 1_701_213);
assert!(parser.is_eof());

Parses a u64.

Examples
let data = 7_501_701_213u64.to_be_bytes();
let mut parser = RawParser::new(&data, 0);
assert_eq!(parser.u64_be().unwrap(), 7_501_701_213);
assert!(parser.is_eof());

Parses a u64, low-endian version.

Examples
let data = 7_501_701_213u64.to_le_bytes();
let mut parser = RawParser::new(&data, 0);
assert_eq!(parser.u64_le().unwrap(), 7_501_701_213);
assert!(parser.is_eof());

Parses a u64, big-endian version.

Examples
let data = 7_501_701.745f64.to_be_bytes();
let mut parser = RawParser::new(&data, 0);
assert_eq!(parser.f64_be().unwrap(), 7_501_701.745);
assert!(parser.is_eof());

Parses a u64, big-endian version.

Examples
let data = 7_501_701.745f64.to_le_bytes();
let mut parser = RawParser::new(&data, 0);
assert_eq!(parser.f64_le().unwrap(), 7_501_701.745);
assert!(parser.is_eof());

Parses and checks the CTF magic number, and sets the big-endian flag.

Attemps to parse the memtrace CTF magic number.

Parsing the magic number reveals whether the dump uses a big- or low-endian convention. Thus, it returns either a big-endian parser or a low-endian one.

Trait Implementations

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

The error type produced by a failed conversion.

Convert the given value into an approximately equivalent representation.

The error type produced by a failed conversion.

Convert the subject into an approximately equivalent representation.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Approximate the subject with the default scheme.

Approximate the subject with a specific scheme.

Approximate the subject to a given type with the default scheme.

Approximate the subject to a given type with a specific scheme.

Convert the subject to a given type.

Attempt to convert the subject to a given type.

Attempt a value conversion of the subject to a given type.

Returns the argument unchanged.

Calls U::from(self).

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

The error type produced by a failed conversion.

Convert the given value into the subject type.

The type returned in the event of a conversion error.

Performs the conversion.

The error type produced by a failed conversion.

Convert the subject into the destination type.

The type returned in the event of a conversion error.

Performs the conversion.

The error type produced by a failed conversion.

Convert the given value into an exactly equivalent representation.

The error type produced by a failed conversion.

Convert the subject into an exactly equivalent representation.