Skip to main content

MessageBuilder

Struct MessageBuilder 

Source
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>

Source

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.

Source

pub fn checkpoint(&self) -> BuilderCheckpoint

Snapshot the full encode state — cursor, header counts, and compression-table size (see BuilderCheckpoint).

Source

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.

Source

pub fn push_question( &mut self, name: &Name, qtype: ResourceType, qclass: ResourceClass, unicast_response: bool, ) -> Result<(), EncodeError>

Append a question to the message.

Source

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.

Source

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.

Source

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.

Source

pub fn push_txt_answer<I, S>( &mut self, name: &Name, ttl: u32, segments: I, cache_flush: bool, ) -> Result<(), EncodeError>
where I: IntoIterator<Item = S>, S: AsRef<[u8]>,

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.

Source

pub fn push_ptr_answer( &mut self, name: &Name, ttl: u32, target: &Name, ) -> Result<(), EncodeError>

Append a PTR record answer.

Source

pub fn push_a_authority( &mut self, name: &Name, ttl: u32, addr: Ipv4Addr, ) -> Result<(), EncodeError>

Append an A record to the authority section.

Source

pub fn push_aaaa_authority( &mut self, name: &Name, ttl: u32, addr: Ipv6Addr, ) -> Result<(), EncodeError>

Append an AAAA record to the authority section.

Source

pub fn push_srv_authority( &mut self, name: &Name, ttl: u32, priority: u16, weight: u16, port: u16, target: &Name, ) -> Result<(), EncodeError>

Append an SRV record to the authority section.

Source

pub fn push_txt_authority<I, S>( &mut self, name: &Name, ttl: u32, segments: I, ) -> Result<(), EncodeError>
where I: IntoIterator<Item = S>, S: AsRef<[u8]>,

Append a TXT record to the authority section.

Source

pub fn push_ptr_authority( &mut self, name: &Name, ttl: u32, target: &Name, ) -> Result<(), EncodeError>

Append a PTR record to the authority section.

Source

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.

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more