pub struct PacketParser<'cxt, 'data, Endian> { /* private fields */ }
Expand description

Packet parser.

Thin wrapper around a RawParser over the bytes of the events of the packet. Also stores the packet header. Note that the bytes for the header are not included in the parser’s data. It has already been parsed.

Implementations

Header accessor.

Returns the next event of the packet, if any.

Methods from Deref<Target = RawParser<'data>>

Data accessor.

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

Position accessor.

Retrieves the byte at some position.

Backtracks the parser to a previous position.

Panics
  • when pos is greater than the current position.

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.

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.

Trait Implementations

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

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.