diff options
author | metamuffin <metamuffin@disroot.org> | 2023-01-14 18:04:16 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-01-14 18:04:16 +0100 |
commit | f452df18749b13f9d83a6ea679361d195b4a9ae1 (patch) | |
tree | 04897eef044ebed319949a0cdbd04232f0dce98c /ebml/src/size.rs | |
parent | 6c023ddeaa0894813fc74038af7568c2d867c052 (diff) | |
download | jellything-f452df18749b13f9d83a6ea679361d195b4a9ae1.tar jellything-f452df18749b13f9d83a6ea679361d195b4a9ae1.tar.bz2 jellything-f452df18749b13f9d83a6ea679361d195b4a9ae1.tar.zst |
seeking and broken writing
Diffstat (limited to 'ebml/src/size.rs')
-rw-r--r-- | ebml/src/size.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/ebml/src/size.rs b/ebml/src/size.rs new file mode 100644 index 0000000..06d6ba8 --- /dev/null +++ b/ebml/src/size.rs @@ -0,0 +1,29 @@ + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum EbmlSize { + Exact(usize), + Unknown, +} +impl EbmlSize { + pub fn from_vint((value, len): (u64, usize)) -> EbmlSize { + if value == ((1 << (7 * len)) - 1) { + Self::Unknown + } else { + Self::Exact(value as usize) + } + } + pub fn some(self) -> Option<usize> { + match self { + EbmlSize::Exact(s) => Some(s), + EbmlSize::Unknown => None, + } + } +} +impl Into<usize> for EbmlSize { + fn into(self) -> usize { + match self { + EbmlSize::Exact(s) => s, + EbmlSize::Unknown => panic!("unknown size, where it should have been known"), + } + } +} |