Struct trust_dns_proto::serialize::binary::BinEncoder
source · [−]pub struct BinEncoder<'a> { /* private fields */ }
Expand description
Encode DNS messages and resource record types.
Implementations
sourceimpl<'a> BinEncoder<'a>
impl<'a> BinEncoder<'a>
sourcepub fn with_mode(buf: &'a mut Vec<u8>, mode: EncodeMode) -> Self
pub fn with_mode(buf: &'a mut Vec<u8>, mode: EncodeMode) -> Self
Specify the mode for encoding
Arguments
mode
- In Signing mode, canonical forms of all data are encoded, otherwise format matches the source form
sourcepub fn with_offset(buf: &'a mut Vec<u8>, offset: u32, mode: EncodeMode) -> Self
pub fn with_offset(buf: &'a mut Vec<u8>, offset: u32, mode: EncodeMode) -> Self
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
sourcepub 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
sourcepub fn into_bytes(self) -> &'a Vec<u8>
pub fn into_bytes(self) -> &'a Vec<u8>
Returns a reference to the internal buffer
sourcepub fn set_offset(&mut self, offset: usize)
pub fn set_offset(&mut self, offset: usize)
sets the current offset to the new offset
sourcepub fn mode(&self) -> EncodeMode
pub fn mode(&self) -> EncodeMode
Returns the current Encoding mode
sourcepub 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
sourcepub fn is_canonical_names(&self) -> bool
pub fn is_canonical_names(&self) -> bool
Returns true if then encoder is writing in canonical form
sourcepub fn with_canonical_names<F: FnOnce(&mut Self) -> ProtoResult<()>>(
&mut self,
f: F
) -> ProtoResult<()>
pub fn with_canonical_names<F: FnOnce(&mut Self) -> ProtoResult<()>>(
&mut self,
f: F
) -> ProtoResult<()>
Emit all names in canonical form, useful for https://tools.ietf.org/html/rfc3597
sourcepub fn reserve(&mut self, _additional: usize) -> ProtoResult<()>
pub fn reserve(&mut self, _additional: usize) -> ProtoResult<()>
Reserve specified additional length in the internal buffer.
sourcepub fn slice_of(&self, start: usize, end: usize) -> &[u8]ⓘNotable traits for &'_ mut [u8]impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
pub fn slice_of(&self, start: usize, end: usize) -> &[u8]ⓘNotable traits for &'_ mut [u8]impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
borrow a slice from the encoder
sourcepub 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.
sourcepub 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
sourcepub fn emit(&mut self, b: u8) -> ProtoResult<()>
pub fn emit(&mut self, b: u8) -> ProtoResult<()>
Emit one byte into the buffer
sourcepub fn emit_character_data<S: AsRef<[u8]>>(
&mut self,
char_data: S
) -> ProtoResult<()>
pub fn emit_character_data<S: AsRef<[u8]>>(
&mut self,
char_data: S
) -> ProtoResult<()>
matches description from above.
use trust_dns_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']);
sourcepub fn emit_u8(&mut self, data: u8) -> ProtoResult<()>
pub fn emit_u8(&mut self, data: u8) -> ProtoResult<()>
Emit one byte into the buffer
sourcepub fn emit_u16(&mut self, data: u16) -> ProtoResult<()>
pub fn emit_u16(&mut self, data: u16) -> ProtoResult<()>
Writes a u16 in network byte order to the buffer
sourcepub fn emit_i32(&mut self, data: i32) -> ProtoResult<()>
pub fn emit_i32(&mut self, data: i32) -> ProtoResult<()>
Writes an i32 in network byte order to the buffer
sourcepub fn emit_u32(&mut self, data: u32) -> ProtoResult<()>
pub fn emit_u32(&mut self, data: u32) -> ProtoResult<()>
Writes an u32 in network byte order to the buffer
sourcepub fn emit_all<'e, I: Iterator<Item = &'e E>, E: 'e + BinEncodable>(
&mut self,
iter: I
) -> ProtoResult<usize>
pub fn emit_all<'e, I: Iterator<Item = &'e E>, E: 'e + BinEncodable>(
&mut self,
iter: I
) -> ProtoResult<usize>
Emits all the elements of an Iterator to the encoder
sourcepub fn emit_all_refs<'r, 'e, I, E>(&mut self, iter: I) -> ProtoResult<usize> where
'e: 'r,
I: Iterator<Item = &'r &'e E>,
E: 'r + 'e + BinEncodable,
pub fn emit_all_refs<'r, 'e, I, E>(&mut self, iter: I) -> ProtoResult<usize> where
'e: 'r,
I: Iterator<Item = &'r &'e E>,
E: 'r + 'e + BinEncodable,
Emits all the elements of an Iterator to the encoder
sourcepub fn emit_iter<'e, I: Iterator<Item = &'e E>, E: 'e + BinEncodable>(
&mut self,
iter: &mut I
) -> ProtoResult<usize>
pub fn emit_iter<'e, I: Iterator<Item = &'e E>, E: 'e + BinEncodable>(
&mut self,
iter: &mut I
) -> ProtoResult<usize>
emits all items in the iterator, return the number emitted
sourcepub fn place<T: EncodedSize>(&mut self) -> ProtoResult<Place<T>>
pub fn place<T: EncodedSize>(&mut self) -> ProtoResult<Place<T>>
capture a location to write back to
sourcepub fn len_since_place<T: EncodedSize>(&self, place: &Place<T>) -> usize
pub fn len_since_place<T: EncodedSize>(&self, place: &Place<T>) -> usize
calculates the length of data written since the place was creating
sourcepub fn emit_at<T: EncodedSize>(
&mut self,
place: Place<T>,
data: T
) -> ProtoResult<()>
pub fn emit_at<T: EncodedSize>(
&mut self,
place: Place<T>,
data: T
) -> ProtoResult<()>
write back to a previously captured location
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more