2024-03-04 16:14:28 +00:00
|
|
|
use futures::Stream;
|
2024-06-27 20:22:16 +01:00
|
|
|
use nom::Err;
|
2024-06-29 17:06:08 +01:00
|
|
|
use std::{collections::BTreeMap, str};
|
2024-06-27 20:22:16 +01:00
|
|
|
use tokio::io::AsyncBufReadExt;
|
2024-03-04 16:14:28 +00:00
|
|
|
|
|
|
|
use crate::{
|
|
|
|
element::{Element, Name, Namespace},
|
|
|
|
error::Error,
|
|
|
|
};
|
|
|
|
|
|
|
|
/// streaming reader that tracks depth and available namespaces at current depth
|
|
|
|
pub struct Reader<R> {
|
2024-06-27 20:22:16 +01:00
|
|
|
inner: R,
|
2024-03-04 16:14:28 +00:00
|
|
|
// holds which tags we are in atm over depth
|
|
|
|
depth: Vec<Name>,
|
|
|
|
namespaces: Vec<(usize, Namespace)>,
|
|
|
|
}
|
|
|
|
|
2024-06-27 20:22:16 +01:00
|
|
|
impl<R> Reader<R> {
|
|
|
|
pub fn new(reader: R) -> Self {
|
|
|
|
Self {
|
|
|
|
inner: reader,
|
|
|
|
depth: Vec::new(),
|
|
|
|
namespaces: Vec::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-31 20:54:19 +00:00
|
|
|
// impl<R> Reader<R>
|
|
|
|
// where
|
|
|
|
// R: AsyncBufReadExt + Unpin,
|
|
|
|
// {
|
|
|
|
// /// could resursively read and include namespace tree with values to be shadowed within new local context
|
|
|
|
// async fn read_recursive(&mut self, namespaces: BTreeMap<Option<String>, String>) -> Result<Element, Error> {
|
|
|
|
// let element;
|
|
|
|
// let len;
|
|
|
|
// loop {
|
|
|
|
// let buf = self.inner.fill_buf().await?;
|
|
|
|
// let input = str::from_utf8(buf)?;
|
|
|
|
// match crate::xml::element(input) {
|
|
|
|
// Ok((rest, e)) => {
|
|
|
|
// element = e;
|
|
|
|
// len = buf.len() - rest.len();
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// Err(e) => match e {
|
|
|
|
// Err::Incomplete(_) => (),
|
|
|
|
// e => return Err::<E, Error>(Error::ParseError(input.to_owned())),
|
|
|
|
// },
|
|
|
|
// }
|
|
|
|
// }
|
2024-06-27 20:22:16 +01:00
|
|
|
|
2024-10-31 20:54:19 +00:00
|
|
|
// let final;
|
|
|
|
// match element {
|
|
|
|
// crate::xml::Element::Empty(e) => {
|
|
|
|
// let final = Element {
|
2024-06-29 17:06:08 +01:00
|
|
|
|
2024-10-31 20:54:19 +00:00
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// crate::xml::Element::NotEmpty(_, _, _) => todo!(),
|
|
|
|
// }
|
2024-06-29 17:06:08 +01:00
|
|
|
|
2024-10-31 20:54:19 +00:00
|
|
|
// self.inner.consume(len);
|
|
|
|
// todo!()
|
|
|
|
// }
|
|
|
|
// /// reads entire next prolog, element, or misc
|
|
|
|
// pub async fn read<E: From<Element>>(&mut self) -> Result<E, Error> {
|
|
|
|
// let element;
|
|
|
|
// let len;
|
|
|
|
// loop {
|
|
|
|
// let buf = self.inner.fill_buf().await?;
|
|
|
|
// let input = str::from_utf8(buf)?;
|
|
|
|
// match crate::xml::element(input) {
|
|
|
|
// Ok((rest, e)) => {
|
|
|
|
// element = e;
|
|
|
|
// len = buf.len() - rest.len();
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// Err(e) => match e {
|
|
|
|
// Err::Incomplete(_) => (),
|
|
|
|
// e => return Err::<E, Error>(Error::ParseError(input.to_owned())),
|
|
|
|
// },
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// self.inner.consume(len);
|
|
|
|
|
|
|
|
// // Ok(element)
|
|
|
|
// todo!()
|
|
|
|
// }
|
|
|
|
// pub async fn read_start(&self) -> Result<impl From<Element>, Error> {
|
|
|
|
// todo!()
|
|
|
|
// }
|
|
|
|
// pub async fn read_end(&self) -> Result<(), Error> {
|
|
|
|
// todo!()
|
|
|
|
// }
|
|
|
|
// }
|
2024-03-04 16:14:28 +00:00
|
|
|
|
2024-06-14 13:11:32 +01:00
|
|
|
// impl<R: AsyncBufRead> Stream for Reader<R> {
|
|
|
|
// type Item = impl From<Element>;
|
2024-03-04 16:14:28 +00:00
|
|
|
|
2024-06-14 13:11:32 +01:00
|
|
|
// async fn poll_next(
|
|
|
|
// self: std::pin::Pin<&mut Self>,
|
|
|
|
// cx: &mut std::task::Context<'_>,
|
|
|
|
// ) -> std::task::Poll<Option<Self::Item>> {
|
|
|
|
// todo!()
|
|
|
|
// }
|
|
|
|
// }
|