55 lines
1.4 KiB
Rust
55 lines
1.4 KiB
Rust
use bytes::Bytes;
|
|
use common_types::{Class, Type};
|
|
use common_types::classes;
|
|
use errors::*;
|
|
use ser::DnsPacketData;
|
|
use ser::text::{DnsTextData, DnsTextFormatter};
|
|
use std::fmt;
|
|
use std::io::Cursor;
|
|
|
|
pub trait RRDataPacket {
|
|
fn deserialize_rr_data(ttl: u32, rr_class: Class, rr_type: Type, data: &mut Cursor<Bytes>) -> Result<Self>
|
|
where
|
|
Self: Sized,
|
|
;
|
|
}
|
|
|
|
impl<T: DnsPacketData + StaticRRData> RRDataPacket for T {
|
|
fn deserialize_rr_data(_ttl: u32, rr_class: Class, rr_type: Type, data: &mut Cursor<Bytes>) -> Result<Self> {
|
|
ensure!(rr_type == T::TYPE, "type mismatch");
|
|
if T::CLASS != classes::ANY {
|
|
ensure!(rr_class == T::CLASS, "class mismatch");
|
|
}
|
|
T::deserialize(data)
|
|
}
|
|
}
|
|
|
|
pub trait RRDataText: Sized {
|
|
fn dns_parse_rr_data(ttl: u32, rr_class: Class, rr_type: Type, data: &mut &str) -> Result<Self>
|
|
where
|
|
Self: Sized,
|
|
;
|
|
|
|
// format might fail if there is no (known) text representation.
|
|
fn dns_format_rr_data(&self, f: &mut DnsTextFormatter) -> fmt::Result;
|
|
}
|
|
|
|
/*
|
|
impl<T: DnsTextData> RRDataText for T {
|
|
fn deserialize_rr_data(_ttl: u32, _rr_class: Class, _rr_type: Type, data: &mut Cursor<Bytes>) -> Result<Self> {
|
|
T::deserialize(data)
|
|
}
|
|
}
|
|
*/
|
|
|
|
pub trait RRData: RRDataPacket + DnsTextData {
|
|
fn rr_type(&self) -> Type;
|
|
}
|
|
|
|
pub trait StaticRRData: RRData {
|
|
const TYPE: Type;
|
|
const NAME: &'static str;
|
|
// classes::ANY marks class independent types
|
|
const CLASS: Class;
|
|
}
|