1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use bytes::{Buf, BufMut};
use error::Error;
use num_traits::FromPrimitive;
use std::io::Cursor;

#[allow(non_camel_case_types)]
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub struct boot {
    pub version: u32,
}

impl From<&[u8]> for boot {
    fn from(data: &[u8]) -> boot {
        let mut cursor = Cursor::new(data);
        boot {
            version: cursor.get_u32_le(),
        }
    }
}

impl Into<Vec<u8>> for boot {
    fn into(self) -> Vec<u8> {
        let mut bytes = Vec::new();
        bytes.put_u32_le(self.version);
        bytes
    }
}

#[allow(non_camel_case_types)]
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub struct boot_failure {
    pub reason: Error,
}

impl From<&[u8]> for boot_failure {
    fn from(data: &[u8]) -> boot_failure {
        let mut cursor = Cursor::new(data);
        boot_failure {
            reason: FromPrimitive::from_u16(cursor.get_u16_le()).unwrap(),
        }
    }
}

impl Into<Vec<u8>> for boot_failure {
    fn into(self) -> Vec<u8> {
        let mut bytes = Vec::new();
        bytes.put_u16_le(self.reason.clone() as u16);
        bytes
    }
}