turn/proto/data.rs
1#[cfg(test)]
2mod data_test;
3
4use stun::attributes::*;
5use stun::message::*;
6
7/// `Data` represents `DATA` attribute.
8///
9/// The `DATA` attribute is present in all Send and Data indications. The
10/// value portion of this attribute is variable length and consists of
11/// the application data (that is, the data that would immediately follow
12/// the UDP header if the data was been sent directly between the client
13/// and the peer).
14///
15/// [RFC 5766 Section 14.4](https://www.rfc-editor.org/rfc/rfc5766#section-14.4).
16#[derive(Default, Debug, PartialEq, Eq)]
17pub struct Data(pub Vec<u8>);
18
19impl Setter for Data {
20 /// Adds `DATA` to message.
21 fn add_to(&self, m: &mut Message) -> Result<(), stun::Error> {
22 m.add(ATTR_DATA, &self.0);
23 Ok(())
24 }
25}
26
27impl Getter for Data {
28 /// Decodes `DATA` from message.
29 fn get_from(&mut self, m: &Message) -> Result<(), stun::Error> {
30 self.0 = m.get(ATTR_DATA)?;
31 Ok(())
32 }
33}