22 lines
405 B
Rust
22 lines
405 B
Rust
|
use bytes::{Bytes, Buf};
|
||
|
use errors::*;
|
||
|
use std::io::Cursor;
|
||
|
|
||
|
mod std_impls;
|
||
|
|
||
|
pub trait DnsPacketData: Sized {
|
||
|
fn deserialize(data: &mut Cursor<Bytes>) -> Result<Self>;
|
||
|
}
|
||
|
|
||
|
pub fn deserialize<T>(data: Bytes) -> Result<T>
|
||
|
where
|
||
|
T: DnsPacketData
|
||
|
{
|
||
|
let mut c = Cursor::new(data);
|
||
|
let result = T::deserialize(&mut c)?;
|
||
|
if c.remaining() != 0 {
|
||
|
bail!("data remaining: {}", c.remaining())
|
||
|
}
|
||
|
Ok(result)
|
||
|
}
|