diff --git a/src/bin/stub.rs b/src/bin/stub.rs new file mode 100644 index 0000000..509ebe8 --- /dev/null +++ b/src/bin/stub.rs @@ -0,0 +1,12 @@ +extern crate lab_ebml; + +use std::io::{Cursor, stdout, Write}; +use lab_ebml::webm::*; + +pub fn main() { + let mut cursor = Cursor::new(Vec::new()); + + encode_webm_element(WebmElement::EbmlHead, &mut cursor).unwrap(); + + stdout().write_all(&cursor.get_ref()).unwrap(); +} diff --git a/src/ebml.rs b/src/ebml.rs index 793ad13..e29e5ec 100644 --- a/src/ebml.rs +++ b/src/ebml.rs @@ -4,6 +4,7 @@ use std::fmt::{Display, Formatter, Result as FmtResult}; use std::io::{Cursor, Error as IoError, ErrorKind, Result as IoResult, Write, Seek, SeekFrom}; pub const EBML_HEAD_ID: u64 = 0x0A45DFA3; +pub const DOC_TYPE_ID: u64 = 0x0282; pub const VOID_ID: u64 = 0x6C; #[derive(Debug, PartialEq)] diff --git a/src/webm.rs b/src/webm.rs index 6a2d645..22b0885 100644 --- a/src/webm.rs +++ b/src/webm.rs @@ -1,3 +1,4 @@ +use std::io::{Error as IoError, ErrorKind, Result as IoResult, Write, Seek}; use bytes::{BigEndian, ByteOrder}; use ebml::*; @@ -79,6 +80,18 @@ fn decode_simple_block(bytes: &[u8]) -> Result { } } +pub fn encode_webm_element(element: WebmElement, output: &mut T) -> IoResult<()> { + let mut start = 0; + match element { + WebmElement::EbmlHead => { + encode_element(EBML_HEAD_ID, output, |output| { + encode_string(DOC_TYPE_ID, "webm", output) + }) + } + _ => Err(IoError::new(ErrorKind::InvalidInput, WriteError::OutOfRange)) + } +} + #[cfg(test)] mod tests { use tests::TEST_FILE;