Skip to content

Commit

Permalink
Merge pull request #14 from qdrant/dependabot/cargo/crc-3
Browse files Browse the repository at this point in the history
Update crc requirement from 1 to 3
  • Loading branch information
agourlay authored Aug 1, 2022
2 parents 864eb51 + 67d79f6 commit 72e858a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["Dan Burkert <[email protected]>", "Andrey Vasnetsov <andrey@vasnets

[dependencies]
byteorder = "1.4"
crc = "1"
crc = "3"
eventual = "0.1.4"
fs2 = "0.4"
log = "0.4"
Expand Down
24 changes: 9 additions & 15 deletions src/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::ptr;
use std::thread;

use byteorder::{ByteOrder, LittleEndian};
use crc::crc32;
use crc::{Crc, CRC_32_ISCSI};
use eventual::Future;
use fs2::FileExt;
use log;
Expand All @@ -26,7 +26,7 @@ const HEADER_LEN: usize = 8;
/// The length of a CRC value.
const CRC_LEN: usize = 4;

type Crc = u32;
pub const CASTAGNOLI: Crc<u32> = Crc::<u32>::new(&CRC_32_ISCSI);

pub struct Entry {
view: MmapViewSync,
Expand Down Expand Up @@ -107,7 +107,7 @@ pub struct Segment {
/// Index of entry offset and lengths.
index: Vec<(usize, usize)>,
/// The crc of the last appended entry.
crc: Crc,
crc: u32,
/// Offset of last flush.
flush_offset: usize,
}
Expand Down Expand Up @@ -222,12 +222,9 @@ impl Segment {
if offset + HEADER_LEN + padded_len + CRC_LEN > capacity {
break;
}

let entry_crc = crc32::update(
crc,
&crc32::CASTAGNOLI_TABLE,
&segment[offset..offset + HEADER_LEN + padded_len],
);
let mut digest = CASTAGNOLI.digest_with_initial(crc);
digest.update(&segment[offset..offset + HEADER_LEN + padded_len]);
let entry_crc = digest.finalize();
if entry_crc != LittleEndian::read_u32(&segment[offset + HEADER_LEN + padded_len..])
{
break;
Expand Down Expand Up @@ -300,6 +297,7 @@ impl Segment {
let offset = self.size();

let mut crc = self.crc;
let mut digest = CASTAGNOLI.digest_with_initial(crc);

LittleEndian::write_u64(&mut self.as_mut_slice()[offset..], entry.len() as u64);
copy_memory(
Expand All @@ -314,12 +312,8 @@ impl Segment {
&mut self.as_mut_slice()[offset + HEADER_LEN + entry.len()..],
);
}

crc = crc32::update(
crc,
&crc32::CASTAGNOLI_TABLE,
&self.as_slice()[offset..offset + HEADER_LEN + padded_len],
);
digest.update(&self.as_slice()[offset..offset + HEADER_LEN + padded_len]);
crc = digest.finalize();

LittleEndian::write_u32(
&mut self.as_mut_slice()[offset + HEADER_LEN + padded_len..],
Expand Down

0 comments on commit 72e858a

Please sign in to comment.