1use crate::decode::{Decode, DecodeError};
2use crate::encode::Encode;
3
4#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd)]
14pub struct Version {
15 pub major: u8,
17 pub minor: u8,
19 pub build: u8,
21 pub beta: u8,
23}
24
25impl Encode for Version {
26 fn size(&self) -> usize {
27 4
28 }
29
30 fn encode(&self, data: &mut [u8]) {
31 data[0] = self.major;
32 data[1] = self.minor;
33 data[2] = self.build;
34 data[3] = self.beta;
35 }
36}
37
38impl Decode for Version {
39 fn decode(data: &mut &[u8]) -> Result<Self, DecodeError> {
40 let major = u8::decode(data)?;
41 let minor = u8::decode(data)?;
42 let build = u8::decode(data)?;
43 let beta = u8::decode(data)?;
44
45 Ok(Self {
46 major,
47 minor,
48 build,
49 beta,
50 })
51 }
52}