Skip to content

Commit

Permalink
fix(rust): change sequence number type of message id from i16 to i32
Browse files Browse the repository at this point in the history
Signed-off-by: SSpirits <admin@lv5.moe>
  • Loading branch information
ShadowySpirits committed Jul 11, 2023
1 parent 29d332b commit dc813b2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ keywords = ["rocketmq", "api", "client", "sdk", "grpc"]
[dependencies]
tokio = { version = "1", features = ["full"] }
tokio-rustls = {version = "0.24.0", features = ["default", "dangerous_configuration"] }
tokio-stream="0.1.12"
async-trait = "0.1.68"
lazy_static = "1.4"
tonic = {version = "0.9.0", features = ["tls", "default", "channel", "tls-roots"]}
Expand All @@ -60,7 +61,6 @@ mac_address = "1.1.4"
hex = "0.4.3"
time = "0.3"
once_cell = "1.9.0"
tokio-stream="0.1.12"

mockall = "0.11.4"
mockall_double= "0.3.0"
Expand Down
5 changes: 3 additions & 2 deletions rust/src/model/message_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub(crate) static UNIQ_ID_GENERATOR: Lazy<Mutex<UniqueIdGenerator>> = Lazy::new(
});

pub struct UniqueIdGenerator {
counter: i16,
counter: i32,
prefix: String,
start_timestamp: i64,
next_timestamp: i64,
Expand Down Expand Up @@ -122,7 +122,7 @@ impl UniqueIdGenerator {
((OffsetDateTime::now_utc().unix_timestamp() - self.start_timestamp) * 1000) as i32,
)
.unwrap();
buf.write_i16::<BigEndian>(self.counter).unwrap();
buf.write_i32::<BigEndian>(self.counter).unwrap();
self.prefix.clone() + &hex::encode(buf)
}
}
Expand All @@ -134,6 +134,7 @@ mod test {
use super::UNIQ_ID_GENERATOR;
for i in 0..10 {
let uid = UNIQ_ID_GENERATOR.lock().next_id();
assert_eq!(uid.len(), 34);
println!("i: {}, uid: {}", i, uid);
}
}
Expand Down

0 comments on commit dc813b2

Please sign in to comment.