mp4_atom/
mdat.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use crate::*;

/// A media data atom.
///
/// I would not recommend using this for large files, as it reads the entire file into memory.
/// Instead, use [ReadFrom] to read the [Header] first followed by the mdat data.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Mdat {
    pub data: Bytes,
}

impl Atom for Mdat {
    const KIND: FourCC = FourCC::new(b"mdat");

    fn decode_body(buf: &mut Bytes) -> Result<Self> {
        Ok(Mdat {
            data: buf.decode()?,
        })
    }

    fn encode_body(&self, buf: &mut BytesMut) -> Result<()> {
        buf.encode(&self.data)
    }
}