aboutsummaryrefslogtreecommitdiff
path: root/matroska/src/write.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-01-25 07:42:27 +0100
committermetamuffin <metamuffin@disroot.org>2023-01-25 07:42:27 +0100
commit814896238c9b3928709f27606816ab6de60abdf3 (patch)
tree8134ed5213cf41f907f2af68ad9c8df245a937bd /matroska/src/write.rs
parent4529d07cc3f2f86a9dbb0d4802875a81d5c4c495 (diff)
downloadjellything-814896238c9b3928709f27606816ab6de60abdf3.tar
jellything-814896238c9b3928709f27606816ab6de60abdf3.tar.bz2
jellything-814896238c9b3928709f27606816ab6de60abdf3.tar.zst
generate seek index
Diffstat (limited to 'matroska/src/write.rs')
-rw-r--r--matroska/src/write.rs28
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);