Skip to content

Commit df0116e

Browse files
fix: Clang-Tidy include and const-correctness in PacketDeduplicator
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 568e005 commit df0116e

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/nuclearnet/PacketDeduplicator.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
#include "PacketDeduplicator.hpp"
2424

25+
#include <cstdint>
26+
2527
namespace NUClear {
2628
namespace network {
2729

@@ -32,15 +34,15 @@ namespace network {
3234
}
3335

3436
// Check how far ahead of newest_seen this packet is
35-
uint16_t forward_distance = packet_id - newest_seen;
37+
const uint16_t forward_distance = packet_id - newest_seen;
3638

3739
// If it's ahead of newest_seen (newer), it can't be a duplicate
3840
if (forward_distance != 0 && forward_distance < 0x8000U) {
3941
return false;
4042
}
4143

4244
// It's at or behind newest_seen — check the distance backward
43-
uint16_t distance = newest_seen - packet_id;
45+
const uint16_t distance = newest_seen - packet_id;
4446

4547
// If distance >= WINDOW_SIZE, it's too old — treat as duplicate (already processed or lost)
4648
if (distance >= WINDOW_SIZE) {
@@ -62,7 +64,7 @@ namespace network {
6264
}
6365

6466
// Calculate how far ahead of newest_seen this packet is (signed interpretation of unsigned diff)
65-
uint16_t forward_distance = packet_id - newest_seen;
67+
const uint16_t forward_distance = packet_id - newest_seen;
6668

6769
// If the high bit is set, it's actually behind us (wrapped subtraction gave a large positive number)
6870
// We use half the uint16_t range as the threshold for "ahead" vs "behind"
@@ -85,7 +87,7 @@ namespace network {
8587
}
8688
else {
8789
// This packet is OLDER than our current newest (behind us)
88-
uint16_t distance = newest_seen - packet_id;
90+
const uint16_t distance = newest_seen - packet_id;
8991
if (distance < WINDOW_SIZE) {
9092
window.set(distance); // Mark it as seen in the appropriate position
9193
}

0 commit comments

Comments
 (0)