From 30a596cb262faab13f42126b9581184ce91d1b52 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 27 Apr 2017 19:05:51 +0100 Subject: [PATCH] ibb: Implement serialise. --- src/ibb.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/ibb.rs b/src/ibb.rs index ba8fcafb..6281d140 100644 --- a/src/ibb.rs +++ b/src/ibb.rs @@ -105,6 +105,33 @@ pub fn parse_ibb(root: &Element) -> Result { } } +pub fn serialise(ibb: &IBB) -> Element { + match *ibb { + IBB::Open { ref block_size, ref sid, ref stanza } => { + Element::builder("open") + .ns(ns::IBB) + .attr("block-size", format!("{}", block_size)) + .attr("sid", sid.to_owned()) + .attr("stanza", stanza.to_owned()) + .build() + }, + IBB::Data { ref seq, ref sid, ref data } => { + Element::builder("data") + .ns(ns::IBB) + .attr("seq", format!("{}", seq)) + .attr("sid", sid.to_owned()) + .attr("data", base64::encode(&data)) + .build() + }, + IBB::Close { ref sid } => { + Element::builder("close") + .ns(ns::IBB) + .attr("sid", sid.to_owned()) + .build() + }, + } +} + #[cfg(test)] mod tests { use minidom::Element;