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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
use std::fmt::{self, Display};
use crate::proto::error::*;
use crate::op::Query;
use crate::rr::{DNSClass, LowerName, RecordType};
use crate::serialize::binary::*;
#[derive(Clone, Debug, PartialEq)]
pub struct LowerQuery {
name: LowerName,
original: Query,
}
impl LowerQuery {
pub fn query(query: Query) -> Self {
LowerQuery {
name: LowerName::new(query.name()),
original: query,
}
}
pub fn name(&self) -> &LowerName {
&self.name
}
pub fn original(&self) -> &Query {
&self.original
}
pub fn query_type(&self) -> RecordType {
self.original.query_type()
}
pub fn query_class(&self) -> DNSClass {
self.original.query_class()
}
}
impl From<Query> for LowerQuery {
fn from(query: Query) -> LowerQuery {
LowerQuery::query(query)
}
}
impl BinEncodable for LowerQuery {
fn emit(&self, encoder: &mut BinEncoder) -> ProtoResult<()> {
self.original.emit(encoder)
}
}
impl<'r> BinDecodable<'r> for LowerQuery {
fn read(decoder: &mut BinDecoder<'r>) -> ProtoResult<Self> {
let original = Query::read(decoder)?;
Ok(LowerQuery::query(original))
}
}
impl Display for LowerQuery {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(
f,
"name: {} type: {} class: {}",
self.name,
self.original.query_type(),
self.original.query_class()
)
}
}