This is an automated email from the ASF dual-hosted git repository. mgrigorov pushed a commit to branch branch-1.11 in repository https://gitbox.apache.org/repos/asf/avro.git
commit 76d1cc34cfd8196c2eadeb6b26339e6ce332d996 Author: Martin Grigorov <[email protected]> AuthorDate: Wed Jan 5 09:45:25 2022 +0200 AVRO-3245 Rust: Replace crc crate with crc32fast (#1388) Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> (cherry picked from commit 54f37e52cb373904c7529a74dee1275bffac457a) --- lang/rust/Cargo.toml | 4 ++-- lang/rust/src/codec.rs | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lang/rust/Cargo.toml b/lang/rust/Cargo.toml index 4501bf0..328e858 100644 --- a/lang/rust/Cargo.toml +++ b/lang/rust/Cargo.toml @@ -29,7 +29,7 @@ categories = ["encoding"] documentation = "https://docs.rs/avro-rs" [features] -snappy = ["crc", "snap"] +snappy = ["crc32fast", "snap"] zstandard = ["zstd"] bzip = ["bzip2"] @@ -53,7 +53,7 @@ harness = false [dependencies] byteorder = "1.4.3" bzip2 = { version = "0.4.3", optional = true } -crc = { version = "1.8.1", optional = true } +crc32fast = { version = "1.2.1", optional = true } digest = "0.9" libflate = "1.1.1" num-bigint = "0.4.2" diff --git a/lang/rust/src/codec.rs b/lang/rust/src/codec.rs index 84f0381..15992c1 100644 --- a/lang/rust/src/codec.rs +++ b/lang/rust/src/codec.rs @@ -26,6 +26,10 @@ use bzip2::{ read::{BzDecoder, BzEncoder}, Compression, }; +#[cfg(feature = "snappy")] +extern crate crc32fast; +#[cfg(feature = "snappy")] +use crc32fast::Hasher; /// The compression codec used to compress blocks. #[derive(Clone, Copy, Debug, PartialEq, EnumString, IntoStaticStr)] @@ -79,8 +83,10 @@ impl Codec { .compress(&stream[..], &mut encoded[..]) .map_err(Error::SnappyCompress)?; - let crc = crc::crc32::checksum_ieee(&stream[..]); - byteorder::BigEndian::write_u32(&mut encoded[compressed_size..], crc); + let mut hasher = Hasher::new(); + hasher.update(&stream[..]); + let checksum = hasher.finalize(); + byteorder::BigEndian::write_u32(&mut encoded[compressed_size..], checksum); encoded.truncate(compressed_size + 4); *stream = encoded; @@ -127,7 +133,9 @@ impl Codec { .map_err(Error::SnappyDecompress)?; let expected = byteorder::BigEndian::read_u32(&stream[stream.len() - 4..]); - let actual = crc::crc32::checksum_ieee(&decoded); + let mut hasher = Hasher::new(); + hasher.update(&decoded); + let actual = hasher.finalize(); if expected != actual { return Err(Error::SnappyCrc32 { expected, actual });
