Cleanup, use EbmlSlice as name

This commit is contained in:
Tangent 128 2018-04-03 23:38:31 -04:00
parent 0909a20a8c
commit 2db227c5f9
3 changed files with 12 additions and 27 deletions

View file

@ -214,11 +214,6 @@ pub fn encode_integer<T: Write>(tag: u64, value: u64, output: &mut T) -> IoResul
output.write_all(&buffer.get_ref()[..]) output.write_all(&buffer.get_ref()[..])
} }
#[derive(Debug, PartialEq)]
pub struct Ebml<Source> {
pub source: Source
}
pub trait FromEbml<'a>: Sized { pub trait FromEbml<'a>: Sized {
/// Indicates if this tag's contents should be treated as a blob, /// Indicates if this tag's contents should be treated as a blob,
/// or if the tag header should be reported as an event and with further /// or if the tag header should be reported as an event and with further

View file

@ -4,23 +4,13 @@ use ebml::EbmlEventSource;
use ebml::FromEbml; use ebml::FromEbml;
use webm::WebmElement; use webm::WebmElement;
pub struct EbmlCursor<'a> { pub struct EbmlSlice<'a>(pub &'a [u8]);
source: &'a [u8]
}
impl<'a> EbmlCursor<'a> { impl<'a> Iterator for EbmlSlice<'a> {
pub fn new(source: &'a [u8]) -> Self {
EbmlCursor {
source
}
}
}
impl<'a> Iterator for EbmlCursor<'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.source) { match WebmElement::check_space(self.0) {
Err(err) => { Err(err) => {
None None
}, },
@ -28,8 +18,8 @@ impl<'a> Iterator for EbmlCursor<'a> {
None None
}, },
Ok(Some(element_size)) => { Ok(Some(element_size)) => {
let (element_data, rest) = self.source.split_at(element_size); let (element_data, rest) = self.0.split_at(element_size);
self.source = rest; self.0 = rest;
match WebmElement::decode_element(element_data) { match WebmElement::decode_element(element_data) {
Err(err) => { Err(err) => {
None None
@ -47,11 +37,11 @@ impl<'a> Iterator for EbmlCursor<'a> {
} }
} }
impl<'b> EbmlEventSource for EbmlCursor<'b> { 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.source) { match T::check_space(self.0) {
Err(err) => { Err(err) => {
Err(err) Err(err)
}, },
@ -59,8 +49,8 @@ impl<'b> EbmlEventSource for EbmlCursor<'b> {
Ok(None) Ok(None)
}, },
Ok(Some(element_size)) => { Ok(Some(element_size)) => {
let (element_data, rest) = self.source.split_at(element_size); let (element_data, rest) = self.0.split_at(element_size);
self.source = rest; self.0 = rest;
match T::decode_element(element_data) { match T::decode_element(element_data) {
Err(err) => { Err(err) => {
Err(err) Err(err)

View file

@ -1,7 +1,7 @@
use std::io::{Cursor, Error as IoError, ErrorKind, Result as IoResult, Write, Seek}; use std::io::{Cursor, Error as IoError, ErrorKind, Result as IoResult, Write, Seek};
use bytes::{BigEndian, BufMut, ByteOrder}; use bytes::{BigEndian, BufMut, ByteOrder};
use ebml::*; use ebml::*;
use iterator::EbmlCursor; use iterator::EbmlSlice;
const SEGMENT_ID: u64 = 0x08538067; const SEGMENT_ID: u64 = 0x08538067;
const SEEK_HEAD_ID: u64 = 0x014D9B74; const SEEK_HEAD_ID: u64 = 0x014D9B74;
@ -12,8 +12,8 @@ const CLUSTER_ID: u64 = 0x0F43B675;
const TIMECODE_ID: u64 = 0x67; const TIMECODE_ID: u64 = 0x67;
const SIMPLE_BLOCK_ID: u64 = 0x23; const SIMPLE_BLOCK_ID: u64 = 0x23;
pub fn parse_webm<'a, T: AsRef<[u8]> + ?Sized>(source: &'a T) -> EbmlCursor<'a> { pub fn parse_webm<'a, T: AsRef<[u8]> + ?Sized>(source: &'a T) -> EbmlSlice<'a> {
EbmlCursor::new(source.as_ref()) EbmlSlice(source.as_ref())
} }
#[derive(Debug, PartialEq, Copy, Clone)] #[derive(Debug, PartialEq, Copy, Clone)]