Struct trust_dns::serialize::binary::BinEncoder [] [src]

pub struct BinEncoder<'a> {
    // some fields omitted
}

Encode DNS messages and resource record types.

Methods

impl<'a> BinEncoder<'a>

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

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

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

offset is used mainly 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.

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

fn len(&self) -> usize

fn offset(&self) -> u32

fn mode(&self) -> EncodeMode

fn set_canonical_names(&mut self, canonical_names: bool)

fn is_canonical_names(&self) -> bool

fn reserve(&mut self, extra: usize)

fn emit(&mut self, b: u8) -> EncodeResult

fn store_label_pointer(&mut self, labels: Vec<Rc<String>>)

store the label pointer, the location is the current position in the buffer implicitly, it is expected that the name will be written to the stream after this.

fn get_label_pointer(&self, labels: &[Rc<String>]) -> Option<u16>

fn emit_character_data(&mut self, char_data: &str) -> EncodeResult

matches description from above.

use trust_dns::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']);

fn emit_u16(&mut self, data: u16) -> EncodeResult

fn emit_i32(&mut self, data: i32) -> EncodeResult

fn emit_u32(&mut self, data: u32) -> EncodeResult

fn emit_vec(&mut self, data: &[u8]) -> EncodeResult