use core::mem::size_of;
use crate::{Error};
#[derive(Copy, Clone, Debug, PartialEq)]
#[repr(u16)]
pub enum QueryClass {
IN = 1,
CS = 2,
CH = 3,
HS = 4,
Reserved,
}
impl QueryClass {
pub(crate) fn read(buf: &[u8], i: &mut usize) -> Result<Self, Error> {
if *i + size_of::<QueryClass>() <= buf.len() {
let query_class = u16::from_be_bytes([buf[*i], buf[*i + 1]]);
*i += size_of::<QueryClass>();
return Ok(query_class.into())
}
Err(Error::MessageTooShort)
}
pub fn to_be_bytes(self) -> [u8; 2] {
(self as u16).to_be_bytes()
}
}
impl From<u16> for QueryClass {
fn from(n: u16) -> Self {
match n {
1 => Self::IN,
2 => Self::CS,
3 => Self::CH,
4 => Self::HS,
_ => Self::Reserved,
}
}
}