diameter_interface/modeling/avp/
float32.rs

1use crate::errors::DiameterResult;
2use crate::impl_avp_data_encode_to_numbers;
3use crate::modeling::avp::AvpData;
4use crate::modeling::avp::avp::AvpValue;
5use std::io::Read;
6
7pub type Float32 = AvpData<f32>;
8
9impl Float32 {
10    impl_avp_data_encode_to_numbers!(Float32, f32);
11
12    pub(super) fn decode_from<R: Read>(reader: &mut R) -> DiameterResult<AvpData<f32>> {
13        let mut buffer = [0u8; 4];
14        reader.read_exact(&mut buffer)?;
15        let num = f32::from_be_bytes(buffer);
16        Ok(Float32::new(num))
17    }
18
19    pub(super) fn len(&self) -> u32 {
20        4
21    }
22}
23
24impl Into<AvpValue> for Float32 {
25    fn into(self) -> AvpValue {
26        AvpValue::Float32(self)
27    }
28}