ping, iq: Implement ping::serialise_ping and link to Iq.

This commit is contained in:
Maxime “pep” Buquet 2017-04-23 21:17:26 +01:00
parent b259ab9ef2
commit c462d230f1
2 changed files with 9 additions and 0 deletions

View file

@ -8,11 +8,13 @@ use error::Error;
use ns;
use disco;
use ping;
/// Lists every known payload of a `<iq/>`.
#[derive(Debug, Clone)]
pub enum IqPayload {
Disco(disco::Disco),
Ping(ping::Ping),
}
#[derive(Debug, Clone)]
@ -77,6 +79,8 @@ pub fn parse_iq(root: &Element) -> Result<Iq, Error> {
} else {
let parsed_payload = if let Ok(disco) = disco::parse_disco(elem) {
Some(IqPayload::Disco(disco))
} else if let Ok(ping) = ping::parse_ping(elem) {
Some(IqPayload::Ping(ping))
} else {
None
};
@ -127,6 +131,7 @@ pub fn parse_iq(root: &Element) -> Result<Iq, Error> {
pub fn serialise_payload(payload: &IqPayload) -> Element {
match *payload {
IqPayload::Disco(ref disco) => disco::serialise_disco(disco),
IqPayload::Ping(_) => ping::serialise_ping(),
}
}

View file

@ -18,6 +18,10 @@ pub fn parse_ping(root: &Element) -> Result<Ping, Error> {
Ok(Ping { })
}
pub fn serialise_ping() -> Element {
Element::builder("ping").ns(ns::PING).build()
}
#[cfg(test)]
mod tests {
use minidom::Element;