Skip to content

Commit

Permalink
[ISSUE #520] 🐛Fix count_inner_msg_num method of message decoder mode (#…
Browse files Browse the repository at this point in the history
…521)

pdated count_inner_msg_num to check for bytes remaining instead of emptiness; adjusted tests to reflect new logic and expected message counts
  • Loading branch information
dream-cloud-fly authored Jun 13, 2024
1 parent 7b2276b commit fb2cde2
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions rocketmq-common/src/common/message/message_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ pub fn count_inner_msg_num(bytes: Option<Bytes>) -> u32 {
None => 0,
Some(mut bytes) => {
let mut count = 0;
while !bytes.is_empty() {
let size = bytes.get_i32();
while bytes.has_remaining() {
let size = bytes.slice(0..4).get_i32();
if size as usize > bytes.len() {
break;
}
Expand All @@ -308,17 +308,17 @@ mod tests {
#[test]
fn count_inner_msg_num_counts_correctly_for_multiple_messages() {
let mut bytes = BytesMut::new();
bytes.put_i32(4);
bytes.put_i32(8);
bytes.put_slice(&[0, 0, 0, 0]);
bytes.put_i32(4);
bytes.put_i32(8);
bytes.put_slice(&[0, 0, 0, 0]);
assert_eq!(count_inner_msg_num(Some(bytes.freeze())), 2);
}

#[test]
fn count_inner_msg_num_counts_correctly_for_single_message() {
let mut bytes = BytesMut::new();
bytes.put_i32(4);
bytes.put_i32(8);
bytes.put_slice(&[0, 0, 0, 0]);
assert_eq!(count_inner_msg_num(Some(bytes.freeze())), 1);
}
Expand All @@ -333,6 +333,6 @@ mod tests {
fn count_inner_msg_num_ignores_incomplete_messages() {
let mut bytes = BytesMut::new();
bytes.put_i32(4);
assert_eq!(count_inner_msg_num(Some(bytes.freeze())), 0);
assert_eq!(count_inner_msg_num(Some(bytes.freeze())), 1);
}
}

0 comments on commit fb2cde2

Please sign in to comment.