Struct trust_dns_proto::serialize::binary::BinEncoder [−][src]
pub struct BinEncoder<'a> { /* fields omitted */ }
Expand description
Encode DNS messages and resource record types.
Implementations
Specify the mode for encoding
Arguments
mode
- In Signing mode, canonical forms of all data are encoded, otherwise format matches the source form
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
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
Returns a reference to the internal buffer
sets the current offset to the new offset
Returns the current Encoding mode
If set to true, then names will be written into the buffer in canonical form
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<()>
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
Reserve specified additional length in the internal buffer.
borrow a slice from the encoder
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.
Looks up the index of an already written label
Emit one byte into the buffer
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']);
Emit one byte into the buffer
Writes a u16 in network byte order to the buffer
Writes an i32 in network byte order to the buffer
Writes an u32 in network byte order to the buffer
pub 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
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,
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
pub 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
capture a location to write back to
calculates the length of data written since the place was creating
write back to a previously captured location