diff options
author | metamuffin <metamuffin@disroot.org> | 2023-05-16 09:34:49 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-05-16 09:34:49 +0200 |
commit | d015e8245291247ba5907fa90720d027fde0cd07 (patch) | |
tree | fd44dd53085719b67d45cdd31c580492f930f945 /matroska | |
parent | 1831529a7a643108fe1122b191b4603cb258552c (diff) | |
download | jellything-d015e8245291247ba5907fa90720d027fde0cd07.tar jellything-d015e8245291247ba5907fa90720d027fde0cd07.tar.bz2 jellything-d015e8245291247ba5907fa90720d027fde0cd07.tar.zst |
cue drift fixed. YAYYY!
Diffstat (limited to 'matroska')
-rw-r--r-- | matroska/src/write.rs | 13 |
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<()>; } |