Skip to content

feat(lazer-protocol): Add fixed rate 1ms #2303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lazer/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lazer/sdk/rust/protocol/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pyth-lazer-protocol"
version = "0.3.2"
version = "0.3.3"
edition = "2021"
description = "Pyth Lazer SDK - protocol types."
license = "Apache-2.0"
Expand Down
6 changes: 4 additions & 2 deletions lazer/sdk/rust/protocol/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,15 @@ mod channel_ids {
pub const REAL_TIME: ChannelId = ChannelId(1);
pub const FIXED_RATE_50: ChannelId = ChannelId(2);
pub const FIXED_RATE_200: ChannelId = ChannelId(3);
pub const FIXED_RATE_1: ChannelId = ChannelId(4);
}

impl Channel {
pub fn id(&self) -> ChannelId {
match self {
Channel::RealTime => channel_ids::REAL_TIME,
Channel::FixedRate(fixed_rate) => match fixed_rate.value_ms() {
1 => channel_ids::FIXED_RATE_1,
50 => channel_ids::FIXED_RATE_50,
200 => channel_ids::FIXED_RATE_200,
_ => panic!("unknown channel: {self:?}"),
Expand Down Expand Up @@ -242,7 +244,7 @@ impl FixedRate {
// - Values are sorted.
// - 1 second contains a whole number of each interval.
// - all intervals are divisable by the smallest interval.
pub const ALL: [Self; 2] = [Self { ms: 50 }, Self { ms: 200 }];
pub const ALL: [Self; 3] = [Self { ms: 1 }, Self { ms: 50 }, Self { ms: 200 }];
pub const MIN: Self = Self::ALL[0];

pub fn from_ms(value: u32) -> Option<Self> {
Expand Down Expand Up @@ -270,7 +272,7 @@ fn fixed_rate_values() {
"1 s must contain whole number of intervals"
);
assert!(
value.ms % FixedRate::MIN.ms == 0,
value.value_us() % FixedRate::MIN.value_us() == 0,
"the interval's borders must be a subset of the minimal interval's borders"
);
}
Expand Down
Loading