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]
impl<'a> Parser<'a>
pub fn new(bytes: &'a [u8]) -> Self
[src]
pub fn new(bytes: &'a [u8]) -> Self
Creates a new parser atop a bytes slice.
pub fn set_limit(&mut self, len: usize) -> ParseResult<()>
[src]
pub 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)
.
pub fn remove_limit(&mut self)
[src]
pub fn remove_limit(&mut self)
Removes any limit from the parser.
impl<'a> Parser<'a>
[src]
impl<'a> Parser<'a>
pub fn bytes(&self) -> &'a [u8]
[src]
pub 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.
pub fn pos(&self) -> usize
[src]
pub fn pos(&self) -> usize
Returns the current parser position.
This is the index in self.bytes()
where the next octet would be
read.
pub fn remaining(&self) -> usize
[src]
pub 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.
pub fn seek(&mut self, pos: usize) -> ParseResult<()>
[src]
pub 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]
impl<'a> Parser<'a>
pub fn skip(&mut self, len: usize) -> ParseResult<()>
[src]
pub 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)
.
pub fn parse_bytes(&mut self, len: usize) -> ParseResult<&'a [u8]>
[src]
pub 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.
pub fn parse_u8(&mut self) -> ParseResult<u8>
[src]
pub fn parse_u8(&mut self) -> ParseResult<u8>
pub fn parse_u16(&mut self) -> ParseResult<u16>
[src]
pub fn parse_u16(&mut self) -> ParseResult<u16>
pub fn parse_u32(&mut self) -> ParseResult<u32>
[src]
pub fn parse_u32(&mut self) -> ParseResult<u32>
pub fn parse_remaining(&mut self) -> ParseResult<&'a [u8]>
[src]
pub fn parse_remaining(&mut self) -> ParseResult<&'a [u8]>
pub fn exhausted(&self) -> ParseResult<()>
[src]
pub fn exhausted(&self) -> ParseResult<()>
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]
impl<'a> Clone for Parser<'a>
fn clone(&self) -> 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[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<'a> Debug for Parser<'a>
[src]
impl<'a> Debug for Parser<'a>