From 5002d0df81f74418665e4e99179ba56d8e78cbe1 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 6 Dec 2022 08:16:09 +0100 Subject: more codde --- evc/src/header.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'evc/src/header.rs') diff --git a/evc/src/header.rs b/evc/src/header.rs index 923e8ff..5244ce5 100644 --- a/evc/src/header.rs +++ b/evc/src/header.rs @@ -1,20 +1,22 @@ use crate::ser::{Ser, Sink, Source}; -#[derive(Debug, Clone)] +#[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) -> std::io::Result<()> { - sink.put([0x5eu8, 0xb1u8, 0xc3u8, 0x08u8])?; + 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) -> std::io::Result { - source.get::<[u8; 4]>()?; + 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, -- cgit v1.2.3-70-g09d2