webrtc_dtls/
application_data.rs1use std::io::{Read, Write};
2
3use super::content::*;
4use crate::error::Result;
5
6#[derive(Clone, PartialEq, Eq, Debug)]
16pub struct ApplicationData {
17 pub data: Vec<u8>,
18}
19
20impl ApplicationData {
21 pub fn content_type(&self) -> ContentType {
22 ContentType::ApplicationData
23 }
24
25 pub fn size(&self) -> usize {
26 self.data.len()
27 }
28
29 pub fn marshal<W: Write>(&self, writer: &mut W) -> Result<()> {
30 writer.write_all(&self.data)?;
31
32 Ok(writer.flush()?)
33 }
34
35 pub fn unmarshal<R: Read>(reader: &mut R) -> Result<Self> {
36 let mut data: Vec<u8> = vec![];
37 reader.read_to_end(&mut data)?;
38
39 Ok(ApplicationData { data })
40 }
41}