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]
fn new(bytes: &'a [u8]) -> Self
Creates a new parser atop a bytes slice.
fn set_limit(&mut self, len: usize) -> ParseResult<()>
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)
.
fn remove_limit(&mut self)
Removes any limit from the parser.
impl<'a> Parser<'a>
[src]
fn bytes(&self) -> &'a [u8]
Returns a reference to the complete message.
The returned slice contains all bytes. It disregards the current position and any limit.
fn pos(&self) -> usize
Returns the current parser position.
This is the index in self.bytes()
where the next octet would be
read.
fn remaining(&self) -> usize
Returns the number of bytes left to parse.
If a limit is set, the returned number is up until that limit.
fn seek(&mut self, pos: usize) -> ParseResult<()>
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]
fn skip(&mut self, len: usize) -> ParseResult<()>
Skips over len
bytes.
If this would go beyond the current limit or the end of the message,
returns Err(ParseError::UnexpectedEnd)
.
fn parse_bytes(&mut self, len: usize) -> ParseResult<&'a [u8]>
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.
fn parse_u8(&mut self) -> ParseResult<u8>
fn parse_u16(&mut self) -> ParseResult<u16>
fn parse_u32(&mut self) -> ParseResult<u32>
Trait Implementations
impl<'a> Clone for Parser<'a>
[src]
fn clone(&self) -> Parser<'a>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more