pub struct ModalEncoder<'a, 'e> { /* private fields */ }Expand description
This wraps a BinEncoder and applies different name encoding options.
Original name encoding options will be restored when this is dropped.
Methods from Deref<Target = BinEncoder<'a>>§
Sourcepub fn set_max_size(&mut self, max: u16)
pub fn set_max_size(&mut self, max: u16)
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
Sourcepub fn set_offset(&mut self, offset: usize)
pub fn set_offset(&mut self, offset: usize)
sets the current offset to the new offset
Sourcepub fn set_canonical_form(&mut self, canonical_form: bool)
pub fn set_canonical_form(&mut self, canonical_form: bool)
If set to true, then records will be written into the buffer in DNSSEC canonical form
Sourcepub fn is_canonical_form(&self) -> bool
pub fn is_canonical_form(&self) -> bool
Returns true if the encoder is writing in DNSSEC canonical form
Sourcepub fn set_name_encoding(&mut self, name_encoding: NameEncoding)
pub fn set_name_encoding(&mut self, name_encoding: NameEncoding)
Select how names are encoded
Sourcepub fn name_encoding(&self) -> NameEncoding
pub fn name_encoding(&self) -> NameEncoding
Returns the current name encoding mode
Sourcepub fn with_name_encoding<'e>(
&'e mut self,
name_encoding: NameEncoding,
) -> ModalEncoder<'a, 'e>
pub fn with_name_encoding<'e>( &'e mut self, name_encoding: NameEncoding, ) -> ModalEncoder<'a, 'e>
Returns a guard type that uses a different name encoding mode.
Sourcepub fn with_rdata_behavior<'e>(
&'e mut self,
rdata_encoding: RDataEncoding,
) -> ModalEncoder<'a, 'e>
pub fn with_rdata_behavior<'e>( &'e mut self, rdata_encoding: RDataEncoding, ) -> ModalEncoder<'a, 'e>
Returns a guard type that uses a different name encoding mode, for RDATA.
If the encoder is using canonical form, name compression will not be used. Otherwise, name compression will be used for standard record types.
If the encoder is using canonical form, the case of names will depend on the record type. Otherwise, the case will be unchanged.
Sourcepub fn store_label_pointer(&mut self, start: usize, end: usize)
pub fn store_label_pointer(&mut self, start: usize, end: usize)
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.
Sourcepub fn get_label_pointer(&self, start: usize, end: usize) -> Option<u16>
pub fn get_label_pointer(&self, start: usize, end: usize) -> Option<u16>
Looks up the index of an already written label
Sourcepub fn emit_character_data<S: AsRef<[u8]>>(
&mut self,
char_data: S,
) -> Result<(), ProtoError>
pub fn emit_character_data<S: AsRef<[u8]>>( &mut self, char_data: S, ) -> Result<(), ProtoError>
matches description from above.
use hickory_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']);Sourcepub fn emit_character_data_unrestricted<S: AsRef<[u8]>>(
&mut self,
data: S,
) -> Result<(), ProtoError>
pub fn emit_character_data_unrestricted<S: AsRef<[u8]>>( &mut self, data: S, ) -> Result<(), ProtoError>
Emit character data of unrestricted length
Although character strings are typically restricted to being no longer than 255 characters, some modern standards allow longer strings to be encoded.
Sourcepub fn emit_u16(&mut self, data: u16) -> Result<(), ProtoError>
pub fn emit_u16(&mut self, data: u16) -> Result<(), ProtoError>
Writes a u16 in network byte order to the buffer
Sourcepub fn emit_i32(&mut self, data: i32) -> Result<(), ProtoError>
pub fn emit_i32(&mut self, data: i32) -> Result<(), ProtoError>
Writes an i32 in network byte order to the buffer
Sourcepub fn emit_u32(&mut self, data: u32) -> Result<(), ProtoError>
pub fn emit_u32(&mut self, data: u32) -> Result<(), ProtoError>
Writes an u32 in network byte order to the buffer
Sourcepub fn emit_vec(&mut self, data: &[u8]) -> Result<(), ProtoError>
pub fn emit_vec(&mut self, data: &[u8]) -> Result<(), ProtoError>
Writes the byte slice to the stream
Sourcepub fn emit_all<'e, I: Iterator<Item = &'e E>, E: 'e + BinEncodable>(
&mut self,
iter: I,
) -> Result<usize, ProtoError>
pub fn emit_all<'e, I: Iterator<Item = &'e E>, E: 'e + BinEncodable>( &mut self, iter: I, ) -> Result<usize, ProtoError>
Emits all the elements of an Iterator to the encoder
Sourcepub fn emit_all_refs<'r, 'e, I, E>(
&mut self,
iter: I,
) -> Result<usize, ProtoError>
pub fn emit_all_refs<'r, 'e, I, E>( &mut self, iter: I, ) -> Result<usize, ProtoError>
Emits all the elements of an Iterator to the encoder
Sourcepub fn emit_iter<'e, I: Iterator<Item = &'e E>, E: 'e + BinEncodable>(
&mut self,
iter: &mut I,
) -> Result<usize, ProtoError>
pub fn emit_iter<'e, I: Iterator<Item = &'e E>, E: 'e + BinEncodable>( &mut self, iter: &mut I, ) -> Result<usize, ProtoError>
emits all items in the iterator, return the number emitted
Sourcepub fn place<T: EncodedSize>(&mut self) -> Result<Place<T>, ProtoError>
pub fn place<T: EncodedSize>(&mut self) -> Result<Place<T>, ProtoError>
capture a location to write back to
Sourcepub fn len_since_place<T: EncodedSize>(&self, place: &Place<T>) -> usize
pub fn len_since_place<T: EncodedSize>(&self, place: &Place<T>) -> usize
calculates the length of data written since the place was creating
Sourcepub fn emit_at<T: EncodedSize>(
&mut self,
place: Place<T>,
data: T,
) -> Result<(), ProtoError>
pub fn emit_at<T: EncodedSize>( &mut self, place: Place<T>, data: T, ) -> Result<(), ProtoError>
write back to a previously captured location