diff --git a/minidom/Cargo.toml b/minidom/Cargo.toml index dd24a9e..100bfb3 100644 --- a/minidom/Cargo.toml +++ b/minidom/Cargo.toml @@ -22,4 +22,4 @@ gitlab = { repository = "xmpp-rs/xmpp-rs" } [dependencies] quick-xml = "0.22.0" -rxml = { git = "https://github.com/horazont/rxml.git" } +rxml = { git = "https://github.com/horazont/rxml.git", branch = "feature/push-buf" } diff --git a/tokio-xmpp/Cargo.toml b/tokio-xmpp/Cargo.toml index 5ffa826..bd10bd6 100644 --- a/tokio-xmpp/Cargo.toml +++ b/tokio-xmpp/Cargo.toml @@ -27,7 +27,7 @@ trust-dns-proto = "0.20" trust-dns-resolver = "0.20" xmpp-parsers = "0.19" minidom = "0.14" -rxml = { git = "https://github.com/horazont/rxml.git" } +rxml = { git = "https://github.com/horazont/rxml.git", branch = "feature/push-buf" } webpki-roots = { version = "0.22", optional = true } [build-dependencies] diff --git a/tokio-xmpp/src/xmpp_codec.rs b/tokio-xmpp/src/xmpp_codec.rs index 5b65f42..2d37eec 100644 --- a/tokio-xmpp/src/xmpp_codec.rs +++ b/tokio-xmpp/src/xmpp_codec.rs @@ -10,7 +10,7 @@ use std::io; use tokio_util::codec::{Decoder, Encoder}; use xmpp_parsers::Element; use minidom::tree_builder::TreeBuilder; -use rxml::{EventRead, Lexer, PushDriver, RawParser}; +use rxml::{Lexer, PushDriver, RawParser}; use crate::Error; /// Anything that can be sent or received on an XMPP/XML stream @@ -31,7 +31,7 @@ pub struct XMPPCodec { /// Outgoing ns: Option, /// Incoming - driver: PushDriver<'static, RawParser>, + driver: PushDriver, stanza_builder: TreeBuilder, } @@ -59,11 +59,7 @@ impl Decoder for XMPPCodec { type Error = Error; fn decode(&mut self, buf: &mut BytesMut) -> Result, Self::Error> { - // TODO: avoid the .to_owned - self.driver.feed(std::borrow::Cow::from(buf.as_ref().to_owned())); - buf.clear(); - - while let Some(token) = self.driver.read().map_err(|e| minidom::Error::from(e))? { + while let Some(token) = self.driver.parse(buf, false).map_err(|e| minidom::Error::from(e))? { let had_stream_root = self.stanza_builder.depth() > 0; self.stanza_builder.process_event(token)?; let has_stream_root = self.stanza_builder.depth() > 0;