xref: /webrtc/sctp/src/chunk/chunk_cookie_ack.rs (revision ffe74184)
1 use super::{chunk_header::*, chunk_type::*, *};
2 
3 use bytes::{Bytes, BytesMut};
4 use std::fmt;
5 
6 /// chunkCookieAck represents an SCTP Chunk of type chunkCookieAck
7 ///
8 ///  0                   1                   2                   3
9 ///  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
10 /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
11 /// |   Type = 11   |Chunk  Flags   |     Length = 4                |
12 /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
13 #[derive(Debug, Clone)]
14 pub(crate) struct ChunkCookieAck;
15 
16 /// makes ChunkCookieAck printable
17 impl fmt::Display for ChunkCookieAck {
fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result18     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19         write!(f, "{}", self.header())
20     }
21 }
22 
23 impl Chunk for ChunkCookieAck {
header(&self) -> ChunkHeader24     fn header(&self) -> ChunkHeader {
25         ChunkHeader {
26             typ: CT_COOKIE_ACK,
27             flags: 0,
28             value_length: self.value_length() as u16,
29         }
30     }
31 
unmarshal(raw: &Bytes) -> Result<Self>32     fn unmarshal(raw: &Bytes) -> Result<Self> {
33         let header = ChunkHeader::unmarshal(raw)?;
34 
35         if header.typ != CT_COOKIE_ACK {
36             return Err(Error::ErrChunkTypeNotCookieAck);
37         }
38 
39         Ok(ChunkCookieAck {})
40     }
41 
marshal_to(&self, buf: &mut BytesMut) -> Result<usize>42     fn marshal_to(&self, buf: &mut BytesMut) -> Result<usize> {
43         self.header().marshal_to(buf)?;
44         Ok(buf.len())
45     }
46 
check(&self) -> Result<()>47     fn check(&self) -> Result<()> {
48         Ok(())
49     }
50 
value_length(&self) -> usize51     fn value_length(&self) -> usize {
52         0
53     }
54 
as_any(&self) -> &(dyn Any + Send + Sync)55     fn as_any(&self) -> &(dyn Any + Send + Sync) {
56         self
57     }
58 }
59