diameter_interface/modeling/avp/
octet_string.rs

1use crate::errors::DiameterResult;
2use crate::modeling::avp::avp::AvpValue;
3use crate::modeling::avp::AvpData;
4use std::io::{Read, Write};
5
6pub type OctetString = AvpData<Vec<u8>>;
7pub type DiameterURI = OctetString;
8
9impl OctetString {
10    pub(super) fn encode_to<W: Write>(&self, writer: &mut W) -> DiameterResult<()> {
11        writer.write(&self.0)?;
12        Ok(())
13    }
14
15    pub(super) fn decode_from<R: Read>(
16        reader: &mut R,
17        length: usize,
18    ) -> DiameterResult<AvpData<Vec<u8>>> {
19        let mut buffer = vec![0u8; length];
20        reader.read_exact(&mut buffer)?;
21        Ok(AvpData::<Vec<u8>>::new(buffer))
22    }
23
24    pub(super) fn len(&self) -> u32 {
25        self.0.len() as u32
26    }
27}
28
29impl Into<AvpValue> for OctetString {
30    fn into(self) -> AvpValue {
31        AvpValue::OctetString(self)
32    }
33}