webrtc_sctp/chunk/
mod.rs

1#[cfg(test)]
2mod chunk_test;
3
4pub(crate) mod chunk_abort;
5pub(crate) mod chunk_cookie_ack;
6pub(crate) mod chunk_cookie_echo;
7pub(crate) mod chunk_error;
8pub(crate) mod chunk_forward_tsn;
9pub(crate) mod chunk_header;
10pub(crate) mod chunk_heartbeat;
11pub(crate) mod chunk_heartbeat_ack;
12pub(crate) mod chunk_init;
13pub mod chunk_payload_data;
14pub(crate) mod chunk_reconfig;
15pub(crate) mod chunk_selective_ack;
16pub(crate) mod chunk_shutdown;
17pub(crate) mod chunk_shutdown_ack;
18pub(crate) mod chunk_shutdown_complete;
19pub(crate) mod chunk_type;
20pub(crate) mod chunk_unknown;
21
22use std::any::Any;
23use std::fmt;
24use std::marker::Sized;
25
26use bytes::{Bytes, BytesMut};
27use chunk_header::*;
28
29use crate::error::{Error, Result};
30
31pub(crate) trait Chunk: fmt::Display + fmt::Debug {
32    fn header(&self) -> ChunkHeader;
33    fn unmarshal(raw: &Bytes) -> Result<Self>
34    where
35        Self: Sized;
36    fn marshal_to(&self, buf: &mut BytesMut) -> Result<usize>;
37    fn check(&self) -> Result<()>;
38    fn value_length(&self) -> usize;
39    fn as_any(&self) -> &(dyn Any + Send + Sync);
40
41    fn marshal(&self) -> Result<Bytes> {
42        let capacity = CHUNK_HEADER_SIZE + self.value_length();
43        let mut buf = BytesMut::with_capacity(capacity);
44        self.marshal_to(&mut buf)?;
45        Ok(buf.freeze())
46    }
47}