[−][src]Struct trust_dns_proto::serialize::binary::BinDecoder
This is non-destructive to the inner buffer, b/c for pointer types we need to perform a reverse seek to lookup names
A note on serialization, there was a thought to have this implement the Serde deserializer, but given that this is such a small subset of all the serialization which that performs this is a simpler implementation without the cruft, at least for serializing to/from the binary DNS protocols.
Methods
impl<'a> BinDecoder<'a>
[src]
pub fn new(buffer: &'a [u8]) -> Self
[src]
pub fn pop(&mut self) -> ProtoResult<Restrict<u8>>
[src]
Pop one byte from the buffer
pub fn len(&self) -> usize
[src]
Returns the number of bytes in the buffer
use trust_dns_proto::serialize::binary::BinDecoder; let deadbeef = b"deadbeef"; let mut decoder = BinDecoder::new(deadbeef); assert_eq!(decoder.len(), 8); decoder.read_slice(7).unwrap(); assert_eq!(decoder.len(), 1);
pub fn is_empty(&self) -> bool
[src]
Returns true
if the buffer is empty
pub fn peek(&self) -> Option<Restrict<u8>>
[src]
Peed one byte forward, without moving the current index forward
pub fn index(&self) -> usize
[src]
Returns the current index in the buffer
pub fn clone(&self, index_at: u16) -> BinDecoder<'a>
[src]
This is a pretty efficient clone, as the buffer is never cloned, and only the index is set to the value passed in
pub fn read_character_data(&mut self) -> ProtoResult<Restrict<&[u8]>>
[src]
Reads a String from the buffer
<character-string> is a single
length octet followed by that number of characters. <character-string>
is treated as binary information, and can be up to 256 characters in
length (including the length octet).
Returns
A String version of the character data
pub fn read_character_data_max(
&mut self,
max_len: Option<usize>
) -> ProtoResult<Restrict<&[u8]>>
[src]
&mut self,
max_len: Option<usize>
) -> ProtoResult<Restrict<&[u8]>>
Reads to a maximum length of data, returns an error if this is exceeded
pub fn read_vec(&mut self, len: usize) -> ProtoResult<Restrict<Vec<u8>>>
[src]
Reads a Vec out of the buffer
Arguments
len
- number of bytes to read from the buffer
Returns
The Vec of the specified length, otherwise an error
pub fn read_slice(&mut self, len: usize) -> ProtoResult<Restrict<&'a [u8]>>
[src]
Reads a slice out of the buffer, without allocating
Arguments
len
- number of bytes to read from the buffer
Returns
The slice of the specified length, otherwise an error
pub fn slice_from(&self, index: usize) -> ProtoResult<&'a [u8]>
[src]
Reads a slice from a previous index to the current
pub fn read_u8(&mut self) -> ProtoResult<Restrict<u8>>
[src]
Reads a byte from the buffer, equivalent to Self::pop()
pub fn read_u16(&mut self) -> ProtoResult<Restrict<u16>>
[src]
Reads the next 2 bytes into u16
This performs a byte-by-byte manipulation, there which means endianness is implicitly handled (i.e. no network to little endian (intel), issues)
Return
Return the u16 from the buffer
pub fn read_i32(&mut self) -> ProtoResult<Restrict<i32>>
[src]
Reads the next four bytes into i32.
This performs a byte-by-byte manipulation, there which means endianness is implicitly handled (i.e. no network to little endian (intel), issues)
Return
Return the i32 from the buffer
pub fn read_u32(&mut self) -> ProtoResult<Restrict<u32>>
[src]
Reads the next four bytes into u32.
This performs a byte-by-byte manipulation, there which means endianness is implicitly handled (i.e. no network to little endian (intel), issues)
Return
Return the u32 from the buffer
Auto Trait Implementations
impl<'a> Send for BinDecoder<'a>
impl<'a> Sync for BinDecoder<'a>
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,