xmpp_parsers/
jingle_grouping.rs1use xso::{AsXml, FromXml};
8
9use crate::jingle::ContentId;
10use crate::ns;
11
12generate_attribute!(
13 Semantics, "semantics", {
15 Ls => "LS",
17
18 Bundle => "BUNDLE",
20 }
21);
22
23#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
25#[xml(namespace = ns::JINGLE_GROUPING, name = "content")]
26pub struct Content {
27 #[xml(attribute)]
29 pub name: ContentId,
30}
31
32impl Content {
33 pub fn new(name: &str) -> Content {
35 Content {
36 name: ContentId(name.to_string()),
37 }
38 }
39}
40
41#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
43#[xml(namespace = ns::JINGLE_GROUPING, name = "group")]
44pub struct Group {
45 #[xml(attribute)]
47 pub semantics: Semantics,
48
49 #[xml(child(n = ..))]
51 pub contents: Vec<Content>,
52}
53
54#[cfg(test)]
55mod tests {
56 use super::*;
57 use minidom::Element;
58
59 #[cfg(target_pointer_width = "32")]
60 #[test]
61 fn test_size() {
62 assert_size!(Semantics, 1);
63 assert_size!(Content, 12);
64 assert_size!(Group, 16);
65 }
66
67 #[cfg(target_pointer_width = "64")]
68 #[test]
69 fn test_size() {
70 assert_size!(Semantics, 1);
71 assert_size!(Content, 24);
72 assert_size!(Group, 32);
73 }
74
75 #[test]
76 fn parse_group() {
77 let elem: Element = "<group xmlns='urn:xmpp:jingle:apps:grouping:0' semantics='BUNDLE'>
78 <content name='voice'/>
79 <content name='webcam'/>
80 </group>"
81 .parse()
82 .unwrap();
83 let group = Group::try_from(elem).unwrap();
84 assert_eq!(group.semantics, Semantics::Bundle);
85 assert_eq!(group.contents.len(), 2);
86 assert_eq!(
87 group.contents,
88 &[Content::new("voice"), Content::new("webcam")]
89 );
90 }
91}