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>;
|
||||
|
||||
fn next(&mut self) -> Option<WebmElement<'a>> {
|
||||
match WebmElement::check_space(self.0) {
|
||||
Err(err) => {
|
||||
None
|
||||
},
|
||||
Ok(None) => {
|
||||
None
|
||||
},
|
||||
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)
|
||||
}
|
||||
}
|
||||
WebmElement::check_space(self.0).unwrap_or(None).and_then(|element_size| {
|
||||
let (element_data, rest) = self.0.split_at(element_size);
|
||||
self.0 = rest;
|
||||
match WebmElement::decode_element(element_data) {
|
||||
Err(_) => None,
|
||||
Ok(None) => 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;
|
||||
|
||||
fn poll_event<'a, T: FromEbml<'a>>(&'a mut self) -> Result<Async<Option<T>>, EbmlError> {
|
||||
match T::check_space(self.0) {
|
||||
Err(err) => {
|
||||
Err(err)
|
||||
},
|
||||
Ok(None) => {
|
||||
Ok(None)
|
||||
},
|
||||
Ok(Some(element_size)) => {
|
||||
let (element_data, rest) = self.0.split_at(element_size);
|
||||
self.0 = rest;
|
||||
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))
|
||||
T::check_space(self.0).and_then(|size_option| {
|
||||
match size_option {
|
||||
None => Ok(None),
|
||||
Some(element_size) => {
|
||||
let (element_data, rest) = self.0.split_at(element_size);
|
||||
self.0 = rest;
|
||||
match T::decode_element(element_data) {
|
||||
Err(err) => Err(err),
|
||||
Ok(None) => 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