forked from lavina/lavina
1
0
Fork 0
lavina/crates/proto-xmpp/src/session.rs

41 lines
1.2 KiB
Rust

use quick_xml::events::{BytesStart, Event};
use crate::xml::*;
use anyhow::{anyhow, Result};
use quick_xml::name::ResolveResult;
pub const XMLNS: &'static str = "urn:ietf:params:xml:ns:xmpp-session";
#[derive(PartialEq, Eq, Debug)]
pub struct Session;
impl FromXml for Session {
type P = impl Parser<Output = Result<Self>>;
fn parse() -> Self::P {
|(mut namespace, mut event): (ResolveResult<'static>, &'static Event<'static>)| -> Result<Self> {
match event {
Event::Start(_) => (),
Event::Empty(_) => return Ok(Session),
_ => return Err(anyhow!("Unexpected XML event: {event:?}")),
}
(namespace, event) = yield;
match event {
Event::End(_) => return Ok(Session),
_ => return Err(anyhow!("Unexpected XML event: {event:?}")),
}
}
}
}
impl FromXmlTag for Session {
const NAME: &'static str = "session";
const NS: &'static str = XMLNS;
}
impl ToXml for Session {
fn serialize(&self, events: &mut Vec<Event<'static>>) {
events.push(Event::Empty(BytesStart::new(format!(r#"session xmlns="{}""#, XMLNS))));
}
}