1use binary_util::interfaces::{Reader, Writer};
2use binary_util::io::{ByteReader, ByteWriter};
3
4pub(crate) const MAGIC: [u8; 16] = [
6 0x00, 0xff, 0xff, 0x0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfd, 0xfd, 0xfd, 0xfd, 0x12, 0x34, 0x56, 0x78,
7];
8
9#[derive(Debug, Clone)]
12pub struct Magic;
13
14impl Magic {
15 pub fn new() -> Self {
16 Self {}
17 }
18}
19
20impl Reader<Magic> for Magic {
21 fn read(buf: &mut ByteReader) -> Result<Magic, std::io::Error> {
22 let mut magic = [0u8; 16];
23 buf.read(&mut magic)?;
24
25 if magic != MAGIC {
26 return Err(std::io::Error::new(
27 std::io::ErrorKind::InvalidData,
28 "Invalid magic",
29 ));
30 }
31
32 Ok(Magic)
33 }
34}
35
36impl Writer for Magic {
37 fn write(&self, buf: &mut ByteWriter) -> Result<(), std::io::Error> {
38 buf.write(&MAGIC)?;
39 Ok(())
40 }
41}