Struct domain::bits::parse::Parser[][src]

pub struct Parser<'a> { /* fields omitted */ }

A type wrapping DNS message data for parsing.

Because of name compression, a full message needs to be available for parsing of DNS data. If you have received a message over the wire, you can use it to create a parser via the new() function.

The parser then allows you to successively parse one item after the other out of the message via a few methods prefixed with parse_. Further methods are available to retrieve some information about the parser state, seek to a new position, or limit the amount of data the parser allows to retrieve.

Parsers are Clone, so you can keep around a copy of a parser for later use. This is, for instance, done by ParsedDName in order to be able to rummage around the message bytes to find all its labels.

Methods

impl<'a> Parser<'a>
[src]

Creates a new parser atop a bytes slice.

Limits the parser to len bytes from its current position.

If the limit would be beyond the end of the parser, returns Err(ParseError::UnexpectedEnd).

Removes any limit from the parser.

impl<'a> Parser<'a>
[src]

Returns a reference to the complete message.

The returned slice contains all bytes. It disregards the current position and any limit.

Returns the current parser position.

This is the index in self.bytes() where the next octet would be read.

Returns the number of bytes left to parse.

If a limit is set, the returned number is up until that limit.

Resets the position of the parser.

The new position is relative to the beginning of the parser’s message. The function fails if the position is beyond the end of the message or, if a limit is set, beyond the limit. In either case, the function will return Err(ParseError::UnexpectedEnd).

impl<'a> Parser<'a>
[src]

Skips over len bytes.

If this would go beyond the current limit or the end of the message, returns Err(ParseError::UnexpectedEnd).

Parses a bytes slice of the given length.

The slice returned upon success references the parser’s message directly. The parser’s position is advanced until the end of the slice.

The method will return Err(ParseError::UnexpectedEnd) if the length would take the parser beyond the current limit or the end of the message.

Verifies that the parser is exhausted.

Returns Ok(()) if there are no remaining bytes in the parser or a form error otherwise.

Trait Implementations

impl<'a> Clone for Parser<'a>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<'a> Debug for Parser<'a>
[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

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

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