xmpp_parsers/
jingle_rtp_hdrext.rs1use xso::{AsXml, FromXml};
8
9use crate::ns;
10
11generate_attribute!(
12 Senders, "senders", {
14 Both => "both",
16
17 Initiator => "initiator",
19
20 Responder => "responder",
22 }, Default = Both
23);
24
25#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
27#[xml(namespace = ns::JINGLE_RTP_HDREXT, name = "rtp-hdrext")]
28pub struct RtpHdrext {
29 #[xml(attribute)]
33 pub id: u16,
34
35 #[xml(attribute)]
37 pub uri: String,
38
39 #[xml(attribute(default))]
41 pub senders: Senders,
42}
43
44impl RtpHdrext {
45 pub fn new(id: u16, uri: String) -> RtpHdrext {
47 RtpHdrext {
48 id,
49 uri,
50 senders: Default::default(),
51 }
52 }
53
54 pub fn with_senders(mut self, senders: Senders) -> RtpHdrext {
56 self.senders = senders;
57 self
58 }
59}
60
61#[cfg(test)]
62mod tests {
63 use super::*;
64 use minidom::Element;
65
66 #[cfg(target_pointer_width = "32")]
67 #[test]
68 fn test_size() {
69 assert_size!(Senders, 1);
70 assert_size!(RtpHdrext, 16);
71 }
72
73 #[cfg(target_pointer_width = "64")]
74 #[test]
75 fn test_size() {
76 assert_size!(Senders, 1);
77 assert_size!(RtpHdrext, 32);
78 }
79
80 #[test]
81 fn parse_exthdr() {
82 let elem: Element = "<rtp-hdrext xmlns='urn:xmpp:jingle:apps:rtp:rtp-hdrext:0'
83 uri='urn:ietf:params:rtp-hdrext:toffset'
84 id='1'/>"
85 .parse()
86 .unwrap();
87 let rtp_hdrext = RtpHdrext::try_from(elem).unwrap();
88 assert_eq!(rtp_hdrext.id, 1);
89 assert_eq!(rtp_hdrext.uri, "urn:ietf:params:rtp-hdrext:toffset");
90 assert_eq!(rtp_hdrext.senders, Senders::Both);
91 }
92}