Skip to content

Commit d085422

Browse files
committed
EBML: Writing WIP
1 parent e37fe44 commit d085422

File tree

8 files changed

+93
-7
lines changed

8 files changed

+93
-7
lines changed

lofty/src/ebml/read/segment_cluster.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ where
6969
continue;
7070
}
7171

72-
total_audio_data_size += (size.value() - u64::from(header_size));
72+
total_audio_data_size += size.value() - u64::from(header_size);
7373
},
7474
ElementIdent::BlockGroup => read_block_group(
7575
&mut children_reader.children(),
@@ -144,7 +144,7 @@ where
144144
continue;
145145
}
146146

147-
*total_audio_data_size += (size.value() - u64::from(header_size));
147+
*total_audio_data_size += size.value() - u64::from(header_size);
148148
}
149149

150150
Ok(())

lofty/src/ebml/read/segment_tags.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ where
215215

216216
Ok(SimpleTag {
217217
name: name.into(),
218-
language,
218+
language: language.unwrap_or_default(),
219219
default,
220220
value,
221221
})

lofty/src/ebml/read/segment_tracks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ where
107107
_ => unreachable!("Unhandled child element in TrackEntry: {:?}", ident),
108108
}
109109
},
110-
ElementReaderYield::Master((id, size)) => match id {
110+
ElementReaderYield::Master((id, _size)) => match id {
111111
ElementIdent::Audio => {
112112
read_audio_settings(&mut children_reader.children(), parse_options, &mut track)?
113113
},

lofty/src/ebml/tag/mod.rs

+38-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub use tag_name::*;
1616
pub use target::*;
1717

1818
use crate::config::{global_options, WriteOptions};
19-
use crate::error::LoftyError;
19+
use crate::error::{LoftyError, Result};
2020
use crate::io::{FileLike, Length, Truncate};
2121
use crate::picture::Picture;
2222
use crate::tag::companion_tag::CompanionTag;
@@ -25,7 +25,6 @@ use crate::tag::{Accessor, MergeTag, SplitTag, TagExt, TagType};
2525
use std::borrow::Cow;
2626
use std::io::Write;
2727
use std::ops::Deref;
28-
use std::path::Path;
2928

3029
use lofty_attr::tag;
3130

@@ -405,3 +404,40 @@ impl From<crate::tag::Tag> for MatroskaTag {
405404
SplitTagRemainder::default().merge_tag(input)
406405
}
407406
}
407+
408+
pub(crate) struct MatroskaTagRef<'a, I, S>
409+
where
410+
I: Iterator<Item = TagRef<'a, S>>,
411+
S: Iterator<Item = Cow<'a, SimpleTag<'a>>> + 'a,
412+
{
413+
tags: I,
414+
}
415+
416+
impl<'a, I, S> From<&'a crate::tag::Tag> for MatroskaTagRef<'a, I, S>
417+
where
418+
I: Iterator<Item = TagRef<'a, S>>,
419+
S: Iterator<Item = Cow<'a, SimpleTag<'a>>>,
420+
{
421+
fn from(_tag: &'a crate::tag::Tag) -> Self {
422+
todo!()
423+
}
424+
}
425+
426+
impl<'a, I, S> MatroskaTagRef<'a, I, S>
427+
where
428+
I: Iterator<Item = TagRef<'a, S>>,
429+
S: Iterator<Item = Cow<'a, SimpleTag<'a>>>,
430+
{
431+
pub(crate) fn write_to<F>(&mut self, _file: &mut F, _write_options: WriteOptions) -> Result<()>
432+
where
433+
F: FileLike,
434+
LoftyError: From<<F as Truncate>::Error>,
435+
LoftyError: From<<F as Length>::Error>,
436+
{
437+
todo!()
438+
}
439+
440+
fn dump_to<W: Write>(&self, _writer: &mut W, _write_options: WriteOptions) -> Result<()> {
441+
todo!()
442+
}
443+
}

lofty/src/ebml/tag/tag.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use super::simple_tag::SimpleTag;
22
use super::target::{Target, TargetDescriptor, TargetType};
33

4+
use std::borrow::Cow;
5+
46
/// A single metadata descriptor.
57
///
68
/// This represents a `\Segment\Tags\Tag` element in the EBML tree. It contains a single [`Target`] and
@@ -119,3 +121,11 @@ impl Tag<'static> {
119121
self.simple_tags.extend(other.simple_tags);
120122
}
121123
}
124+
125+
pub(crate) struct TagRef<'a, I>
126+
where
127+
I: Iterator<Item = Cow<'a, SimpleTag<'a>>>,
128+
{
129+
pub(crate) targets: TargetDescriptor<'a>,
130+
pub(crate) simple_tags: &'a mut I,
131+
}
+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#![allow(non_upper_case_globals)]
2+
13
pub(super) mod attached_file;
2-
mod simple_tag;
4+
pub(super) mod simple_tag;
5+
pub(super) mod tags;
36
pub(super) mod target;
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use crate::ebml::tag::write::{write_element, ElementWriterCtx, WriteableElement};
2+
use crate::ebml::{ElementId, SimpleTag, TagRef};
3+
use crate::io::FileLike;
4+
5+
use std::borrow::Cow;
6+
use std::io::Cursor;
7+
8+
impl<'a, I> WriteableElement for TagRef<'a, I>
9+
where
10+
I: Iterator<Item = Cow<'a, SimpleTag<'a>>>,
11+
{
12+
const ID: ElementId = ElementId(0x7373);
13+
14+
fn write_element<F: FileLike>(
15+
&self,
16+
ctx: ElementWriterCtx,
17+
writer: &mut F,
18+
) -> crate::error::Result<()> {
19+
let mut element_children = Cursor::new(Vec::new());
20+
self.targets.write_element(ctx, &mut element_children)?;
21+
22+
// TODO
23+
// for simple_tag in self.simple_tags {
24+
// simple_tag.write_element(ctx, &mut element_children)?;
25+
// }
26+
27+
write_element(
28+
ctx,
29+
Self::ID,
30+
&element_children.get_ref().as_slice(),
31+
writer,
32+
)?;
33+
34+
Ok(())
35+
}
36+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)