Struct BinDecoder
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§
§impl<'a> BinDecoder<'a>
impl<'a> BinDecoder<'a>
pub fn new(buffer: &'a [u8]) -> BinDecoder<'a>
pub fn new(buffer: &'a [u8]) -> BinDecoder<'a>
pub fn pop(&mut self) -> Result<Restrict<u8>, DecodeError>
pub fn pop(&mut self) -> Result<Restrict<u8>, DecodeError>
Pop one byte from the buffer
pub 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);
pub fn peek(&self) -> Option<Restrict<u8>>
pub fn peek(&self) -> Option<Restrict<u8>>
Peed one byte forward, without moving the current index forward
pub 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
pub 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
pub 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>
pub 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
pub 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()
pub 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
Auto Trait Implementations§
impl<'a> Freeze for BinDecoder<'a>
impl<'a> RefUnwindSafe for BinDecoder<'a>
impl<'a> Send for BinDecoder<'a>
impl<'a> Sync for BinDecoder<'a>
impl<'a> Unpin for BinDecoder<'a>
impl<'a> UnwindSafe for BinDecoder<'a>
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy
that returns Action::Follow
only if self
and other
return
Action::Follow
. Read more