From db1a87e2eec9812a6f69389b1b37c128eb79b251 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 24 Apr 2017 19:25:00 +0100 Subject: [PATCH] jingle: Implement serialise. --- src/jingle.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/jingle.rs b/src/jingle.rs index c8a2dfc..9e2549c 100644 --- a/src/jingle.rs +++ b/src/jingle.rs @@ -347,6 +347,38 @@ pub fn parse_jingle(root: &Element) -> Result { }) } +pub fn serialise_content(content: &Content) -> Element { + let mut root = Element::builder("content") + .ns(ns::JINGLE) + .attr("creator", String::from(content.creator.clone())) + .attr("disposition", content.disposition.clone()) + .attr("name", content.name.clone()) + .attr("senders", String::from(content.senders.clone())) + .build(); + root.append_child(content.description.1.clone()); + root.append_child(content.transport.1.clone()); + if let Some(security) = content.security.clone() { + root.append_child(security.1.clone()); + } + root +} + +pub fn serialise(jingle: &Jingle) -> Element { + let mut root = Element::builder("jingle") + .ns(ns::JINGLE) + .attr("action", String::from(jingle.action.clone())) + .attr("initiator", jingle.initiator.clone()) + .attr("responder", jingle.responder.clone()) + .attr("sid", jingle.sid.clone()) + .build(); + for content in jingle.contents.clone() { + println!("{:?}", content); + let content_elem = serialise_content(&content); + root.append_child(content_elem); + } + root +} + #[cfg(test)] mod tests { use minidom::Element;