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