-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquerytype.rs
39 lines (37 loc) · 912 Bytes
/
querytype.rs
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
#[derive(PartialEq, Eq, Debug, Clone, Hash, Copy)]
pub enum QueryType {
Unknown(u16),
A, // 1
NS, // 2
Cname, // 5
Soa, // 6
MX , // 15
Txt, // 16
Aaaa, // 28
}
impl QueryType {
pub fn to_num(self) -> u16 {
match self {
QueryType::Unknown(x) => x,
QueryType::A => 1,
QueryType::NS => 2,
QueryType::Cname => 5,
QueryType::Soa => 6,
QueryType::MX => 15,
QueryType::Txt => 16,
QueryType::Aaaa => 28,
}
}
pub fn from_num(num: u16) -> QueryType {
match num {
1 => QueryType::A,
2 => QueryType::NS,
5 => QueryType::Cname,
6 => QueryType::Soa,
15 => QueryType::MX,
16 => QueryType::Txt,
28 => QueryType::Aaaa,
_ => QueryType::Unknown(num),
}
}
}