Struct BinEncoder

pub struct BinEncoder<'a> { /* private fields */ }
Expand description

Encode DNS messages and resource record types.

Implementations§

§

impl<'a> BinEncoder<'a>

pub fn new(buf: &'a mut Vec<u8>) -> BinEncoder<'a>

Create a new encoder with the Vec to fill

pub fn with_mode(buf: &'a mut Vec<u8>, mode: EncodeMode) -> BinEncoder<'a>

Specify the mode for encoding

§Arguments
  • mode - In Signing mode, canonical forms of all data are encoded, otherwise format matches the source form

pub fn with_offset( buf: &'a mut Vec<u8>, offset: u32, mode: EncodeMode, ) -> BinEncoder<'a>

Begins the encoder at the given offset

This is used for pointers. If this encoder is starting at some point further in the sequence of bytes, for the proper offset of the pointer, the offset accounts for that by using the offset to add to the pointer location being written.

§Arguments
  • offset - index at which to start writing into the buffer

pub fn set_max_size(&mut self, max: u16)

Sets the maximum size of the buffer

DNS message lens must be smaller than u16::max_value due to hard limits in the protocol

this method will move to the constructor in a future release

pub fn into_bytes(self) -> &'a Vec<u8>

Returns a reference to the internal buffer

pub fn len(&self) -> usize

Returns the length of the buffer

pub fn is_empty(&self) -> bool

Returns true if the buffer is empty

pub fn offset(&self) -> usize

Returns the current offset into the buffer

pub fn set_offset(&mut self, offset: usize)

sets the current offset to the new offset

pub fn mode(&self) -> EncodeMode

Returns the current Encoding mode

pub fn set_canonical_names(&mut self, canonical_names: bool)

If set to true, then names will be written into the buffer in canonical form

pub fn is_canonical_names(&self) -> bool

Returns true if then encoder is writing in canonical form

pub fn with_canonical_names<F>(&mut self, f: F) -> Result<(), ProtoError>
where F: FnOnce(&mut BinEncoder<'a>) -> Result<(), ProtoError>,

Emit all names in canonical form, useful for https://tools.ietf.org/html/rfc3597

pub fn reserve(&mut self, _additional: usize) -> Result<(), ProtoError>

Reserve specified additional length in the internal buffer.

pub fn trim(&mut self)

trims to the current offset

pub fn slice_of(&self, start: usize, end: usize) -> &[u8]

borrow a slice from the encoder

pub fn store_label_pointer(&mut self, start: usize, end: usize)

Stores a label pointer to an already written label

The location is the current position in the buffer implicitly, it is expected that the name will be written to the stream after the current index.

pub fn get_label_pointer(&self, start: usize, end: usize) -> Option<u16>

Looks up the index of an already written label

pub fn emit(&mut self, b: u8) -> Result<(), ProtoError>

Emit one byte into the buffer

pub fn emit_character_data<S>(&mut self, char_data: S) -> Result<(), ProtoError>
where S: AsRef<[u8]>,

matches description from above.

use hickory_proto::serialize::binary::BinEncoder;

let mut bytes: Vec<u8> = Vec::new();
{
  let mut encoder: BinEncoder = BinEncoder::new(&mut bytes);
  encoder.emit_character_data("abc");
}
assert_eq!(bytes, vec![3,b'a',b'b',b'c']);

pub fn emit_character_data_unrestricted<S>( &mut self, data: S, ) -> Result<(), ProtoError>
where S: AsRef<[u8]>,

Emit character data of unrestricted length

Although character strings are typically restricted to being no longer than 255 characters, some modern standards allow longer strings to be encoded.

pub fn emit_u8(&mut self, data: u8) -> Result<(), ProtoError>

Emit one byte into the buffer

pub fn emit_u16(&mut self, data: u16) -> Result<(), ProtoError>

Writes a u16 in network byte order to the buffer

pub fn emit_i32(&mut self, data: i32) -> Result<(), ProtoError>

Writes an i32 in network byte order to the buffer

pub fn emit_u32(&mut self, data: u32) -> Result<(), ProtoError>

Writes an u32 in network byte order to the buffer

pub fn emit_vec(&mut self, data: &[u8]) -> Result<(), ProtoError>

Writes the byte slice to the stream

pub fn emit_all<'e, I, E>(&mut self, iter: I) -> Result<usize, ProtoError>
where I: Iterator<Item = &'e E>, E: 'e + BinEncodable,

Emits all the elements of an Iterator to the encoder

pub fn emit_all_refs<'r, 'e, I, E>( &mut self, iter: I, ) -> Result<usize, ProtoError>
where 'e: 'r, I: Iterator<Item = &'r &'e E>, E: 'r + 'e + BinEncodable,

Emits all the elements of an Iterator to the encoder

pub fn emit_iter<'e, I, E>(&mut self, iter: &mut I) -> Result<usize, ProtoError>
where I: Iterator<Item = &'e E>, E: 'e + BinEncodable,

emits all items in the iterator, return the number emitted

pub fn place<T>(&mut self) -> Result<Place<T>, ProtoError>
where T: EncodedSize,

capture a location to write back to

pub fn len_since_place<T>(&self, place: &Place<T>) -> usize
where T: EncodedSize,

calculates the length of data written since the place was creating

pub fn emit_at<T>(&mut self, place: Place<T>, data: T) -> Result<(), ProtoError>
where T: EncodedSize,

write back to a previously captured location

Auto Trait Implementations§

§

impl<'a> Freeze for BinEncoder<'a>

§

impl<'a> RefUnwindSafe for BinEncoder<'a>

§

impl<'a> Send for BinEncoder<'a>

§

impl<'a> Sync for BinEncoder<'a>

§

impl<'a> Unpin for BinEncoder<'a>

§

impl<'a> !UnwindSafe for BinEncoder<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
§

impl<T, U> RamaFrom<T> for U
where U: From<T>,

§

fn rama_from(value: T) -> U

§

impl<T, U, CrateMarker> RamaInto<U, CrateMarker> for T
where U: RamaFrom<T, CrateMarker>,

§

fn rama_into(self) -> U

§

impl<T, U> RamaTryFrom<T> for U
where U: TryFrom<T>,

§

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

§

fn rama_try_from(value: T) -> Result<U, <U as RamaTryFrom<T>>::Error>

§

impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for T
where U: RamaTryFrom<T, CrateMarker>,

§

type Error = <U as RamaTryFrom<T, CrateMarker>>::Error

§

fn rama_try_into(self) -> Result<U, <U as RamaTryFrom<T, CrateMarker>>::Error>

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,