pub struct Chksum(/* private fields */);Expand description
A 31-bit checksum with validity marker
The checksum is computed using the DJB2 hash algorithm and masked to 31 bits. The most significant bit (bit 31) must be zero for a valid checksum, allowing quick detection of erased/uninitialized flash memory (which reads as 0xFF).
Implementations§
Source§impl Chksum
impl Chksum
Sourcepub const fn zero() -> Self
pub const fn zero() -> Self
Create a zero checksum
This is used as the initial previous checksum for the first savegame.
Sourcepub const fn hash(prev: Chksum, data: &[u8]) -> Self
pub const fn hash(prev: Chksum, data: &[u8]) -> Self
Compute a checksum for the given data, chained with a previous checksum
Uses DJB2 hash algorithm. The previous checksum is included in the hash to create a chain of checksums linking savegames together.
§Arguments
prev- The checksum of the previous savegamedata- The data to hash
Sourcepub const fn is_valid(&self) -> bool
pub const fn is_valid(&self) -> bool
Check if this checksum has a valid format
A valid checksum has its most significant bit set to zero. This allows quick detection of uninitialized flash (0xFF) or corrupted data.
Sourcepub const fn from_bytes(bytes: [u8; 4]) -> Self
pub const fn from_bytes(bytes: [u8; 4]) -> Self
Parse a checksum from big-endian bytes