Ilst: Add AtomData::Bool for flag atoms

This commit is contained in:
Serial 2022-11-09 14:10:03 -05:00 committed by Alex
parent e4c0ea5579
commit 742eaa680f
4 changed files with 25 additions and 1 deletions

View file

@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- **TagExt**: `TagExt::contains`
- **Ilst**: `AtomData::Bool` for the various flag atoms such as `cpil`, `pcst`, etc.
### Changed
- **Files**: Return the removed tag from `<File>::remove(TagType)`

View file

@ -165,7 +165,6 @@ impl Debug for Atom {
/// to the link above for codes.
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum AtomData {
// TODO: Bool variant for the various flag atoms?
/// A UTF-8 encoded string
UTF8(String),
/// A UTF-16 encoded string
@ -188,6 +187,12 @@ pub enum AtomData {
///
/// NOTE: See [`AtomData::SignedInteger`]
UnsignedInteger(u32),
/// A boolean value
///
/// NOTE: This isn't an official data type, but multiple flag atoms exist,
/// so this makes them easier to represent. The *real* underlying type
/// is `SignedInteger`.
Bool(bool),
/// Unknown data
///
/// Due to the number of possible types, there are many

View file

@ -86,6 +86,23 @@ where
continue;
},
b"cpil" | b"hdvd" | b"pcst" | b"pgap" | b"shwm" => {
if let Some(atom_data) = parse_data_inner(&mut ilst_reader, &atom)? {
if let Some((_, content)) = atom_data.first() {
let data = match content[..] {
[0, ..] => AtomData::Bool(false),
_ => AtomData::Bool(true),
};
tag.atoms.push(Atom {
ident: AtomIdent::Fourcc(*fourcc),
data: AtomDataStorage::Single(data),
})
}
}
continue;
},
_ => {},
}
}

View file

@ -381,6 +381,7 @@ where
AtomData::Picture(ref pic) => write_picture(pic, writer)?,
AtomData::SignedInteger(int) => write_signed_int(*int, writer)?,
AtomData::UnsignedInteger(uint) => write_unsigned_int(*uint, writer)?,
AtomData::Bool(b) => write_signed_int(i32::from(*b), writer)?,
AtomData::Unknown { code, ref data } => write_data(*code, data, writer)?,
};
}