Generalize string writing to binary writing

This commit is contained in:
Tangent 128 2017-08-09 01:49:44 -04:00
parent b76f244022
commit 509dcd3827
2 changed files with 5 additions and 5 deletions

View File

@ -197,10 +197,10 @@ pub fn encode_tag_header<T: Write>(tag: u64, size: Varint, output: &mut T) -> Io
encode_varint(size, output)
}
/// Tries to write a simple EBML tag with a string value
pub fn encode_string<T: Write>(tag: u64, string: &str, output: &mut T) -> IoResult<()> {
encode_tag_header(tag, Varint::Value(string.len() as u64), output)?;
output.write_all(string.as_ref())
/// Tries to write a simple EBML tag with a string or binary value
pub fn encode_bytes<T: Write>(tag: u64, bytes: &[u8], output: &mut T) -> IoResult<()> {
encode_tag_header(tag, Varint::Value(bytes.len() as u64), output)?;
output.write_all(bytes)
}
/// Tries to write a simple EBML tag with an integer value

View File

@ -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<()> {
match element {
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::SeekHead => Ok(()),