Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
conorbros committed Mar 30, 2023
1 parent b4fe9be commit fcb0470
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions shotover/src/codec/cassandra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,20 @@ impl CassandraDecoder {
Compression::None => {
let mut frame_bytes = src.split_to(frame_len);

let header = if frame_bytes.len() >= 8 {
i64::from_le_bytes(frame_bytes[..8].try_into().unwrap()) & 0xffffffffffff
} else {
let mut header = 0;
for (i, byte) in frame_bytes[..UNCOMPRESSED_FRAME_HEADER_LENGTH]
.iter()
.enumerate()
{
header |= (*byte as i64) << (8 * i as i64);
}

header
};
let header =
// if frame_bytes.len() >= 8 {
i64::from_le_bytes(frame_bytes[..8].try_into().unwrap()) & 0xffffffffffff;
// } else {
// let mut header = 0;
// for (i, byte) in frame_bytes[..UNCOMPRESSED_FRAME_HEADER_LENGTH]
// .iter()
// .enumerate()
// {
// header |= (*byte as i64) << (8 * i as i64);
// }

// header
// };

let header_crc24 = ((header >> 24) & 0xffffff) as i32;
let computed_crc = cassandra_protocol::crc::crc24(&header.to_le_bytes()[..3]);
Expand Down Expand Up @@ -236,18 +237,18 @@ impl CassandraDecoder {

let mut envelopes: Vec<Message> = vec![];

loop {
if payload.len() < ENVELOPE_HEADER_LEN {
break;
}

while !payload.is_empty() {
let body_len =
i32::from_be_bytes(payload[5..9].try_into().unwrap()) as usize;

let envelope_len = ENVELOPE_HEADER_LEN + body_len;

if envelope_len > payload.len() {
break;
return Err(anyhow!(format!(
"envelope length {} is longer than payload length {}",
envelope_len,
payload.len()
),));
}

let envelope = payload.split_to(envelope_len);
Expand Down

0 comments on commit fcb0470

Please sign in to comment.