webrtc_turn/proto/
data.rs

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