diff --git a/src/ebml.rs b/src/ebml.rs index 14248a9..23d24d1 100644 --- a/src/ebml.rs +++ b/src/ebml.rs @@ -157,6 +157,19 @@ pub fn encode_varint(varint: Varint, output: &mut T) -> IoResult(tag: u64, size: Varint, output: &mut T) -> IoResult { + let id_size = encode_varint(Varint::Value(tag), output)?; + let size_size = encode_varint(size, output)?; + Ok(id_size + size_size) +} + +/// Tries to write a simple EBML tag with a string value +pub fn encode_string(tag: u64, string: &str, output: &mut T) -> IoResult { + let tag_size = encode_tag_header(tag, Varint::Value(string.len() as u64), output)?; + let string_size = output.write_all(string.as_ref()).map(|()| string.len())?; + Ok(tag_size + string_size) +} + #[derive(Debug, PartialEq)] pub struct Ebml(pub S, pub T);