Struct trust_dns::serialize::binary::BinEncoder
[−]
[src]
pub struct BinEncoder<'a> { /* fields omitted */ }
Encode DNS messages and resource record types.
Methods
impl<'a> BinEncoder<'a>
[src]
fn new(buf: &'a mut Vec<u8>) -> Self
Create a new encoder with the Vec to fill
fn with_mode(buf: &'a mut Vec<u8>, mode: EncodeMode) -> Self
Specify the mode for encoding
Arguments
mode
- In Signing mode, it canonical forms of all data are encoded, otherwise format matches the source form
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
fn as_bytes(self) -> &'a Vec<u8>
Returns a reference to the internal buffer
fn len(&self) -> usize
Returns the length of the buffer
fn offset(&self) -> u32
Returns the current offset into the buffer
fn mode(&self) -> EncodeMode
Returns the current Encoding mode
fn set_canonical_names(&mut self, canonical_names: bool)
If set to true, then names will be written into the buffer in canonical form
fn is_canonical_names(&self) -> bool
Returns true if then encoder is writing in canonical form
fn reserve(&mut self, extra: usize)
Reserve specified length in the internal buffer
fn emit(&mut self, b: u8) -> EncodeResult
Emit one byte into the buffer
fn store_label_pointer(&mut self, labels: Vec<Rc<String>>)
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.
fn get_label_pointer(&self, labels: &[Rc<String>]) -> Option<u16>
Looks up the index of an already written label
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
Writes a u16 in network byte order to the buffer
fn emit_i32(&mut self, data: i32) -> EncodeResult
Writes an i32 in network byte order to the buffer
fn emit_u32(&mut self, data: u32) -> EncodeResult
Writes an u32 in network byte order to the buffer
fn emit_vec(&mut self, data: &[u8]) -> EncodeResult
Writes the byte slice to the stream