diff options
Diffstat (limited to 'matroska/src/write.rs')
-rw-r--r-- | matroska/src/write.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/matroska/src/write.rs b/matroska/src/write.rs index 70ee06c..ee1c44c 100644 --- a/matroska/src/write.rs +++ b/matroska/src/write.rs @@ -26,6 +26,31 @@ impl EbmlWriter { Ok(()) } + pub fn write_padding(&mut self, position: usize) -> Result<()> { + let mut size = position - self.position; + match size { + 0 => return Ok(()), + 1 => bail!("this is sadly not possible"), + _ => (), + } + size -= 1; // subtract tag size + size -= 4; // subtract vint size + + // match size { + // _ if size < (1 << 7) => size -= 1, + // _ if size < (1 << 14) => size -= 2, + // _ if size < (1 << 21) => size -= 3, + // _ if size < (1 << 28) => size -= 4, + // _ if size < (1 << 35) => size -= 5, + // _ => bail!("padding to large"), + // } + + self.write(&[0xec])?; + self.write_vint_len(size.try_into().unwrap(), 4)?; + self.write(&vec![0; size])?; + Ok(()) + } + pub fn write_tag(&mut self, tag: &MatroskaTag) -> Result<()> { let mut buf = vec![]; tag.write_full(&mut buf)?; @@ -44,6 +69,9 @@ impl EbmlWriter { } len += 1; } + self.write_vint_len(i, len) + } + pub fn write_vint_len(&mut self, i: u64, len: usize) -> Result<()> { let mut bytes = i.to_be_bytes(); let trunc = &mut bytes[(8 - len)..]; trunc[0] |= 1 << (8 - len); |