Commit 8e534c01 authored by Guy Watson's avatar Guy Watson
Browse files

Add wasm module to handle crc computations

parent dbac9c26
[build]
target = "wasm32-unknown-unknown"
[package]
name = "wasm-crc-lib"
version = "0.1.0"
edition = "2021"
[lib]
name = "crc_lib"
crate-type = ["cdylib"]
path = "src/crc_lib.rs"
test = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
crc = "1.8.1"
lazy_static = "1.4.0"
structopt = "0.3.25"
// This library contains the core of the crc machinery: namely, add_to_crc and get_crc_val
use crc::{crc32, Hasher32};
use std::sync::Mutex;
#[macro_use]
extern crate lazy_static;
lazy_static! {
static ref CRC_VAL: Mutex<crc32::Digest> = Mutex::new(crc32::Digest::new(crc32::IEEE));
}
#[no_mangle]
pub fn add_to_crc(new_val : u32) {
CRC_VAL.lock().unwrap().write(&new_val.to_le_bytes());
}
#[no_mangle]
pub fn get_crc_val() -> u32 {
return CRC_VAL.lock().unwrap().sum32();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment