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