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