webrtc_mdns/message/
question.rs

1use std::collections::HashMap;
2use std::fmt;
3
4use super::name::*;
5use super::*;
6use crate::error::Result;
7
8// A question is a DNS query.
9#[derive(Default, Debug, PartialEq, Eq, Clone)]
10pub struct Question {
11    pub name: Name,
12    pub typ: DnsType,
13    pub class: DnsClass,
14}
15
16impl fmt::Display for Question {
17    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
26impl Question {
27    // pack appends the wire format of the question to msg.
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}