Remove usage page stack
Apparently the whole stack thing only applies to Push/Pop items.
This commit is contained in:
@ -249,13 +249,11 @@ impl Collection {
|
|||||||
pub enum ParseError {
|
pub enum ParseError {
|
||||||
Truncated,
|
Truncated,
|
||||||
UnexpectedData,
|
UnexpectedData,
|
||||||
StackOverflow,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Parser<'a> {
|
pub struct Parser<'a> {
|
||||||
data: &'a [u8],
|
data: &'a [u8],
|
||||||
usage_page: [u16; 16],
|
usage_page: u16,
|
||||||
stack_index: usize,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Iterator for Parser<'a> {
|
impl<'a> Iterator for Parser<'a> {
|
||||||
@ -263,23 +261,10 @@ impl<'a> Iterator for Parser<'a> {
|
|||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
(!self.data.is_empty()).then(|| {
|
(!self.data.is_empty()).then(|| {
|
||||||
use ParseError::*;
|
|
||||||
let e;
|
let e;
|
||||||
let page = self
|
(e, self.data) = Item::parse(self.data, self.usage_page)?;
|
||||||
.usage_page
|
|
||||||
.get_mut(self.stack_index)
|
|
||||||
.ok_or(StackOverflow)?;
|
|
||||||
// TODO update usage page
|
|
||||||
(e, self.data) = Item::parse(self.data, *page)?;
|
|
||||||
match &e {
|
match &e {
|
||||||
Item::Collection(_) => {
|
Item::UsagePage(p) => self.usage_page = p.as_raw(),
|
||||||
self.stack_index += 1;
|
|
||||||
*self.usage_page.get_mut(self.stack_index).ok_or(StackOverflow)? = *page;
|
|
||||||
}
|
|
||||||
Item::EndCollection => {
|
|
||||||
self.stack_index -= 1;
|
|
||||||
}
|
|
||||||
Item::UsagePage(p) => *page = p.as_raw(),
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
Ok(e)
|
Ok(e)
|
||||||
@ -290,8 +275,7 @@ impl<'a> Iterator for Parser<'a> {
|
|||||||
pub fn parse(data: &[u8]) -> Parser<'_> {
|
pub fn parse(data: &[u8]) -> Parser<'_> {
|
||||||
Parser {
|
Parser {
|
||||||
data,
|
data,
|
||||||
usage_page: [0xffff; 16],
|
usage_page: 0,
|
||||||
stack_index: 0,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user