parsers: add streamable parsing

This adds shims which provide FromXml and IntoXml implementations to
*all* macro-generated types in `xmpp_parsers`. Mind that this does not
cover all types in `xmpp_parsers`, but a good share of them.

This is another first step toward real, fully streamed parsing.
This commit is contained in:
Jonas Schäfer 2024-06-16 10:14:18 +02:00
commit cb3da52ba2
7 changed files with 131 additions and 0 deletions

View file

@ -131,3 +131,18 @@ impl From<chrono::ParseError> for Error {
Error::ChronoParseError(err)
}
}
impl From<Error> for xso::error::Error {
fn from(other: Error) -> Self {
match other {
Error::ParseError(e) => Self::Other(e.to_string().into()),
Error::TypeMismatch { .. } => Self::TypeMismatch,
Error::Base64Error(e) => Self::TextParseError(Box::new(e)),
Error::ParseIntError(e) => Self::TextParseError(Box::new(e)),
Error::ParseStringError(e) => Self::TextParseError(Box::new(e)),
Error::ParseAddrError(e) => Self::TextParseError(Box::new(e)),
Error::JidParseError(e) => Self::TextParseError(Box::new(e)),
Error::ChronoParseError(e) => Self::TextParseError(Box::new(e)),
}
}
}

View file

@ -676,6 +676,23 @@ macro_rules! generate_element {
)*
}
impl ::xso::FromXml for $elem {
type Builder = ::xso::minidom_compat::FromEventsViaElement<$elem>;
fn from_events(
qname: ::xso::exports::rxml::QName,
attrs: ::xso::exports::rxml::AttrMap,
) -> Result<Self::Builder, ::xso::error::FromEventsError> {
if qname.0 != crate::ns::$ns || qname.1 != $name {
return Err(::xso::error::FromEventsError::Mismatch {
name: qname,
attrs,
})
}
Self::Builder::new(qname, attrs)
}
}
impl ::std::convert::TryFrom<crate::Element> for $elem {
type Error = crate::util::error::Error;
@ -748,6 +765,14 @@ macro_rules! generate_element {
builder.build()
}
}
impl ::xso::IntoXml for $elem {
type EventIter = ::xso::minidom_compat::IntoEventsViaElement;
fn into_event_iter(self) -> Result<Self::EventIter, ::xso::error::Error> {
Self::EventIter::new(self)
}
}
);
}