1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
use futures::Stream;
use nom::Err;
use std::{collections::BTreeMap, str};
use tokio::io::AsyncBufReadExt;
use crate::{
element::{Element, Name, Namespace},
error::Error,
};
/// streaming reader that tracks depth and available namespaces at current depth
pub struct Reader<R> {
inner: R,
// holds which tags we are in atm over depth
depth: Vec<Name>,
namespaces: Vec<(usize, Namespace)>,
}
impl<R> Reader<R> {
pub fn new(reader: R) -> Self {
Self {
inner: reader,
depth: Vec::new(),
namespaces: Vec::new(),
}
}
}
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())),
},
}
}
let final;
match element {
crate::xml::Element::Empty(e) => {
let final = Element {
}
},
crate::xml::Element::NotEmpty(_, _, _) => todo!(),
}
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!()
// }
}
// impl<R: AsyncBufRead> Stream for Reader<R> {
// type Item = impl From<Element>;
// async fn poll_next(
// self: std::pin::Pin<&mut Self>,
// cx: &mut std::task::Context<'_>,
// ) -> std::task::Poll<Option<Self::Item>> {
// todo!()
// }
// }
|