1extern crate plain;
2use plain::Plain;
3
4use super::Error;
5
6#[repr(C)]
7#[derive(Debug, Clone, Default)]
8pub struct RiteBinaryHeader {
9 pub ident: [u8; 4],
10 pub major_version: [u8; 2],
11 pub minor_version: [u8; 2],
12 pub size: [u8; 4],
13 pub compiler_name: [u8; 4],
14 pub compiler_version: [u8; 4],
15}
16unsafe impl Plain for RiteBinaryHeader {}
17
18impl RiteBinaryHeader {
19 pub fn from_bytes(buf: &[u8]) -> Result<Self, Error> {
20 plain::from_bytes(buf).map_err(|_| Error::General).cloned()
21 }
22}
23
24#[repr(C)]
25#[derive(Debug, Clone, Default)]
26pub struct SectionMiscHeader {
27 pub ident: [u8; 4],
28 pub size: [u8; 4],
29}
30unsafe impl Plain for SectionMiscHeader {}
31
32impl SectionMiscHeader {
33 pub fn from_bytes(buf: &[u8]) -> Result<Self, Error> {
34 plain::from_bytes(buf).map_err(|_| Error::General).cloned()
35 }
36}
37
38#[repr(C)]
39#[derive(Debug, Clone, Default)]
40pub struct SectionIrepHeader {
41 pub ident: [u8; 4],
42 pub size: [u8; 4],
43
44 pub rite_version: [u8; 4],
45}
46unsafe impl Plain for SectionIrepHeader {}
47
48impl SectionIrepHeader {
49 pub fn from_bytes(buf: &[u8]) -> Result<Self, Error> {
50 plain::from_bytes(buf).map_err(|_| Error::General).cloned()
51 }
52}
53
54#[repr(C)]
55#[derive(Debug, Clone, Default)]
56pub struct IrepRecord {
57 pub size: [u8; 4],
58 pub nlocals: [u8; 2],
59 pub nregs: [u8; 2],
60 pub rlen: [u8; 2],
61 pub clen: [u8; 2],
62 pub ilen: [u8; 4],
63}
64
65unsafe impl Plain for IrepRecord {}
66
67impl IrepRecord {
68 pub fn from_bytes(buf: &[u8]) -> Result<Self, Error> {
69 plain::from_bytes(buf).map_err(|_| Error::General).cloned()
70 }
71}
72
73#[repr(C)]
74#[derive(Debug, Clone, Default)]
75pub struct IrepCatchHandler {
76 pub type_: u8,
77 pub begin: [u8; 4],
78 pub end: [u8; 4],
79 pub target: [u8; 4],
80}
81
82unsafe impl Plain for IrepCatchHandler {}
83
84impl IrepCatchHandler {
85 pub fn from_bytes(buf: &[u8]) -> Result<Self, Error> {
86 plain::from_bytes(buf).map_err(|_| Error::General).cloned()
87 }
88}