xref: /webrtc/mdns/src/message/question.rs (revision ffe74184)
1 use super::name::*;
2 use super::*;
3 use crate::error::Result;
4 
5 use std::collections::HashMap;
6 use std::fmt;
7 
8 // A question is a DNS query.
9 #[derive(Default, Debug, PartialEq, Eq, Clone)]
10 pub struct Question {
11     pub name: Name,
12     pub typ: DnsType,
13     pub class: DnsClass,
14 }
15 
16 impl fmt::Display for Question {
fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result17     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18         write!(
19             f,
20             "dnsmessage.question{{Name: {}, Type: {}, Class: {}}}",
21             self.name, self.typ, self.class
22         )
23     }
24 }
25 
26 impl Question {
27     // pack appends the wire format of the question to msg.
pack( &self, mut msg: Vec<u8>, compression: &mut Option<HashMap<String, usize>>, compression_off: usize, ) -> Result<Vec<u8>>28     pub fn pack(
29         &self,
30         mut msg: Vec<u8>,
31         compression: &mut Option<HashMap<String, usize>>,
32         compression_off: usize,
33     ) -> Result<Vec<u8>> {
34         msg = self.name.pack(msg, compression, compression_off)?;
35         msg = self.typ.pack(msg);
36         Ok(self.class.pack(msg))
37     }
38 }
39