aboutsummaryrefslogtreecommitdiff
path: root/evc/src/header.rs
blob: 5244ce5a41542dddfc8e881993773cf12f8c12b2 (plain)
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
26
use crate::ser::{Ser, Sink, Source};

#[derive(Debug, Clone, PartialEq, Copy)]
pub struct Header {
    pub resolution: (usize, usize),
    pub frame_count: usize,
}

pub const MAGIC: [u8; 4] = [0x5eu8, 0xb1u8, 0xc3u8, 0x08u8];

impl Ser for Header {
    fn write(&self, sink: &mut impl std::io::Write) -> anyhow::Result<()> {
        sink.put(MAGIC)?;
        sink.put((self.resolution, self.frame_count))?;
        Ok(())
    }

    fn read(source: &mut impl std::io::Read) -> anyhow::Result<Self> {
        assert_eq!(source.get::<[u8; 4]>()?, MAGIC);
        let (resolution, frame_count) = source.get()?;
        Ok(Self {
            resolution,
            frame_count,
        })
    }
}