xref: /webrtc/dtls/src/application_data.rs (revision ffe74184)
1 use std::io::{Read, Write};
2 
3 use super::content::*;
4 use crate::error::Result;
5 
6 // Application data messages are carried by the record layer and are
7 // fragmented, compressed, and encrypted based on the current connection
8 // state.  The messages are treated as transparent data to the record
9 // layer.
10 // https://tools.ietf.org/html/rfc5246#section-10
11 #[derive(Clone, PartialEq, Eq, Debug)]
12 pub struct ApplicationData {
13     pub data: Vec<u8>,
14 }
15 
16 impl ApplicationData {
content_type(&self) -> ContentType17     pub fn content_type(&self) -> ContentType {
18         ContentType::ApplicationData
19     }
20 
size(&self) -> usize21     pub fn size(&self) -> usize {
22         self.data.len()
23     }
24 
marshal<W: Write>(&self, writer: &mut W) -> Result<()>25     pub fn marshal<W: Write>(&self, writer: &mut W) -> Result<()> {
26         writer.write_all(&self.data)?;
27 
28         Ok(writer.flush()?)
29     }
30 
unmarshal<R: Read>(reader: &mut R) -> Result<Self>31     pub fn unmarshal<R: Read>(reader: &mut R) -> Result<Self> {
32         let mut data: Vec<u8> = vec![];
33         reader.read_to_end(&mut data)?;
34 
35         Ok(ApplicationData { data })
36     }
37 }
38