Skip to content

Commit

Permalink
Make PriorityRange inclusive
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzypixelz committed Sep 5, 2024
1 parent 16b5b09 commit 83ea7f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
15 changes: 7 additions & 8 deletions DEFAULT_CONFIG.json5
Original file line number Diff line number Diff line change
Expand Up @@ -326,17 +326,16 @@
},
},
link: {
/// An optional whitelist of protocols to be used for accepting and opening sessions.
/// If not configured, all the supported protocols are automatically whitelisted.
/// The supported protocols are: ["tcp" , "udp", "tls", "quic", "ws", "unixsock-stream", "vsock"]
/// For example, to only enable "tls" and "quic":
/// protocols: ["tls", "quic"],
/// An optional whitelist of protocols to be used for accepting and opening sessions. If not
/// configured, all the supported protocols are automatically whitelisted. The supported
/// protocols are: ["tcp" , "udp", "tls", "quic", "ws", "unixsock-stream", "vsock"] For
/// example, to only enable "tls" and "quic": protocols: ["tls", "quic"],
///
/// ## Endpoint metadata
///
/// **priorities**: a Rust-style half-open range (e.g. `2..4` signifies priorities 2 and 3).
/// This value is used to select the link used for transmission based on the Priority of the
/// message in question.
/// **priorities**: a range bounded inclusively below and above (e.g. `2..4` signifies
/// priorities 2, 3 and 4). This value is used to select the link used for transmission based
/// on the Priority of the message in question.
///
/// **reliability**: either "best_effort" or "reliable". This value is used to select the link
/// used for transmission based on the Reliability of the message in question.
Expand Down
7 changes: 4 additions & 3 deletions commons/zenoh-protocol/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,15 @@ pub enum Priority {
}

#[derive(Debug, Default, Copy, Clone, Eq, Hash, PartialEq, Serialize)]
/// A `u8` range bounded inclusively below and above.
pub struct PriorityRange {
pub start: u8,
pub end: u8,
}

impl PriorityRange {
pub fn new(start: u8, end: u8) -> ZResult<Self> {
if start >= end || start < Priority::MAX as u8 || end > Priority::MIN as u8 + 1 {
if start > end || start < Priority::MAX as u8 || end > Priority::MIN as u8 {
bail!("Invalid priority range: {start}..{end}")
};

Expand All @@ -327,7 +328,7 @@ impl PriorityRange {

/// Returns `true` if `priority` is a member of `self`.
pub fn contains(&self, priority: Priority) -> bool {
self.start <= (priority as u8) && (priority as u8) < self.end
self.start <= (priority as u8) && (priority as u8) <= self.end
}

/// Returns `true` if `self` is a superset of `other`.
Expand All @@ -336,7 +337,7 @@ impl PriorityRange {
}

pub fn len(&self) -> usize {
(self.end - self.start) as usize
(self.end - self.start + 1) as usize
}

pub fn is_empty(&self) -> bool {
Expand Down

0 comments on commit 83ea7f6

Please sign in to comment.