Struct hickory_proto::serialize::binary::BinDecoder
source · pub struct BinDecoder<'a> { /* private fields */ }
Expand description
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.
Implementations§
source§impl<'a> BinDecoder<'a>
impl<'a> BinDecoder<'a>
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of bytes in the buffer
use hickory_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);
sourcepub fn peek(&self) -> Option<Restrict<u8>>
pub fn peek(&self) -> Option<Restrict<u8>>
Peed one byte forward, without moving the current index forward
sourcepub fn clone(&self, index_at: u16) -> BinDecoder<'a>
pub fn clone(&self, index_at: u16) -> BinDecoder<'a>
This is a pretty efficient clone, as the buffer is never cloned, and only the index is set to the value passed in
sourcepub fn read_character_data(&mut self) -> Result<Restrict<&[u8]>, DecodeError>
pub fn read_character_data(&mut self) -> Result<Restrict<&[u8]>, DecodeError>
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
sourcepub fn read_slice(
&mut self,
len: usize
) -> Result<Restrict<&'a [u8]>, DecodeError>
pub fn read_slice( &mut self, len: usize ) -> Result<Restrict<&'a [u8]>, DecodeError>
sourcepub fn slice_from(&self, index: usize) -> Result<&'a [u8], DecodeError>
pub fn slice_from(&self, index: usize) -> Result<&'a [u8], DecodeError>
Reads a slice from a previous index to the current
sourcepub fn read_u8(&mut self) -> Result<Restrict<u8>, DecodeError>
pub fn read_u8(&mut self) -> Result<Restrict<u8>, DecodeError>
Reads a byte from the buffer, equivalent to Self::pop()
sourcepub fn read_u16(&mut self) -> Result<Restrict<u16>, DecodeError>
pub fn read_u16(&mut self) -> Result<Restrict<u16>, DecodeError>
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