rename EbmlStreamingParser to reflect genericity, change construction to Stream extension
This commit is contained in:
parent
8189794287
commit
be92d04c09
3 changed files with 16 additions and 10 deletions
|
@ -11,7 +11,7 @@ use futures::stream::repeat;
|
|||
use futures::stream::Stream;
|
||||
use lab_ebml::chunk::{Chunk, WebmStream, ChunkingError};
|
||||
use lab_ebml::timecode_fixer::ChunkStream;
|
||||
use lab_ebml::webm_stream::WebmBuffer;
|
||||
use lab_ebml::stream_parser::StreamEbml;
|
||||
use hyper::{Get, StatusCode};
|
||||
use hyper::header::ContentType;
|
||||
use hyper::server::{Http, Request, Response, Service};
|
||||
|
@ -34,7 +34,7 @@ impl Service for WebmServer {
|
|||
let stream: BodyStream<Vec<u8>> = Box::new(
|
||||
repeat(()).take(3)
|
||||
.map(|()| {
|
||||
WebmBuffer::new(once::<&[u8], ()>(Ok(SRC_FILE))).chunk_webm()
|
||||
once::<&[u8], ()>(Ok(SRC_FILE)).parse_ebml().chunk_webm()
|
||||
}).flatten()
|
||||
.fix_timecodes()
|
||||
.map_err(|err| match err {
|
||||
|
|
|
@ -6,8 +6,8 @@ pub mod chunk;
|
|||
pub mod ebml;
|
||||
mod iterator;
|
||||
pub mod slice;
|
||||
pub mod stream_parser;
|
||||
|
||||
pub mod webm_stream;
|
||||
pub mod timecode_fixer;
|
||||
pub mod webm;
|
||||
|
||||
|
|
|
@ -12,21 +12,27 @@ pub enum ParsingError<E> {
|
|||
OtherError(E)
|
||||
}
|
||||
|
||||
pub struct WebmBuffer<S> {
|
||||
pub struct EbmlStreamingParser<S> {
|
||||
stream: S,
|
||||
buffer: BytesMut,
|
||||
last_read: usize
|
||||
}
|
||||
|
||||
impl<I: AsRef<[u8]>, S: Stream<Item = I>> WebmBuffer<S> {
|
||||
pub fn new(stream: S) -> Self {
|
||||
WebmBuffer {
|
||||
stream: stream,
|
||||
pub trait StreamEbml<I: AsRef<[u8]>, S: Stream<Item = I>> {
|
||||
fn parse_ebml(self) -> EbmlStreamingParser<S>;
|
||||
}
|
||||
|
||||
impl<I: AsRef<[u8]>, S: Stream<Item = I>> StreamEbml<I, S> for S {
|
||||
fn parse_ebml(self) -> EbmlStreamingParser<S> {
|
||||
EbmlStreamingParser {
|
||||
stream: self,
|
||||
buffer: BytesMut::new(),
|
||||
last_read: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: AsRef<[u8]>, S: Stream<Item = I>> EbmlStreamingParser<S> {
|
||||
pub fn poll_event<'a, T: FromEbml<'a>>(&'a mut self) -> Result<Async<Option<T>>, ParsingError<S::Error>> {
|
||||
// release buffer from previous event
|
||||
self.buffer.advance(self.last_read);
|
||||
|
@ -72,11 +78,11 @@ impl<I: AsRef<[u8]>, S: Stream<Item = I>> WebmBuffer<S> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<I: AsRef<[u8]>, S: Stream<Item = I>> EbmlEventSource for WebmBuffer<S> {
|
||||
impl<I: AsRef<[u8]>, S: Stream<Item = I>> EbmlEventSource for EbmlStreamingParser<S> {
|
||||
type Error = ParsingError<S::Error>;
|
||||
|
||||
fn poll_event<'a, T: FromEbml<'a>>(&'a mut self) -> Result<Async<Option<T>>, Self::Error> {
|
||||
return WebmBuffer::poll_event(self);
|
||||
return EbmlStreamingParser::poll_event(self);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in a new issue