ibb: Implement serialise.
This commit is contained in:
parent
6a48a6bf00
commit
30a596cb26
1 changed files with 27 additions and 0 deletions
27
src/ibb.rs
27
src/ibb.rs
|
@ -105,6 +105,33 @@ pub fn parse_ibb(root: &Element) -> Result<IBB, Error> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use minidom::Element;
|
use minidom::Element;
|
||||||
|
|
Loading…
Reference in a new issue