1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use super::*;
use crate::error::Result;
use crate::message::name::*;
use crate::message::packer::*;
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct MxResource {
pub pref: u16,
pub mx: Name,
}
impl fmt::Display for MxResource {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"dnsmessage.MXResource{{pref: {}, mx: {}}}",
self.pref, self.mx
)
}
}
impl ResourceBody for MxResource {
fn real_type(&self) -> DnsType {
DnsType::Mx
}
fn pack(
&self,
mut msg: Vec<u8>,
compression: &mut Option<HashMap<String, usize>>,
compression_off: usize,
) -> Result<Vec<u8>> {
msg = pack_uint16(msg, self.pref);
msg = self.mx.pack(msg, compression, compression_off)?;
Ok(msg)
}
fn unpack(&mut self, msg: &[u8], off: usize, _length: usize) -> Result<usize> {
let (pref, off) = unpack_uint16(msg, off)?;
self.pref = pref;
self.mx.unpack(msg, off)
}
}