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()[..])
}
#[derive(Debug, PartialEq)]
pub struct Ebml<Source> {
pub source: Source
}
pub trait FromEbml<'a>: Sized {
/// 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

View File

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

View File

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