mirror of
https://github.com/lifegpc/msg-tool.git
synced 2026-06-24 04:37:15 +08:00
Add document
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user