Skip to content

Commit

Permalink
Replace software implementation of castagnoli crc32 with hardware imp…
Browse files Browse the repository at this point in the history
…lementation (#32)
  • Loading branch information
rukai authored Sep 16, 2023
1 parent 8902908 commit 974738a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ flate2 = "1.0.20"
string = "0.3.0"
derive_builder = "0.12.0"
paste = "1.0.7"
crc32c = "0.6.4"
9 changes: 4 additions & 5 deletions src/records.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,16 @@
//! ```
use bytes::Bytes;
use indexmap::IndexMap;
use crc32c::crc32c;
use log::{error};
use crc::{CRC_32_CKSUM, CRC_32_ISCSI, Crc};
use crc::{CRC_32_CKSUM, Crc};
use string::TryFrom;

use crate::protocol::{Encoder, Decoder, EncodeError, DecodeError, StrBytes, types, buf::{ByteBuf, ByteBufMut, gap}};

use super::compression::{self as cmpr, Compressor, Decompressor};
use std::cmp::Ordering;

/// CRC-32C (Castagnoli) cyclic redundancy check
pub const CASTAGNOLI: Crc<u32> = Crc::<u32>::new(&CRC_32_ISCSI);
/// IEEE (checksum) cyclic redundancy check.
pub const IEEE: Crc<u32> = Crc::<u32>::new(&CRC_32_CKSUM);

Expand Down Expand Up @@ -354,7 +353,7 @@ impl RecordBatchEncoder {
buf.fill_typed_gap(size_gap, batch_size as i32);

// Fill CRC gap
let crc = CASTAGNOLI.checksum(buf.range(content_start..batch_end));
let crc = crc32c(buf.range(content_start..batch_end));
buf.fill_typed_gap(crc_gap, crc);

Ok(true)
Expand Down Expand Up @@ -433,7 +432,7 @@ impl RecordBatchDecoder {

// CRC
let supplied_crc: u32 = types::UInt32.decode(buf)?;
let actual_crc = CASTAGNOLI.checksum(buf);
let actual_crc = crc32c(buf);

if supplied_crc != actual_crc {
error!("Cyclic redundancy check failed ({} != {})", supplied_crc, actual_crc);
Expand Down

0 comments on commit 974738a

Please sign in to comment.