EBML: Impl some TagExt methods

This commit is contained in:
Serial 2024-09-16 02:41:19 -04:00
parent 6f1404ae61
commit 0eb55e6b68
No known key found for this signature in database
GPG key ID: DA95198DC17C4568
5 changed files with 21 additions and 4 deletions

View file

@ -16,7 +16,7 @@ pub use vint::VInt;
/// An EBML file
#[derive(LoftyFile, Default)]
#[lofty(read_fn = "read::read_from")]
// TODO: #[lofty(internal_write_module_do_not_use_anywhere_else)]
#[lofty(internal_write_module_do_not_use_anywhere_else)]
pub struct EbmlFile {
/// An EBML tag
#[lofty(tag_type = "Ebml")]

View file

@ -2,6 +2,7 @@ mod attached_file;
mod simple_tag;
mod tag;
mod target;
mod write;
pub use attached_file::*;
pub use simple_tag::*;
@ -39,7 +40,11 @@ impl TagExt for EbmlTag {
}
fn len(&self) -> usize {
todo!()
self.tags
.iter()
.map(|tag| tag.simple_tags.len())
.sum::<usize>()
+ self.attached_files.len()
}
fn contains<'a>(&'a self, _key: Self::RefKey<'a>) -> bool {
@ -47,7 +52,7 @@ impl TagExt for EbmlTag {
}
fn is_empty(&self) -> bool {
todo!()
self.tags.is_empty() && self.attached_files.is_empty()
}
fn save_to<F>(
@ -85,7 +90,8 @@ impl TagExt for EbmlTag {
}
fn clear(&mut self) {
todo!()
self.tags.clear();
self.attached_files.clear();
}
}

View file

@ -93,3 +93,12 @@ pub struct Target {
/// [`AttachedFile::uid`]: crate::ebml::AttachedFile::uid
pub attachment_uids: Option<Vec<u64>>,
}
impl From<TargetType> for Target {
fn from(target_type: TargetType) -> Self {
Self {
target_type,
..Default::default()
}
}
}

View file

View file

@ -51,6 +51,8 @@ pub(crate) fn init_write_lookup(
.write_to(file, write_options)
});
insert!(map, Ebml, { todo!() });
insert!(map, Id3v1, {
Into::<lofty::id3::v1::tag::Id3v1TagRef<'_>>::into(tag).write_to(file, write_options)
});