aboutsummaryrefslogtreecommitdiff
path: root/matroska
diff options
context:
space:
mode:
Diffstat (limited to 'matroska')
-rw-r--r--matroska/src/write.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/matroska/src/write.rs b/matroska/src/write.rs
index 8fc17c3..63cec2b 100644
--- a/matroska/src/write.rs
+++ b/matroska/src/write.rs
@@ -90,13 +90,15 @@ impl MatroskaTag {
pub fn write_full(&self, w: &mut Vec<u8>) -> Result<()> {
let mut buf = vec![];
buf.extend(self.id().to_be_bytes().iter().skip_while(|&v| *v == 0u8));
- // note: it is relevant here, to pass the buffer with the id, such that closing tags, can clear it
+ //* note: it is relevant here, to pass the buffer with the id, such that closing tags, can clear it
self.write(&mut buf)?;
w.extend_from_slice(&buf);
Ok(())
}
}
+/// this routine works only, if the varint is as small as it can possibly be.
+/// thats not always what we do though - see below
pub fn vint_length(v: u64) -> usize {
let mut len = 1;
while len <= 8 {
@@ -107,8 +109,17 @@ pub fn vint_length(v: u64) -> usize {
}
len
}
+pub fn bad_vint_length(v: u64) -> usize {
+ match 64 - v.leading_zeros() {
+ x if x <= 8 => 1,
+ x if x <= 16 => 2,
+ x if x <= 32 => 4,
+ _ => 8,
+ }
+}
pub trait WriteValue {
+ /// writes the contents of a tag, including the size but excluding the id.
fn write_to(&self, w: &mut Vec<u8>) -> Result<()>;
}