Remove EbmlEventSource trait in favor of concrete EbmlStreamingParser
This commit is contained in:
parent
fa85939c0b
commit
eda2e4f7be
3 changed files with 13 additions and 26 deletions
21
src/chunk.rs
21
src/chunk.rs
|
@ -1,10 +1,10 @@
|
|||
use bytes::Bytes;
|
||||
use bytes::{Buf, Bytes};
|
||||
use futures::{Async, Stream};
|
||||
use std::{
|
||||
io::Cursor,
|
||||
mem
|
||||
};
|
||||
use crate::ebml::EbmlEventSource;
|
||||
use crate::stream_parser::EbmlStreamingParser;
|
||||
use crate::error::WebmetroError;
|
||||
use crate::webm::*;
|
||||
|
||||
|
@ -103,7 +103,7 @@ enum ChunkerState {
|
|||
}
|
||||
|
||||
pub struct WebmChunker<S> {
|
||||
source: S,
|
||||
source: EbmlStreamingParser<S>,
|
||||
buffer_size_limit: Option<usize>,
|
||||
state: ChunkerState
|
||||
}
|
||||
|
@ -128,8 +128,7 @@ fn encode(element: WebmElement, buffer: &mut Cursor<Vec<u8>>, limit: Option<usiz
|
|||
encode_webm_element(element, buffer).map_err(|err| err.into())
|
||||
}
|
||||
|
||||
impl<S: EbmlEventSource> Stream for WebmChunker<S>
|
||||
where S::Error: Into<WebmetroError>
|
||||
impl<I: Buf, S: Stream<Item = I, Error = WebmetroError>> Stream for WebmChunker<S>
|
||||
{
|
||||
type Item = Chunk;
|
||||
type Error = WebmetroError;
|
||||
|
@ -266,8 +265,14 @@ where S::Error: Into<WebmetroError>
|
|||
}
|
||||
}
|
||||
|
||||
pub trait WebmStream where Self: Sized + EbmlEventSource {
|
||||
fn chunk_webm(self) -> WebmChunker<Self> {
|
||||
pub trait WebmStream {
|
||||
type Stream;
|
||||
fn chunk_webm(self) -> WebmChunker<Self::Stream>;
|
||||
}
|
||||
|
||||
impl<S: Stream> WebmStream for EbmlStreamingParser<S> {
|
||||
type Stream = S;
|
||||
fn chunk_webm(self) -> WebmChunker<S> {
|
||||
WebmChunker {
|
||||
source: self,
|
||||
buffer_size_limit: None,
|
||||
|
@ -276,8 +281,6 @@ pub trait WebmStream where Self: Sized + EbmlEventSource {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: EbmlEventSource> WebmStream for T {}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use bytes::{BigEndian, ByteOrder, BufMut};
|
||||
use custom_error::custom_error;
|
||||
use std::io::{Cursor, Error as IoError, ErrorKind, Result as IoResult, Write, Seek, SeekFrom};
|
||||
use futures::Async;
|
||||
|
||||
pub const EBML_HEAD_ID: u64 = 0x0A45DFA3;
|
||||
pub const DOC_TYPE_ID: u64 = 0x0282;
|
||||
|
@ -261,11 +260,6 @@ pub trait FromEbml<'a>: Sized {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait EbmlEventSource {
|
||||
type Error;
|
||||
fn poll_event<'a, T: FromEbml<'a>>(&'a mut self) -> Result<Async<Option<T>>, Self::Error>;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use bytes::{BytesMut};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use bytes::{Buf, BufMut, Bytes, BytesMut};
|
||||
use futures::{stream::Stream, Async};
|
||||
|
||||
use crate::ebml::{EbmlEventSource, FromEbml};
|
||||
use crate::ebml::FromEbml;
|
||||
use crate::error::WebmetroError;
|
||||
|
||||
pub struct EbmlStreamingParser<S> {
|
||||
|
@ -76,16 +76,6 @@ impl<I: Buf, S: Stream<Item = I, Error = WebmetroError>> EbmlStreamingParser<S>
|
|||
}
|
||||
}
|
||||
|
||||
impl<I: Buf, S: Stream<Item = I, Error = WebmetroError>> EbmlEventSource
|
||||
for EbmlStreamingParser<S>
|
||||
{
|
||||
type Error = WebmetroError;
|
||||
|
||||
fn poll_event<'a, T: FromEbml<'a>>(&'a mut self) -> Result<Async<Option<T>>, WebmetroError> {
|
||||
return EbmlStreamingParser::poll_event(self);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use bytes::IntoBuf;
|
||||
|
|
Loading…
Reference in a new issue