Implement writing a barebones EBML header from scratch
This commit is contained in:
parent
95fcc6c86b
commit
45fe373ee6
3 changed files with 26 additions and 0 deletions
12
src/bin/stub.rs
Normal file
12
src/bin/stub.rs
Normal file
|
@ -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();
|
||||
}
|
|
@ -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)]
|
||||
|
|
13
src/webm.rs
13
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<WebmElement, Error> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn encode_webm_element<T: Write + Seek>(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;
|
||||
|
|
Loading…
Reference in a new issue