[][src]Struct domain::base::octets::Parser

pub struct Parser<Ref> { /* fields omitted */ }

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

impl<Ref> Parser<Ref>[src]

pub fn from_ref(octets: Ref) -> Self where
    Ref: AsRef<[u8]>, 
[src]

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

pub fn octets_ref(&self) -> Ref where
    Ref: Copy
[src]

Returns the wrapped reference to the underlying octets sequence.

pub fn pos(&self) -> usize[src]

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

pub fn len(&self) -> usize[src]

Returns the length of the underlying octet sequence.

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

pub fn is_empty(&self) -> bool[src]

Returns whether the underlying octets sequence is empty.

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

impl Parser<&'static [u8]>[src]

pub fn from_static(slice: &'static [u8]) -> Self[src]

Creates a new parser atop a static byte slice.

This function is most useful for testing.

impl<Ref: AsRef<[u8]>> Parser<Ref>[src]

pub fn as_slice(&self) -> &[u8][src]

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.

pub fn as_slice_mut(&mut self) -> &mut [u8] where
    Ref: AsMut<[u8]>, 
[src]

Returns a mutable octets slice of the underlying sequence.

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

pub fn remaining(&self) -> usize[src]

Returns the number of remaining octets to parse.

pub fn peek(&self, len: usize) -> Result<&[u8], ParseError>[src]

Returns a slice for the next len octets.

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

pub fn peek_all(&self) -> &[u8][src]

Returns a slice of the data left to parse.

pub fn seek(&mut self, pos: usize) -> Result<(), ParseError>[src]

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.

pub fn advance(&mut self, len: usize) -> Result<(), ParseError>[src]

Advances the parser‘s position by len octets.

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

pub fn advance_to_end(&mut self)[src]

Advances to the end of the parser.

pub fn check_len(&self, len: usize) -> Result<(), ParseError>[src]

Checks that there are len octets left to parse.

If there aren’t, returns an error.

impl<Ref: AsRef<[u8]>> Parser<Ref>[src]

pub fn parse_octets(&mut self, len: usize) -> Result<Ref::Range, ParseError> where
    Ref: OctetsRef
[src]

Takes and returns the next len octets.

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

pub fn parse_buf(&mut self, buf: &mut [u8]) -> Result<(), ParseError>[src]

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.

pub fn parse_i8(&mut self) -> Result<i8, ParseError>[src]

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.

pub fn parse_u8(&mut self) -> Result<u8, ParseError>[src]

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.

pub fn parse_i16(&mut self) -> Result<i16, ParseError>[src]

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.

pub fn parse_u16(&mut self) -> Result<u16, ParseError>[src]

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.

pub fn parse_i32(&mut self) -> Result<i32, ParseError>[src]

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.

pub fn parse_u32(&mut self) -> Result<u32, ParseError>[src]

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.

pub fn parse_block<F, U>(
    &mut self,
    limit: usize,
    op: F
) -> Result<U, ParseError> where
    F: FnOnce(&mut Self) -> Result<U, ParseError>, 
[src]

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

impl<Ref: Clone> Clone for Parser<Ref>[src]

impl<Ref: Copy> Copy for Parser<Ref>[src]

impl<Ref: Debug> Debug for Parser<Ref>[src]

Auto Trait Implementations

impl<Ref> RefUnwindSafe for Parser<Ref> where
    Ref: RefUnwindSafe

impl<Ref> Send for Parser<Ref> where
    Ref: Send

impl<Ref> Sync for Parser<Ref> where
    Ref: Sync

impl<Ref> Unpin for Parser<Ref> where
    Ref: Unpin

impl<Ref> UnwindSafe for Parser<Ref> where
    Ref: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,