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>) -> BinEncoder<'a>
[src]
Create a new encoder with the Vec to fill
fn with_mode(buf: &'a mut Vec<u8>, mode: EncodeMode) -> BinEncoder<'a>
[src]
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
) -> BinEncoder<'a>
[src]
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
fn into_bytes(self) -> &'a Vec<u8>
[src]
Returns a reference to the internal buffer
fn len(&self) -> usize
[src]
Returns the length of the buffer
fn is_empty(&self) -> bool
[src]
Returns true
if the buffer is empty
fn offset(&self) -> u32
[src]
Returns the current offset into the buffer
fn mode(&self) -> EncodeMode
[src]
Returns the current Encoding mode
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
fn is_canonical_names(&self) -> bool
[src]
Returns true if then encoder is writing in canonical form
fn reserve(&mut self, extra: usize)
[src]
Reserve specified length in the internal buffer
fn emit(&mut self, b: u8) -> Result<(), ProtoError>
[src]
Emit one byte into the buffer
fn store_label_pointer(&mut self, labels: Vec<Arc<String>>)
[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.
fn get_label_pointer(&self, labels: &[Arc<String>]) -> Option<u16>
[src]
Looks up the index of an already written label
fn emit_character_data(&mut self, char_data: &str) -> Result<(), ProtoError>
[src]
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']);
fn emit_u8(&mut self, data: u8) -> Result<(), ProtoError>
[src]
Emit one byte into the buffer
fn emit_u16(&mut self, data: u16) -> Result<(), ProtoError>
[src]
Writes a u16 in network byte order to the buffer
fn emit_i32(&mut self, data: i32) -> Result<(), ProtoError>
[src]
Writes an i32 in network byte order to the buffer
fn emit_u32(&mut self, data: u32) -> Result<(), ProtoError>
[src]
Writes an u32 in network byte order to the buffer
fn emit_vec(&mut self, data: &[u8]) -> Result<(), ProtoError>
[src]
Writes the byte slice to the stream