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
40
41
// TODO TEMP until switching to unreleased protobuf:
//#![deny(warnings, rust_2018_idioms)]

use bytes::BytesMut;
use std::io;
use tokio_codec::{Decoder, Encoder};

use super::proto::dns_wire::WireResponse;

/// A `Codec` implementation that creates and parses DNS responses.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct DNSResponseCodec {}

impl DNSResponseCodec {
    /// Returns a `DNSClientCodec` for creating and parsing DNS responses.
    pub fn new() -> DNSResponseCodec {
        DNSResponseCodec {}
    }
}

/// Deserializes DNS responses.
impl Decoder for DNSResponseCodec {
    type Item = WireResponse;
    type Error = io::Error;

    fn decode(&mut self, _buf: &mut BytesMut) -> Result<Option<WireResponse>, io::Error> {
        // TODO parse buf -> response
        Ok(None)
    }
}

/// Serializes DNS responses.
impl Encoder for DNSResponseCodec {
    type Item = WireResponse;
    type Error = io::Error;

    fn encode(&mut self, _response: WireResponse, _buf: &mut BytesMut) -> Result<(), io::Error> {
        // TODO write response -> buf
        Ok(())
    }
}