From 96d2895c74bdf01ac451452abe10095ddf939b64 Mon Sep 17 00:00:00 2001 From: Juhana Helovuo Date: Wed, 11 Oct 2023 08:50:26 +0300 Subject: [PATCH] Additional SequenceNumber members for RPC/ROS2 to avoid duplicate implementation in ros2-client. --- src/structure/sequence_number.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/structure/sequence_number.rs b/src/structure/sequence_number.rs index 123f3c03..c4067ff1 100644 --- a/src/structure/sequence_number.rs +++ b/src/structure/sequence_number.rs @@ -45,7 +45,23 @@ impl SequenceNumber { } pub const fn plus_1(&self) -> Self { - SequenceNumber(self.0 + 1) + SequenceNumber( self.0 + 1 ) + } + + pub fn next(&self) -> SequenceNumber { + self.plus_1() + } + + pub fn from_high_low(high: i32, low: u32) -> Self { + Self( ((high as i64) << 32) + (low as i64) ) + } + + pub fn high(&self) -> i32 { + (self.0 >> 32) as i32 + } + + pub fn low(&self) -> u32 { + (self.0 & 0xFFFF_FFFF) as u32 } } @@ -79,6 +95,7 @@ impl From for i64 { } } + // --------------------------------------- #[derive(Clone, Copy, Debug)] @@ -403,7 +420,7 @@ where end }; // sanity ok. Now do the actual work. - let num_bits = i64::from(end - base + N::from(1)); + let num_bits = i64::from( end - base + N::from(1) ); let mut sns = Self::new(base, num_bits as u32); for s in set.iter().filter(|s| base <= **s && **s <= end) { sns.insert(*s);