diameter_interface/modeling/avp/
ipv4.rs1use 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::Ipv4Addr;
7
8pub type IPv4 = AvpData<Ipv4Addr>;
9
10impl IPv4 {
11 impl_avp_data_encode_to_address!(IPv4, Ipv4Addr);
12
13 pub(super) fn decode_from<R: Read>(reader: &mut R) -> DiameterResult<AvpData<Ipv4Addr>> {
14 let mut b = [0; 4];
15 reader.read_exact(&mut b)?;
16 let ip = Ipv4Addr::new(b[0], b[1], b[2], b[3]);
17 Ok(IPv4::new(ip))
18 }
19
20 pub(super) fn len(&self) -> u32 {
21 4
22 }
23}
24
25impl Into<AvpValue> for IPv4 {
26 fn into(self) -> AvpValue {
27 AvpValue::AddressIPv4(self)
28 }
29}