xref: /webrtc/mdns/src/message/resource/a.rs (revision ffe74184)
1 use super::*;
2 use crate::message::packer::*;
3 
4 // An AResource is an A Resource record.
5 #[derive(Default, Debug, Clone, PartialEq, Eq)]
6 pub struct AResource {
7     pub a: [u8; 4],
8 }
9 
10 impl fmt::Display for AResource {
fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result11     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
12         write!(f, "dnsmessage.AResource{{A: {:?}}}", self.a)
13     }
14 }
15 
16 impl ResourceBody for AResource {
real_type(&self) -> DnsType17     fn real_type(&self) -> DnsType {
18         DnsType::A
19     }
20 
21     // pack appends the wire format of the AResource to msg.
pack( &self, msg: Vec<u8>, _compression: &mut Option<HashMap<String, usize>>, _compression_off: usize, ) -> Result<Vec<u8>>22     fn pack(
23         &self,
24         msg: Vec<u8>,
25         _compression: &mut Option<HashMap<String, usize>>,
26         _compression_off: usize,
27     ) -> Result<Vec<u8>> {
28         Ok(pack_bytes(msg, &self.a))
29     }
30 
unpack(&mut self, msg: &[u8], off: usize, _length: usize) -> Result<usize>31     fn unpack(&mut self, msg: &[u8], off: usize, _length: usize) -> Result<usize> {
32         unpack_bytes(msg, off, &mut self.a)
33     }
34 }
35