Skip to main content

ModalEncoder

Struct ModalEncoder 

pub struct ModalEncoder<'a, 'e> { /* private fields */ }
Expand description

This wraps a BinEncoder and applies different name encoding options.

Original name encoding options will be restored when this is dropped.

Methods from Deref<Target = BinEncoder<'a>>§

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 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 set_canonical_form(&mut self, canonical_form: bool)

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

pub fn is_canonical_form(&self) -> bool

Returns true if the encoder is writing in DNSSEC canonical form

pub fn set_name_encoding(&mut self, name_encoding: NameEncoding)

Select how names are encoded

pub fn name_encoding(&self) -> NameEncoding

Returns the current name encoding mode

pub fn with_name_encoding<'e>( &'e mut self, name_encoding: NameEncoding, ) -> ModalEncoder<'a, 'e>

Returns a guard type that uses a different name encoding mode.

pub fn with_rdata_behavior<'e>( &'e mut self, rdata_encoding: RDataEncoding, ) -> ModalEncoder<'a, 'e>

Returns a guard type that uses a different name encoding mode, for RDATA.

If the encoder is using canonical form, name compression will not be used. Otherwise, name compression will be used for standard record types.

If the encoder is using canonical form, the case of names will depend on the record type. Otherwise, the case will be unchanged.

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

Trait Implementations§

§

impl<'a> Deref for ModalEncoder<'a, '_>

§

type Target = BinEncoder<'a>

The resulting type after dereferencing.
§

fn deref(&self) -> &<ModalEncoder<'a, '_> as Deref>::Target

Dereferences the value.
§

impl DerefMut for ModalEncoder<'_, '_>

§

fn deref_mut(&mut self) -> &mut <ModalEncoder<'_, '_> as Deref>::Target

Mutably dereferences the value.
§

impl Drop for ModalEncoder<'_, '_>

§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, 'e> Freeze for ModalEncoder<'a, 'e>

§

impl<'a, 'e> RefUnwindSafe for ModalEncoder<'a, 'e>

§

impl<'a, 'e> Send for ModalEncoder<'a, 'e>

§

impl<'a, 'e> Sync for ModalEncoder<'a, 'e>

§

impl<'a, 'e> Unpin for ModalEncoder<'a, 'e>

§

impl<'a, 'e> UnsafeUnpin for ModalEncoder<'a, 'e>

§

impl<'a, 'e> !UnwindSafe for ModalEncoder<'a, 'e>

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> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a rama_grpc::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
§

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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