Shrink EbmlSlice trait implementations
This commit is contained in:
parent
2db227c5f9
commit
ee068bc887
1 changed files with 19 additions and 44 deletions
|
@ -10,30 +10,15 @@ impl<'a> Iterator for EbmlSlice<'a> {
|
||||||
type Item = WebmElement<'a>;
|
type Item = WebmElement<'a>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<WebmElement<'a>> {
|
fn next(&mut self) -> Option<WebmElement<'a>> {
|
||||||
match WebmElement::check_space(self.0) {
|
WebmElement::check_space(self.0).unwrap_or(None).and_then(|element_size| {
|
||||||
Err(err) => {
|
let (element_data, rest) = self.0.split_at(element_size);
|
||||||
None
|
self.0 = rest;
|
||||||
},
|
match WebmElement::decode_element(element_data) {
|
||||||
Ok(None) => {
|
Err(_) => None,
|
||||||
None
|
Ok(None) => panic!("Buffer was supposed to have enough data to parse element, somehow did not."),
|
||||||
},
|
Ok(Some((element, _))) => Some(element)
|
||||||
Ok(Some(element_size)) => {
|
|
||||||
let (element_data, rest) = self.0.split_at(element_size);
|
|
||||||
self.0 = rest;
|
|
||||||
match WebmElement::decode_element(element_data) {
|
|
||||||
Err(err) => {
|
|
||||||
None
|
|
||||||
},
|
|
||||||
Ok(None) => {
|
|
||||||
// buffer should have enough data
|
|
||||||
panic!("Buffer was supposed to have enough data to parse element, somehow did not.")
|
|
||||||
},
|
|
||||||
Ok(Some((element, _))) => {
|
|
||||||
Some(element)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,29 +26,19 @@ impl<'b> EbmlEventSource for EbmlSlice<'b> {
|
||||||
type Error = EbmlError;
|
type Error = EbmlError;
|
||||||
|
|
||||||
fn poll_event<'a, T: FromEbml<'a>>(&'a mut self) -> Result<Async<Option<T>>, EbmlError> {
|
fn poll_event<'a, T: FromEbml<'a>>(&'a mut self) -> Result<Async<Option<T>>, EbmlError> {
|
||||||
match T::check_space(self.0) {
|
T::check_space(self.0).and_then(|size_option| {
|
||||||
Err(err) => {
|
match size_option {
|
||||||
Err(err)
|
None => Ok(None),
|
||||||
},
|
Some(element_size) => {
|
||||||
Ok(None) => {
|
let (element_data, rest) = self.0.split_at(element_size);
|
||||||
Ok(None)
|
self.0 = rest;
|
||||||
},
|
match T::decode_element(element_data) {
|
||||||
Ok(Some(element_size)) => {
|
Err(err) => Err(err),
|
||||||
let (element_data, rest) = self.0.split_at(element_size);
|
Ok(None) => panic!("Buffer was supposed to have enough data to parse element, somehow did not."),
|
||||||
self.0 = rest;
|
Ok(Some((element, _))) => Ok(Some(element))
|
||||||
match T::decode_element(element_data) {
|
|
||||||
Err(err) => {
|
|
||||||
Err(err)
|
|
||||||
},
|
|
||||||
Ok(None) => {
|
|
||||||
// buffer should have enough data
|
|
||||||
panic!("Buffer was supposed to have enough data to parse element, somehow did not.")
|
|
||||||
},
|
|
||||||
Ok(Some((element, _))) => {
|
|
||||||
Ok(Some(element))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.map(Async::Ready)
|
}).map(Async::Ready)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue