sctp_async/param/
param_heartbeat_info.rs

1use super::{param_header::*, param_type::*, *};
2
3use bytes::{Bytes, BytesMut};
4
5#[derive(Default, Debug, Clone, PartialEq)]
6pub(crate) struct ParamHeartbeatInfo {
7    pub(crate) heartbeat_information: Bytes,
8}
9
10impl fmt::Display for ParamHeartbeatInfo {
11    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
12        write!(f, "{} {:?}", self.header(), self.heartbeat_information)
13    }
14}
15
16impl Param for ParamHeartbeatInfo {
17    fn header(&self) -> ParamHeader {
18        ParamHeader {
19            typ: ParamType::HeartbeatInfo,
20            value_length: self.value_length() as u16,
21        }
22    }
23
24    fn unmarshal(raw: &Bytes) -> Result<Self> {
25        let header = ParamHeader::unmarshal(raw)?;
26        let heartbeat_information =
27            raw.slice(PARAM_HEADER_LENGTH..PARAM_HEADER_LENGTH + header.value_length());
28        Ok(ParamHeartbeatInfo {
29            heartbeat_information,
30        })
31    }
32
33    fn marshal_to(&self, buf: &mut BytesMut) -> Result<usize> {
34        self.header().marshal_to(buf)?;
35        buf.extend(self.heartbeat_information.clone());
36        Ok(buf.len())
37    }
38
39    fn value_length(&self) -> usize {
40        self.heartbeat_information.len()
41    }
42
43    fn clone_to(&self) -> Box<dyn Param + Send + Sync> {
44        Box::new(self.clone())
45    }
46
47    fn as_any(&self) -> &(dyn Any + Send + Sync) {
48        self
49    }
50}