floaout/oao/
id.rs

1use crate::io::{ReadExt, WriteExt};
2use mycrc::CRC;
3use std::io::{Read, Result, Write};
4
5#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
6pub struct OaoID {
7    pub id: u128,
8}
9
10impl OaoID {
11    pub const fn new(id: u128) -> Self {
12        Self { id }
13    }
14
15    pub fn read<R: Read>(reader: &mut R) -> Result<Self> {
16        Ok(Self {
17            id: reader.read_le()?,
18        })
19    }
20    pub fn read_and_calc_bytes<R: Read>(reader: &mut R, crc: &mut CRC<u32>) -> Result<Self> {
21        Ok(Self {
22            id: reader.read_le_and_calc_bytes(crc)?,
23        })
24    }
25
26    pub fn write<W: Write>(self, writer: &mut W) -> Result<()> {
27        writer.write_le(self.id)
28    }
29    pub fn write_and_calc_bytes<W: Write>(self, writer: &mut W, crc: &mut CRC<u32>) -> Result<()> {
30        writer.write_le_and_calc_bytes(self.id, crc)
31    }
32}