mp4_atom/moov/trak/mdia/minf/dinf/dref/
url.rs

1use crate::*;
2
3ext! {
4    name: Url,
5    versions: [0],
6    flags: {
7        self_contained = 1,
8    }
9}
10
11#[derive(Debug, Clone, PartialEq, Eq, Default)]
12#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
13pub struct Url {
14    pub location: String,
15}
16
17impl AtomExt for Url {
18    type Ext = UrlExt;
19
20    const KIND_EXT: FourCC = FourCC::new(b"url ");
21
22    fn decode_body_ext<B: Buf>(buf: &mut B, _ext: UrlExt) -> Result<Self> {
23        let location = match buf.has_remaining() {
24            true => String::decode(buf)?,
25            false => "".to_string(),
26        };
27
28        Ok(Url { location })
29    }
30
31    fn encode_body_ext<B: BufMut>(&self, buf: &mut B) -> Result<UrlExt> {
32        if !self.location.is_empty() {
33            self.location.as_str().encode(buf)?;
34        }
35
36        Ok(UrlExt {
37            // TODO what does this do?
38            self_contained: true,
39            ..Default::default()
40        })
41    }
42}