Generalize string writing to binary writing
This commit is contained in:
parent
b76f244022
commit
509dcd3827
2 changed files with 5 additions and 5 deletions
|
@ -197,10 +197,10 @@ pub fn encode_tag_header<T: Write>(tag: u64, size: Varint, output: &mut T) -> Io
|
||||||
encode_varint(size, output)
|
encode_varint(size, output)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tries to write a simple EBML tag with a string value
|
/// Tries to write a simple EBML tag with a string or binary value
|
||||||
pub fn encode_string<T: Write>(tag: u64, string: &str, output: &mut T) -> IoResult<()> {
|
pub fn encode_bytes<T: Write>(tag: u64, bytes: &[u8], output: &mut T) -> IoResult<()> {
|
||||||
encode_tag_header(tag, Varint::Value(string.len() as u64), output)?;
|
encode_tag_header(tag, Varint::Value(bytes.len() as u64), output)?;
|
||||||
output.write_all(string.as_ref())
|
output.write_all(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tries to write a simple EBML tag with an integer value
|
/// Tries to write a simple EBML tag with an integer value
|
||||||
|
|
|
@ -83,7 +83,7 @@ fn decode_simple_block(bytes: &[u8]) -> Result<WebmElement, Error> {
|
||||||
pub fn encode_webm_element<T: Write + Seek>(element: WebmElement, output: &mut T) -> IoResult<()> {
|
pub fn encode_webm_element<T: Write + Seek>(element: WebmElement, output: &mut T) -> IoResult<()> {
|
||||||
match element {
|
match element {
|
||||||
WebmElement::EbmlHead => encode_element(EBML_HEAD_ID, output, |output| {
|
WebmElement::EbmlHead => encode_element(EBML_HEAD_ID, output, |output| {
|
||||||
encode_string(DOC_TYPE_ID, "webm", output)
|
encode_bytes(DOC_TYPE_ID, "webm".as_bytes(), output)
|
||||||
}),
|
}),
|
||||||
WebmElement::Segment => encode_tag_header(SEGMENT_ID, Varint::Unknown, output),
|
WebmElement::Segment => encode_tag_header(SEGMENT_ID, Varint::Unknown, output),
|
||||||
WebmElement::SeekHead => Ok(()),
|
WebmElement::SeekHead => Ok(()),
|
||||||
|
|
Loading…
Reference in a new issue