webrtc_sctp/param/
param_random.rs1use bytes::{Bytes, BytesMut};
2
3use super::param_header::*;
4use super::param_type::*;
5use super::*;
6
7#[derive(Default, Debug, Clone, PartialEq)]
8pub(crate) struct ParamRandom {
9 pub(crate) random_data: Bytes,
10}
11
12impl fmt::Display for ParamRandom {
13 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14 write!(f, "{} {:?}", self.header(), self.random_data)
15 }
16}
17
18impl Param for ParamRandom {
19 fn header(&self) -> ParamHeader {
20 ParamHeader {
21 typ: ParamType::Random,
22 value_length: self.value_length() as u16,
23 }
24 }
25
26 fn unmarshal(raw: &Bytes) -> Result<Self> {
27 let header = ParamHeader::unmarshal(raw)?;
28 let random_data =
29 raw.slice(PARAM_HEADER_LENGTH..PARAM_HEADER_LENGTH + header.value_length());
30 Ok(ParamRandom { random_data })
31 }
32
33 fn marshal_to(&self, buf: &mut BytesMut) -> Result<usize> {
34 self.header().marshal_to(buf)?;
35 buf.extend(self.random_data.clone());
36 Ok(buf.len())
37 }
38
39 fn value_length(&self) -> usize {
40 self.random_data.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}