1 #[cfg(test)] 2 mod data_test; 3 4 use stun::attributes::*; 5 use 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 16 #[derive(Default, Debug, PartialEq, Eq)] 17 pub struct Data(pub Vec<u8>); 18 19 impl Setter for Data { 20 // AddTo adds DATA to message. add_to(&self, m: &mut Message) -> Result<(), stun::Error>21 fn add_to(&self, m: &mut Message) -> Result<(), stun::Error> { 22 m.add(ATTR_DATA, &self.0); 23 Ok(()) 24 } 25 } 26 27 impl Getter for Data { 28 // GetFrom decodes DATA from message. get_from(&mut self, m: &Message) -> Result<(), stun::Error>29 fn get_from(&mut self, m: &Message) -> Result<(), stun::Error> { 30 self.0 = m.get(ATTR_DATA)?; 31 Ok(()) 32 } 33 } 34