From 8ca219c6b0d5448fd4529713ccd093e89de4e252 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Wed, 7 Dec 2022 17:55:27 +0100 Subject: refactor --- evc/src/format/header.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 evc/src/format/header.rs (limited to 'evc/src/format/header.rs') diff --git a/evc/src/format/header.rs b/evc/src/format/header.rs new file mode 100644 index 0000000..371b4ba --- /dev/null +++ b/evc/src/format/header.rs @@ -0,0 +1,29 @@ +use crate::{ + helpers::vector::Vec2, + format::ser::{Ser, Sink, Source}, +}; + +#[derive(Debug, Clone, PartialEq, Copy)] +pub struct Header { + pub resolution: Vec2, + 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 { + assert_eq!(source.get::<[u8; 4]>()?, MAGIC); + let (resolution, frame_count) = source.get()?; + Ok(Self { + resolution, + frame_count, + }) + } +} -- cgit v1.2.3-70-g09d2