Skip to main content

mdns_proto/
transmit.rs

1//! Outgoing-datagram descriptor.
2
3use core::net::{IpAddr, SocketAddr};
4
5/// Outgoing datagram metadata produced by the proto state machines.
6///
7/// The proto writes the actual bytes into a caller-supplied `&mut [u8]`;
8/// this struct describes where the bytes go and how many were written.
9#[derive(Debug, Clone, Copy, Eq, PartialEq)]
10pub struct Transmit {
11  dst: SocketAddr,
12  src_ip: Option<IpAddr>,
13  size: usize,
14}
15
16impl Transmit {
17  /// Creates a new transmit descriptor.
18  #[inline(always)]
19  pub const fn new(dst: SocketAddr, src_ip: Option<IpAddr>, size: usize) -> Self {
20    Self { dst, src_ip, size }
21  }
22
23  /// Destination socket address (typically the mDNS multicast group).
24  #[inline(always)]
25  pub const fn dst(&self) -> SocketAddr {
26    self.dst
27  }
28
29  /// Source local IP, if the proto needs the caller to bind a specific
30  /// interface for this send.
31  #[inline(always)]
32  pub const fn src_ip(&self) -> Option<IpAddr> {
33    self.src_ip
34  }
35
36  /// Number of bytes written into the caller-supplied buffer.
37  #[inline(always)]
38  pub const fn size(&self) -> usize {
39    self.size
40  }
41}
42
43#[cfg(test)]
44mod tests;