use super::*;
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct Text {
pub state: State,
pub data: Cow<'static, [u8]>,
}
impl Atom for Text {
const FOURCC: Fourcc = TEXT_MEDIA;
}
impl ParseAtom for Text {
fn parse_atom(
reader: &mut (impl Read + Seek),
_cfg: &ParseConfig<'_>,
size: Size,
) -> crate::Result<Self> {
let bounds = find_bounds(reader, size)?;
let data = reader.read_u8_vec(size.content_len())?;
Ok(Self {
state: State::Existing(bounds),
data: Cow::Owned(data),
})
}
}
impl AtomSize for Text {
fn size(&self) -> Size {
Size::from(self.data.len() as u64)
}
}
impl WriteAtom for Text {
fn write_atom(&self, writer: &mut impl Write, _changes: &[Change<'_>]) -> crate::Result<()> {
self.write_head(writer)?;
writer.write_all(&self.data)?;
Ok(())
}
}
impl LeafAtomCollectChanges for Text {
fn state(&self) -> &State {
&self.state
}
fn atom_ref(&self) -> AtomRef<'_> {
AtomRef::Text(self)
}
}
impl Text {
pub fn media_chapter() -> Self {
Self {
state: State::Insert,
data: Cow::Borrowed(&[
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D, b'f', b't', b'a', b'b', 0x00, 0x01, 0x00, 0x01, 0x00, ]),
}
}
pub fn media_information_chapter() -> Self {
Self {
state: State::Insert,
data: Cow::Borrowed(&[
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, ]),
}
}
}