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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use crate::{Buffer, DnsMessage, DnsMessageError};
use crate::parse::Parse;
use crate::rdata::{RData, RDataParse};
use crate::write::WriteBytes;

/// # IPv6 address record
/// This record is used to return a IPv6 address for a host.
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct Aaaa {
    /// IPv6 address
    pub address: [u8; 16],
}

impl<'a> RDataParse<'a> for Aaaa {
    #[inline]
    fn parse(rdata: &RData<'a>, i: &mut usize) -> Result<Self, DnsMessageError> {
        Ok(Self { address: <[u8; 16]>::parse(rdata.buffer, i)? })
    }
}

impl WriteBytes for Aaaa {
    #[inline]
    fn write<
        const PTR_STORAGE: usize,
        const DNS_SECTION: usize,
        B: Buffer,
    >(&self, message: &mut DnsMessage<PTR_STORAGE, DNS_SECTION, B>) -> Result<usize, DnsMessageError> {
        self.address.write(message)
    }
}

#[cfg(test)]
mod test {
    use crate::rdata::testutils::parse_write_test;

    use super::*;

    parse_write_test!(
        16,
        [
            0x01, 0x02, 0x03, 0x04,
            0x01, 0x02, 0x03, 0x04,
            0x01, 0x02, 0x03, 0x04,
            0x01, 0x02, 0x03, 0x04,
        ],
        Aaaa {
            address: [
                0x01, 0x02, 0x03, 0x04,
                0x01, 0x02, 0x03, 0x04,
                0x01, 0x02, 0x03, 0x04,
                0x01, 0x02, 0x03, 0x04,
            ],
        },
    );
}