diameter_interface/modeling/avp/
ipv6.rs

1use crate::errors::DiameterResult;
2use crate::impl_avp_data_encode_to_address;
3use crate::modeling::avp::avp::AvpValue;
4use crate::modeling::avp::AvpData;
5use std::io::Read;
6use std::net::Ipv6Addr;
7
8pub type IPv6 = AvpData<Ipv6Addr>;
9
10impl IPv6 {
11    impl_avp_data_encode_to_address!(IPv6, Ipv6Addr);
12
13    pub(super) fn decode_from<R: Read>(reader: &mut R) -> DiameterResult<AvpData<Ipv6Addr>> {
14        let mut b = [0; 16];
15        reader.read_exact(&mut b)?;
16
17        let ip = Ipv6Addr::new(
18            (b[0] as u16) << 8 | b[1] as u16,
19            (b[2] as u16) << 8 | b[3] as u16,
20            (b[4] as u16) << 8 | b[5] as u16,
21            (b[6] as u16) << 8 | b[7] as u16,
22            (b[8] as u16) << 8 | b[9] as u16,
23            (b[10] as u16) << 8 | b[11] as u16,
24            (b[12] as u16) << 8 | b[13] as u16,
25            (b[14] as u16) << 8 | b[15] as u16,
26        );
27        Ok(IPv6::new(ip))
28    }
29
30    pub(super) fn len(&self) -> u32 {
31        16
32    }
33}
34
35impl Into<AvpValue> for IPv6 {
36    fn into(self) -> AvpValue {
37        AvpValue::AddressIPv6(self)
38    }
39}