pub struct Parser<Ref> { /* private fields */ }
Expand description

A parser for sequentially extracting data from an octets sequence.

The parser wraps an octets reference and remembers the read position on the referenced sequence. Methods allow reading out data and progressing the position beyond processed data.

Implementations

Creates a new parser atop a reference to an octet sequence.

Returns the wrapped reference to the underlying octets sequence.

Returns the current parse position as an index into the octets.

Returns the length of the underlying octet sequence.

This is not the number of octets left for parsing. Use remaining for that.

Returns whether the underlying octets sequence is empty.

This does not return whether there are no more octets left to parse.

Creates a new parser atop a static byte slice.

This function is most useful for testing.

Returns an octets slice of the underlying sequence.

The slice covers the entire sequence, not just the remaining data. You can use peek for that.

Returns a mutable octets slice of the underlying sequence.

The slice covers the entire sequence, not just the remaining data.

Returns the number of remaining octets to parse.

Returns a slice for the next len octets.

If less than len octets are left, returns an error.

Returns a slice of the data left to parse.

Repositions the parser to the given index.

It is okay to reposition anywhere within the sequence. However, if pos is larger than the length of the sequence, an error is returned.

Advances the parser‘s position by len octets.

If this would take the parser beyond its end, an error is returned.

Advances to the end of the parser.

Checks that there are len octets left to parse.

If there aren’t, returns an error.

Takes and returns the next len octets.

Advances the parser by len octets. If there aren’t enough octets left, leaves the parser untouched and returns an error instead.

Fills the provided buffer by taking octets from the parser.

Copies as many octets as the buffer is long from the parser into the buffer and advances the parser by that many octets.

If there aren’t enough octets left in the parser to fill the buffer completely, returns an error and leaves the parser untouched.

Takes an i8 from the beginning of the parser.

Advances the parser by one octet. If there aren’t enough octets left, leaves the parser untouched and returns an error instead.

Takes a u8 from the beginning of the parser.

Advances the parser by one octet. If there aren’t enough octets left, leaves the parser untouched and returns an error instead.

Takes an i16 from the beginning of the parser.

The value is converted from network byte order into the system’s own byte order if necessary. The parser is advanced by two octets. If there aren’t enough octets left, leaves the parser untouched and returns an error instead.

Takes a u16 from the beginning of the parser.

The value is converted from network byte order into the system’s own byte order if necessary. The parser is advanced by two ocetets. If there aren’t enough octets left, leaves the parser untouched and returns an error instead.

Takes an i32 from the beginning of the parser.

The value is converted from network byte order into the system’s own byte order if necessary. The parser is advanced by four octets. If there aren’t enough octets left, leaves the parser untouched and returns an error instead.

Takes a u32 from the beginning of the parser.

The value is converted from network byte order into the system’s own byte order if necessary. The parser is advanced by four octets. If there aren’t enough octets left, leaves the parser untouched and returns an error instead.

Parses a given amount of octets through a closure.

Parses a block of limit octets and moves the parser to the end of that block or, if less than limit octets are still available, to the end of the parser.

The closure op will be allowed to parse up to limit octets. If it does so successfully or returns with a form error, the method returns its return value. If it returns with a short buffer error, the method returns a form error. If it returns successfully with less than limit octets parsed, returns a form error indicating trailing data. If the limit is larger than the remaining number of octets, returns a ParseError::ShortInput.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Performs the conversion.

The resulting type after obtaining ownership.

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.