[−][src]Struct trust_dns_proto::serialize::binary::BinEncoder
Encode DNS messages and resource record types.
Methods
impl<'a> BinEncoder<'a>
[src]
pub fn new(buf: &'a mut Vec<u8>) -> Self
[src]
Create a new encoder with the Vec to fill
pub fn with_mode(buf: &'a mut Vec<u8>, mode: EncodeMode) -> Self
[src]
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) -> Self
[src]
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)
[src]
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>
[src]
Returns a reference to the internal buffer
pub fn len(&self) -> usize
[src]
Returns the length of the buffer
pub fn is_empty(&self) -> bool
[src]
Returns true
if the buffer is empty
pub fn offset(&self) -> usize
[src]
Returns the current offset into the buffer
pub fn set_offset(&mut self, offset: usize)
[src]
sets the current offset to the new offset
pub fn mode(&self) -> EncodeMode
[src]
Returns the current Encoding mode
pub fn set_canonical_names(&mut self, canonical_names: bool)
[src]
If set to true, then names will be written into the buffer in canonical form
pub fn is_canonical_names(&self) -> bool
[src]
Returns true if then encoder is writing in canonical form
pub fn with_canonical_names<F: FnOnce(&mut Self) -> ProtoResult<()>>(
&mut self,
f: F
) -> ProtoResult<()>
[src]
&mut self,
f: F
) -> ProtoResult<()>
Emit all names in canonical form, useful for https://tools.ietf.org/html/rfc3597
pub fn reserve(&mut self, _additional: usize) -> ProtoResult<()>
[src]
Reserve specified additional length in the internal buffer.
pub fn trim(&mut self)
[src]
trims to the current offset
pub fn slice_of(&self, start: usize, end: usize) -> &[u8]
[src]
borrow a slice from the encoder
pub fn store_label_pointer(&mut self, start: usize, end: usize)
[src]
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>
[src]
Looks up the index of an already written label
pub fn emit(&mut self, b: u8) -> ProtoResult<()>
[src]
Emit one byte into the buffer
pub fn emit_character_data<S: AsRef<[u8]>>(
&mut self,
char_data: S
) -> ProtoResult<()>
[src]
&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']);
pub fn emit_u8(&mut self, data: u8) -> ProtoResult<()>
[src]
Emit one byte into the buffer
pub fn emit_u16(&mut self, data: u16) -> ProtoResult<()>
[src]
Writes a u16 in network byte order to the buffer
pub fn emit_i32(&mut self, data: i32) -> ProtoResult<()>
[src]
Writes an i32 in network byte order to the buffer
pub fn emit_u32(&mut self, data: u32) -> ProtoResult<()>
[src]
Writes an u32 in network byte order to the buffer
pub fn emit_vec(&mut self, data: &[u8]) -> ProtoResult<()>
[src]
Writes the byte slice to the stream
pub fn emit_all<'e, I: Iterator<Item = &'e E>, E: 'e + BinEncodable>(
&mut self,
iter: I
) -> ProtoResult<usize>
[src]
&mut self,
iter: I
) -> ProtoResult<usize>
Emits all the elements of an Iterator to the encoder
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,
[src]
'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: Iterator<Item = &'e E>, E: 'e + BinEncodable>(
&mut self,
iter: &mut I
) -> ProtoResult<usize>
[src]
&mut self,
iter: &mut I
) -> ProtoResult<usize>
emits all items in the iterator, return the number emited
pub fn place<T: EncodedSize>(&mut self) -> ProtoResult<Place<T>>
[src]
capture a location to write back to
pub fn len_since_place<T: EncodedSize>(&self, place: &Place<T>) -> usize
[src]
calculates the length of data written since the place was creating
pub fn emit_at<T: EncodedSize>(
&mut self,
place: Place<T>,
data: T
) -> ProtoResult<()>
[src]
&mut self,
place: Place<T>,
data: T
) -> ProtoResult<()>
write back to a previously captured location
Auto Trait Implementations
impl<'a> Send for BinEncoder<'a>
impl<'a> Sync for BinEncoder<'a>
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,