1use std::io;
2use std::io::Read;
3
4pub struct Sig {
5 pub raw: [u8; 11],
6}
7
8impl Sig {
9 pub fn from_rdr_no_validation<R>(rdr: &mut R) -> Result<Self, io::Error>
10 where
11 R: Read,
12 {
13 let mut s = Self { raw: [0; 11] };
14 rdr.read_exact(&mut s.raw)?;
15 Ok(s)
16 }
17}
18
19pub struct Flags {
21 pub raw: u32,
22}
23
24impl Flags {
25 pub fn from_rdr_no_validation<R>(rdr: &mut R) -> Result<Self, io::Error>
26 where
27 R: Read,
28 {
29 let mut buf: [u8; 4] = [0; 4];
30 rdr.read_exact(&mut buf)?;
31 Ok(Self {
32 raw: u32::from_be_bytes(buf),
33 })
34 }
35}
36
37pub struct Ext {
39 pub raw: u32,
40}
41
42impl Ext {
43 pub fn from_rdr_no_validation<R>(rdr: &mut R) -> Result<Self, io::Error>
44 where
45 R: Read,
46 {
47 let mut buf: [u8; 4] = [0; 4];
48 rdr.read_exact(&mut buf)?;
49 Ok(Self {
50 raw: u32::from_be_bytes(buf),
51 })
52 }
53}
54
55pub struct Header {
56 pub sig: Sig,
57 pub flags: Flags,
58 pub ext: Ext,
59}
60
61impl Header {
62 pub fn from_rdr_no_validation<R>(rdr: &mut R) -> Result<Self, io::Error>
63 where
64 R: Read,
65 {
66 let sig: Sig = Sig::from_rdr_no_validation(rdr)?;
67 let flags: Flags = Flags::from_rdr_no_validation(rdr)?;
68 let ext: Ext = Ext::from_rdr_no_validation(rdr)?;
69 Ok(Self { sig, flags, ext })
70 }
71}