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