dns_server/dns_op_code.rs
1/// > `OPCODE` A four bit field that specifies kind of query in this message.
2/// > This value is set by the originator of a query and copied into
3/// > the response. The values are:
4/// > - `0` a standard query (`QUERY`)
5/// > - `1` an inverse query (`IQUERY`)
6/// > - `2` a server status request (`STATUS`)
7/// > - `3-15` reserved for future use
8///
9/// <https://datatracker.ietf.org/doc/html/rfc1035#section-4.1.1>
10#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
11pub enum DnsOpCode {
12 Query,
13 InverseQuery,
14 Status,
15 Reserved(u8),
16}
17impl DnsOpCode {
18 #[must_use]
19 pub fn new(value: u8) -> Self {
20 match value {
21 0 => DnsOpCode::Query,
22 1 => DnsOpCode::InverseQuery,
23 2 => DnsOpCode::Status,
24 other => DnsOpCode::Reserved(other),
25 }
26 }
27
28 #[must_use]
29 pub fn num(&self) -> u8 {
30 match self {
31 DnsOpCode::Query => 0,
32 DnsOpCode::InverseQuery => 1,
33 DnsOpCode::Status => 2,
34 DnsOpCode::Reserved(other) => *other,
35 }
36 }
37}