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