aboutsummaryrefslogtreecommitdiff
path: root/matroska/src/unflatten.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-01-28 03:21:03 +0100
committermetamuffin <metamuffin@disroot.org>2024-01-28 03:21:03 +0100
commitce9eb140ab9243d1c87ace4727a82b7fa50f964b (patch)
treeb64da94ba58f72a2371cdd8644dc48a178b7d260 /matroska/src/unflatten.rs
parentb514ec8cea2c2143e0bd7a0eb377c96a6f091d0d (diff)
downloadjellything-ce9eb140ab9243d1c87ace4727a82b7fa50f964b.tar
jellything-ce9eb140ab9243d1c87ace4727a82b7fa50f964b.tar.bz2
jellything-ce9eb140ab9243d1c87ace4727a82b7fa50f964b.tar.zst
fix yet another fundamental issue in the ebml reader and seekindex.
Diffstat (limited to 'matroska/src/unflatten.rs')
-rw-r--r--matroska/src/unflatten.rs24
1 files changed, 6 insertions, 18 deletions
diff --git a/matroska/src/unflatten.rs b/matroska/src/unflatten.rs
index 71089f4..944d2c7 100644
--- a/matroska/src/unflatten.rs
+++ b/matroska/src/unflatten.rs
@@ -3,30 +3,23 @@
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2024 metamuffin <metamuffin.org>
*/
-use crate::{matroska::MatroskaTag, Master};
use crate::Result;
-
-
-pub trait IterWithPos {
- type Item;
- fn next(&mut self) -> Option<Self::Item>;
- fn position(&self) -> usize;
-}
+use crate::{matroska::MatroskaTag, Master};
pub struct Unflat<'a> {
pub item: MatroskaTag,
pub children: Option<Unflatten<'a>>,
- pub position: usize,
+ pub position: Option<u64>,
}
pub struct Unflatten<'a> {
- inner: &'a mut dyn IterWithPos<Item = Result<MatroskaTag>>,
+ inner: &'a mut dyn Iterator<Item = Result<(Option<u64>, MatroskaTag)>>,
stop: bool,
end: Option<MatroskaTag>,
}
impl<'a> Unflatten<'a> {
- pub fn new(inner: &'a mut dyn IterWithPos<Item = Result<MatroskaTag>>) -> Self {
+ pub fn new(inner: &'a mut dyn Iterator<Item = Result<(Option<u64>, MatroskaTag)>>) -> Self {
Self {
inner,
stop: false,
@@ -34,7 +27,7 @@ impl<'a> Unflatten<'a> {
}
}
pub fn new_with_end(
- inner: &'a mut dyn IterWithPos<Item = Result<MatroskaTag>>,
+ inner: &'a mut dyn Iterator<Item = Result<(Option<u64>, MatroskaTag)>>,
start: MatroskaTag,
) -> Self {
Self {
@@ -47,19 +40,14 @@ impl<'a> Unflatten<'a> {
self.stop = true;
}
- pub fn position(&self) -> usize {
- self.inner.position()
- }
-
pub fn n(&mut self) -> Option<Result<Unflat>> {
if self.stop {
return None;
}
- let position = self.inner.position();
match self.inner.next() {
None => None,
Some(Err(e)) => Some(Err(e)),
- Some(Ok(item)) => {
+ Some(Ok((position, item))) => {
let master = MatroskaTag::is_master(item.id()).unwrap();
if Some(&item) == self.end.as_ref() {
self.stop = true;