webrtc_mdns/message/resource/
srv.rs1use super::*;
2use crate::error::Result;
3use crate::message::name::*;
4use crate::message::packer::*;
5
6#[derive(Default, Debug, Clone, PartialEq, Eq)]
8pub struct SrvResource {
9 pub priority: u16,
10 pub weight: u16,
11 pub port: u16,
12 pub target: Name, }
14
15impl fmt::Display for SrvResource {
16 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17 write!(
18 f,
19 "dnsmessage.SRVResource{{priority: {}, weight: {}, port: {}, target: {}}}",
20 self.priority, self.weight, self.port, self.target
21 )
22 }
23}
24
25impl ResourceBody for SrvResource {
26 fn real_type(&self) -> DnsType {
27 DnsType::Srv
28 }
29
30 fn pack(
32 &self,
33 mut msg: Vec<u8>,
34 _compression: &mut Option<HashMap<String, usize>>,
35 compression_off: usize,
36 ) -> Result<Vec<u8>> {
37 msg = pack_uint16(msg, self.priority);
38 msg = pack_uint16(msg, self.weight);
39 msg = pack_uint16(msg, self.port);
40 msg = self.target.pack(msg, &mut None, compression_off)?;
41 Ok(msg)
42 }
43
44 fn unpack(&mut self, msg: &[u8], off: usize, _length: usize) -> Result<usize> {
45 let (priority, off) = unpack_uint16(msg, off)?;
46 self.priority = priority;
47
48 let (weight, off) = unpack_uint16(msg, off)?;
49 self.weight = weight;
50
51 let (port, off) = unpack_uint16(msg, off)?;
52 self.port = port;
53
54 let off = self
55 .target
56 .unpack_compressed(msg, off, false )?;
57
58 Ok(off)
59 }
60}