sctp_async/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;
20
21use crate::error::{Error, Result};
22use chunk_header::*;
23
24use bytes::{Bytes, BytesMut};
25use std::marker::Sized;
26use std::{any::Any, fmt};
27
28pub(crate) trait Chunk: fmt::Display + fmt::Debug {
29    fn header(&self) -> ChunkHeader;
30    fn unmarshal(raw: &Bytes) -> Result<Self>
31    where
32        Self: Sized;
33    fn marshal_to(&self, buf: &mut BytesMut) -> Result<usize>;
34    fn check(&self) -> Result<()>;
35    fn value_length(&self) -> usize;
36    fn as_any(&self) -> &(dyn Any + Send + Sync);
37
38    fn marshal(&self) -> Result<Bytes> {
39        let capacity = CHUNK_HEADER_SIZE + self.value_length();
40        let mut buf = BytesMut::with_capacity(capacity);
41        self.marshal_to(&mut buf)?;
42        Ok(buf.freeze())
43    }
44}