Struct BinEncoder
pub struct BinEncoder<'a> { /* private fields */ }
Expand description
Encode DNS messages and resource record types.
Implementations§
§impl<'a> BinEncoder<'a>
impl<'a> BinEncoder<'a>
pub fn new(buf: &'a mut Vec<u8>) -> 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>
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>
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)
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> ⓘ
pub fn into_bytes(self) -> &'a Vec<u8> ⓘ
Returns a reference to the internal buffer
pub fn set_offset(&mut self, offset: usize)
pub fn set_offset(&mut self, offset: usize)
sets the current offset to the new offset
pub fn mode(&self) -> EncodeMode
pub fn mode(&self) -> EncodeMode
Returns the current Encoding mode
pub fn set_canonical_names(&mut self, canonical_names: bool)
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
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>
pub fn with_canonical_names<F>(&mut self, f: F) -> 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>
pub fn reserve(&mut self, _additional: usize) -> Result<(), ProtoError>
Reserve specified additional length in the internal buffer.
pub fn trim(&mut self)
pub fn trim(&mut self)
trims to the current offset
pub fn store_label_pointer(&mut self, start: usize, end: usize)
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>
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>
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>
pub fn emit_character_data<S>(&mut self, char_data: S) -> Result<(), ProtoError>
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>
pub fn emit_character_data_unrestricted<S>( &mut self, data: S, ) -> Result<(), ProtoError>
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>
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>
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>
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>
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>
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>
pub fn emit_all<'e, I, E>(&mut self, iter: I) -> Result<usize, ProtoError>
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>
pub fn emit_all_refs<'r, 'e, I, E>( &mut self, iter: I, ) -> Result<usize, ProtoError>
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>
pub fn emit_iter<'e, I, E>(&mut self, iter: &mut I) -> Result<usize, ProtoError>
emits all items in the iterator, return the number emitted
pub fn place<T>(&mut self) -> Result<Place<T>, ProtoError>where
T: EncodedSize,
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>) -> usizewhere
T: EncodedSize,
pub fn len_since_place<T>(&self, place: &Place<T>) -> usizewhere
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,
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§
§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