pub struct MessageBuilder<'a, const COMP_N: usize = mdns_proto::::wire::builder::MessageBuilder::{constant#0}> { /* private fields */ }Expand description
Incremental mDNS message encoder.
Implementations§
Source§impl<'a, const COMP_N: usize> MessageBuilder<'a, COMP_N>
impl<'a, const COMP_N: usize> MessageBuilder<'a, COMP_N>
Sourcepub fn try_new(
out: &'a mut [u8],
header: Header,
) -> Result<MessageBuilder<'a, COMP_N>, EncodeError>
pub fn try_new( out: &'a mut [u8], header: Header, ) -> Result<MessageBuilder<'a, COMP_N>, EncodeError>
Begin building. Reserves the 12-byte header slot and finalises it on
Self::finish.
Sourcepub fn checkpoint(&self) -> BuilderCheckpoint
pub fn checkpoint(&self) -> BuilderCheckpoint
Snapshot the full encode state — cursor, header counts, and
compression-table size (see BuilderCheckpoint).
Sourcepub fn restore(&mut self, cp: BuilderCheckpoint)
pub fn restore(&mut self, cp: BuilderCheckpoint)
Roll back to a Self::checkpoint, fully restoring the encode state: the
write cursor, the header counts, AND the compression table — entries
recorded after the snapshot are dropped. Without truncating the
table, a later write_name could emit a back-reference pointer into the
rolled-back (now-overwritten) region and corrupt the message; restoring
used makes those stale entries invisible to lookup, so appending after
a restore is safe.
Sourcepub fn push_question(
&mut self,
name: &Name,
qtype: ResourceType,
qclass: ResourceClass,
unicast_response: bool,
) -> Result<(), EncodeError>
pub fn push_question( &mut self, name: &Name, qtype: ResourceType, qclass: ResourceClass, unicast_response: bool, ) -> Result<(), EncodeError>
Append a question to the message.
Sourcepub fn push_a_answer(
&mut self,
name: &Name,
ttl: u32,
addr: Ipv4Addr,
cache_flush: bool,
) -> Result<(), EncodeError>
pub fn push_a_answer( &mut self, name: &Name, ttl: u32, addr: Ipv4Addr, cache_flush: bool, ) -> Result<(), EncodeError>
Append an A record answer.
cache_flush — when true, the cache-flush bit (RFC 6762 §10.2, bit 15
of the class field) is set. Set this for unique records (A/AAAA/SRV/TXT
owned by a single host); leave clear for shared records such as PTR.
Sourcepub fn push_aaaa_answer(
&mut self,
name: &Name,
ttl: u32,
addr: Ipv6Addr,
cache_flush: bool,
) -> Result<(), EncodeError>
pub fn push_aaaa_answer( &mut self, name: &Name, ttl: u32, addr: Ipv6Addr, cache_flush: bool, ) -> Result<(), EncodeError>
Append an AAAA record answer.
cache_flush — when true, the cache-flush bit (RFC 6762 §10.2) is set.
Unique records such as AAAA should always set this.
Sourcepub fn push_srv_answer(
&mut self,
name: &Name,
ttl: u32,
priority: u16,
weight: u16,
port: u16,
target: &Name,
cache_flush: bool,
) -> Result<(), EncodeError>
pub fn push_srv_answer( &mut self, name: &Name, ttl: u32, priority: u16, weight: u16, port: u16, target: &Name, cache_flush: bool, ) -> Result<(), EncodeError>
Append an SRV record answer.
cache_flush — when true, the cache-flush bit (RFC 6762 §10.2) is set.
SRV records are unique and should always set this.
Sourcepub fn push_txt_answer<I, S>(
&mut self,
name: &Name,
ttl: u32,
segments: I,
cache_flush: bool,
) -> Result<(), EncodeError>
pub fn push_txt_answer<I, S>( &mut self, name: &Name, ttl: u32, segments: I, cache_flush: bool, ) -> Result<(), EncodeError>
Append a TXT record answer.
cache_flush — when true, the cache-flush bit (RFC 6762 §10.2) is set.
TXT records are unique and should always set this.
Sourcepub fn push_ptr_answer(
&mut self,
name: &Name,
ttl: u32,
target: &Name,
) -> Result<(), EncodeError>
pub fn push_ptr_answer( &mut self, name: &Name, ttl: u32, target: &Name, ) -> Result<(), EncodeError>
Append a PTR record answer.
Append an A record to the authority section.
Append an AAAA record to the authority section.
Append an SRV record to the authority section.
Append a TXT record to the authority section.
Append a PTR record to the authority section.
Sourcepub fn push_nsec_additional(
&mut self,
name: &Name,
ttl: u32,
present_types: &[u16],
cache_flush: bool,
) -> Result<(), EncodeError>
pub fn push_nsec_additional( &mut self, name: &Name, ttl: u32, present_types: &[u16], cache_flush: bool, ) -> Result<(), EncodeError>
Append an NSEC record to the additional section (RFC 6762 §6.1,
“negative responses”). present_types lists the resource-record types
that DO exist at name — e.g. [A] for an IPv4-only host, or
[SRV, TXT] for a service instance. A querier asking for any type NOT in
the bitmap thereby learns authoritatively that no such record exists,
instead of waiting out a retransmission timeout. The NSEC “Next Domain
Name” field is the owner name itself (§6.1; legacy DNSSEC chaining does
not apply to mDNS). Every type must be < 256 so it maps into RFC 4034
§4.1.2 window block 0 — the only block mDNS service types need; any
>= 256 entry is ignored.
cache_flush — set for the unique RRset this NSEC asserts (RFC 6762
§10.2), as the host/instance records it describes are themselves unique.
Sourcepub fn finish(self) -> Result<usize, EncodeError>
pub fn finish(self) -> Result<usize, EncodeError>
Finalise: write the header into the reserved 12-byte slot and return the total number of bytes written.
Auto Trait Implementations§
impl<'a, const COMP_N: usize = mdns_proto::::wire::builder::MessageBuilder::{constant#0}> !UnwindSafe for MessageBuilder<'a, COMP_N>
impl<'a, const COMP_N: usize> Freeze for MessageBuilder<'a, COMP_N>
impl<'a, const COMP_N: usize> RefUnwindSafe for MessageBuilder<'a, COMP_N>
impl<'a, const COMP_N: usize> Send for MessageBuilder<'a, COMP_N>
impl<'a, const COMP_N: usize> Sync for MessageBuilder<'a, COMP_N>
impl<'a, const COMP_N: usize> Unpin for MessageBuilder<'a, COMP_N>
impl<'a, const COMP_N: usize> UnsafeUnpin for MessageBuilder<'a, COMP_N>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more