Add document

This commit is contained in:
2025-08-10 16:58:44 +08:00
parent f602ddb4b5
commit cfc1dbf507
43 changed files with 516 additions and 13 deletions

View File

@@ -1,3 +1,4 @@
//! Crc32 Utility
use lazy_static::lazy_static;
fn get_crc32normal_table() -> [u32; 256] {
@@ -17,18 +18,22 @@ fn get_crc32normal_table() -> [u32; 256] {
}
lazy_static! {
/// CRC32 Normal Table
pub static ref CRC32NORMAL_TABLE: [u32; 256] = get_crc32normal_table();
}
/// A CRC32 Normal implementation.
pub struct Crc32Normal {
crc: u32,
}
impl Crc32Normal {
/// Creates a new Crc32Normal instance with an initial CRC value.
pub fn new() -> Self {
Crc32Normal { crc: 0xFFFFFFFF }
}
/// Creates a new Crc32Normal instance with a specified initial CRC value.
pub fn update_crc(init_crc: u32, data: &[u8]) -> u32 {
let mut crc = init_crc;
for &byte in data {
@@ -38,10 +43,12 @@ impl Crc32Normal {
crc ^ 0xFFFFFFFF
}
/// Updates the CRC value with new data.
pub fn update(&mut self, data: &[u8]) {
self.crc = Self::update_crc(self.crc, data);
}
/// Returns the current CRC value.
pub fn value(&self) -> u32 {
self.crc
}