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