pub struct MessageEncoder<'a, S>where
S: Section,{ /* private fields */ }Implementations§
Source§impl<'a, S> MessageEncoder<'a, S>where
S: Section,
impl<'a, S> MessageEncoder<'a, S>where
S: Section,
Sourcepub fn set_header(&mut self, header: Header)
pub fn set_header(&mut self, header: Header)
Sets the message header.
Note that the MessageEncoder will modify some header fields on drop, to ensure that the
message can be parsed correctly.
Sourcepub fn finish(self) -> Result<usize, Error>
pub fn finish(self) -> Result<usize, Error>
Finishes encoding the packet, and returns the number of bytes that were written to the buffer.
If the message was truncated because the provided buffer was too small, this will return
Error::Truncated, and the message’s truncation bit will be set. In that case,
the user can still decide to send the message.
Source§impl<'a> MessageEncoder<'a, Question>
impl<'a> MessageEncoder<'a, Question>
Sourcepub fn new(buf: &'a mut [u8]) -> MessageEncoder<'a, Question>
pub fn new(buf: &'a mut [u8]) -> MessageEncoder<'a, Question>
Creates a new message encoder that will write to buf.
Initially, the encoder will be in the Question state, in which questions can be appended
to the message by calling MessageEncoder::question. The encoder can either be moved to
the next section by calling the appropriate method, or be dropped, which will finish the
encoded message.
§Panics
buf must be large enough to fit at least the message header (size_of::<Header>()),
otherwise this function will panic.
Sourcepub fn answers(self) -> MessageEncoder<'a, Answer>
pub fn answers(self) -> MessageEncoder<'a, Answer>
Moves the encoder to the Answer section.
Source§impl<'a> MessageEncoder<'a, Answer>
impl<'a> MessageEncoder<'a, Answer>
pub fn add_answer(&mut self, rr: ResourceRecord<'_>)
Moves the encoder to the Authority section.
Source§impl<'a> MessageEncoder<'a, Authority>
impl<'a> MessageEncoder<'a, Authority>
Sourcepub fn additional(self) -> MessageEncoder<'a, Additional>
pub fn additional(self) -> MessageEncoder<'a, Additional>
Moves the encoder to the Additional Records section.