vex_cdc/
version.rs

1use crate::decode::{Decode, DecodeError};
2use crate::encode::Encode;
3
4/// A VEXos firmware version.
5///
6/// This type represents a version identifier for VEXos firmware. VEXos is
7/// versioned using a slightly modified [semantic versioning] scheme.
8///
9/// [semantic versioning]: https://semver.org/
10///
11/// This type implements `PartialOrd`, meaning it can be compared to other
12/// instances of itself.
13#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd)]
14pub struct Version {
15    /// The major version
16    pub major: u8,
17    /// The minor version
18    pub minor: u8,
19    /// The build version
20    pub build: u8,
21    /// The beta version
22    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}