EBML: Writing WIP

This commit is contained in:
Serial 2024-10-28 12:24:36 -04:00
parent 756f022584
commit d99f902344
No known key found for this signature in database
GPG key ID: DA95198DC17C4568
8 changed files with 93 additions and 7 deletions

View file

@ -69,7 +69,7 @@ where
continue;
}
total_audio_data_size += (size.value() - u64::from(header_size));
total_audio_data_size += size.value() - u64::from(header_size);
},
ElementIdent::BlockGroup => read_block_group(
&mut children_reader.children(),
@ -144,7 +144,7 @@ where
continue;
}
*total_audio_data_size += (size.value() - u64::from(header_size));
*total_audio_data_size += size.value() - u64::from(header_size);
}
Ok(())

View file

@ -215,7 +215,7 @@ where
Ok(SimpleTag {
name: name.into(),
language,
language: language.unwrap_or_default(),
default,
value,
})

View file

@ -107,7 +107,7 @@ where
_ => unreachable!("Unhandled child element in TrackEntry: {:?}", ident),
}
},
ElementReaderYield::Master((id, size)) => match id {
ElementReaderYield::Master((id, _size)) => match id {
ElementIdent::Audio => {
read_audio_settings(&mut children_reader.children(), parse_options, &mut track)?
},

View file

@ -16,7 +16,7 @@ pub use tag_name::*;
pub use target::*;
use crate::config::{global_options, WriteOptions};
use crate::error::LoftyError;
use crate::error::{LoftyError, Result};
use crate::io::{FileLike, Length, Truncate};
use crate::picture::Picture;
use crate::tag::companion_tag::CompanionTag;
@ -25,7 +25,6 @@ use crate::tag::{Accessor, MergeTag, SplitTag, TagExt, TagType};
use std::borrow::Cow;
use std::io::Write;
use std::ops::Deref;
use std::path::Path;
use lofty_attr::tag;
@ -405,3 +404,40 @@ impl From<crate::tag::Tag> for MatroskaTag {
SplitTagRemainder::default().merge_tag(input)
}
}
pub(crate) struct MatroskaTagRef<'a, I, S>
where
I: Iterator<Item = TagRef<'a, S>>,
S: Iterator<Item = Cow<'a, SimpleTag<'a>>> + 'a,
{
tags: I,
}
impl<'a, I, S> From<&'a crate::tag::Tag> for MatroskaTagRef<'a, I, S>
where
I: Iterator<Item = TagRef<'a, S>>,
S: Iterator<Item = Cow<'a, SimpleTag<'a>>>,
{
fn from(_tag: &'a crate::tag::Tag) -> Self {
todo!()
}
}
impl<'a, I, S> MatroskaTagRef<'a, I, S>
where
I: Iterator<Item = TagRef<'a, S>>,
S: Iterator<Item = Cow<'a, SimpleTag<'a>>>,
{
pub(crate) fn write_to<F>(&mut self, _file: &mut F, _write_options: WriteOptions) -> Result<()>
where
F: FileLike,
LoftyError: From<<F as Truncate>::Error>,
LoftyError: From<<F as Length>::Error>,
{
todo!()
}
fn dump_to<W: Write>(&self, _writer: &mut W, _write_options: WriteOptions) -> Result<()> {
todo!()
}
}

View file

@ -1,6 +1,8 @@
use super::simple_tag::SimpleTag;
use super::target::{Target, TargetDescriptor, TargetType};
use std::borrow::Cow;
/// A single metadata descriptor.
///
/// This represents a `\Segment\Tags\Tag` element in the EBML tree. It contains a single [`Target`] and
@ -119,3 +121,11 @@ impl Tag<'static> {
self.simple_tags.extend(other.simple_tags);
}
}
pub(crate) struct TagRef<'a, I>
where
I: Iterator<Item = Cow<'a, SimpleTag<'a>>>,
{
pub(crate) targets: TargetDescriptor<'a>,
pub(crate) simple_tags: &'a mut I,
}

View file

@ -1,3 +1,6 @@
#![allow(non_upper_case_globals)]
pub(super) mod attached_file;
mod simple_tag;
pub(super) mod simple_tag;
pub(super) mod tags;
pub(super) mod target;

View file

@ -0,0 +1,36 @@
use crate::ebml::tag::write::{write_element, ElementWriterCtx, WriteableElement};
use crate::ebml::{ElementId, SimpleTag, TagRef};
use crate::io::FileLike;
use std::borrow::Cow;
use std::io::Cursor;
impl<'a, I> WriteableElement for TagRef<'a, I>
where
I: Iterator<Item = Cow<'a, SimpleTag<'a>>>,
{
const ID: ElementId = ElementId(0x7373);
fn write_element<F: FileLike>(
&self,
ctx: ElementWriterCtx,
writer: &mut F,
) -> crate::error::Result<()> {
let mut element_children = Cursor::new(Vec::new());
self.targets.write_element(ctx, &mut element_children)?;
// TODO
// for simple_tag in self.simple_tags {
// simple_tag.write_element(ctx, &mut element_children)?;
// }
write_element(
ctx,
Self::ID,
&element_children.get_ref().as_slice(),
writer,
)?;
Ok(())
}
}

View file

@ -0,0 +1 @@