1use crate::{full_box};
2use crate::bytes_read::{Mp4Readable, ReadMp4};
3use crate::error::{MP4Error};
4use crate::header::BoxHeader;
5use crate::mp4box::box_trait::{BoxRead, BoxWrite, IBox};
6use crate::mp4box::url::UrlBox;
7use crate::mp4box::urn::UrnBox;
8use crate::types::array::Mp4Array;
9use async_trait::async_trait;
10use DataEntryBox::{Unknown, Urn};
11use crate::bytes_write::{Mp4Writable, WriteMp4};
12use crate::mp4box::box_unknown::UnknownBox;
13use crate::mp4box::dref::DataEntryBox::Url;
14
15#[derive(Debug, Clone, Eq, PartialEq, Hash)]
16pub enum DataEntryBox {
17 Url(UrlBox),
18 Urn(UrnBox),
19 Unknown(UnknownBox)
20}
21
22#[async_trait]
23impl Mp4Readable for DataEntryBox {
24 async fn read<R: ReadMp4>(reader: &mut R) -> Result<Self, MP4Error> {
25 let header: BoxHeader = reader.read().await?;
26 Ok(match header.id {
27 UrlBox::ID => Url(<UrlBox as BoxRead>::read(header, reader).await?),
28 UrnBox::ID => Urn(<UrnBox as BoxRead>::read(header, reader).await?),
29 _ => Unknown(<UnknownBox as BoxRead>::read(header, reader).await?)
30 })
31 }
32}
33
34impl Mp4Writable for DataEntryBox {
35 fn byte_size(&self) -> usize {
36 match self {
37 Url(it) => it.byte_size(),
38 Urn(it ) => it.byte_size(),
39 Unknown(it) => it.byte_size()
40 }
41 }
42
43 fn write<W: WriteMp4>(&self, writer: &mut W) -> Result<usize, MP4Error> {
44 match self {
45 Url(it) => it.write(writer),
46 Urn(it ) => it.write(writer),
47 Unknown(it) => it.write(writer),
48 }
49 }
50}
51
52full_box! {
53 box (b"dref", Dref, DrefBox, u32) data {
54 entries: Mp4Array<u32, DataEntryBox>
55 }
56}
57
58impl Default for Dref {
59 fn default() -> Self {
60 Self {
61 entries: vec![Url(UrlBox::default())].into()
62 }
63 }
64}