webrtc_sctp/param/
param_unknown.rs1use std::any::Any;
2use std::fmt::{Debug, Display, Formatter};
3
4use bytes::{Bytes, BytesMut};
5
6use crate::param::param_header::{ParamHeader, PARAM_HEADER_LENGTH};
7use crate::param::param_type::ParamType;
8use crate::param::Param;
9
10#[derive(Clone, Debug, PartialEq, Eq)]
15pub struct ParamUnknown {
16 typ: u16,
17 value: Bytes,
18}
19
20impl Display for ParamUnknown {
21 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
22 write!(f, "ParamUnknown( {} {:?} )", self.header(), self.value)
23 }
24}
25
26impl Param for ParamUnknown {
27 fn header(&self) -> ParamHeader {
28 ParamHeader {
29 typ: ParamType::Unknown {
30 param_type: self.typ,
31 },
32 value_length: self.value.len() as u16,
33 }
34 }
35
36 fn as_any(&self) -> &(dyn Any + Send + Sync) {
37 self
38 }
39
40 fn unmarshal(raw: &Bytes) -> crate::error::Result<Self>
41 where
42 Self: Sized,
43 {
44 let header = ParamHeader::unmarshal(raw)?;
45 let value = raw.slice(PARAM_HEADER_LENGTH..PARAM_HEADER_LENGTH + header.value_length());
46 Ok(Self {
47 typ: header.typ.into(),
48 value,
49 })
50 }
51
52 fn marshal_to(&self, buf: &mut BytesMut) -> crate::error::Result<usize> {
53 self.header().marshal_to(buf)?;
54 buf.extend(self.value.clone());
55 Ok(buf.len())
56 }
57
58 fn value_length(&self) -> usize {
59 self.value.len()
60 }
61
62 fn clone_to(&self) -> Box<dyn Param + Send + Sync> {
63 Box::new(self.clone())
64 }
65}