Skip to content

Commit

Permalink
Define DEFAULT consts
Browse files Browse the repository at this point in the history
  • Loading branch information
Mallets committed Feb 9, 2024
1 parent 3c79d5e commit 89555f1
Show file tree
Hide file tree
Showing 21 changed files with 99 additions and 64 deletions.
6 changes: 3 additions & 3 deletions commons/zenoh-codec/benches/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let codec = Zenoh080::new();

let frame = FrameHeader {
reliability: Reliability::default(),
reliability: Reliability::DEFAULT,
sn: TransportSn::MIN,
ext_qos: zenoh_protocol::transport::frame::ext::QoSType::default(),
};
Expand Down Expand Up @@ -121,7 +121,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let codec = Zenoh080::new();

let frame = FrameHeader {
reliability: Reliability::default(),
reliability: Reliability::DEFAULT,
sn: TransportSn::MIN,
ext_qos: zenoh_protocol::transport::frame::ext::QoSType::default(),
};
Expand Down Expand Up @@ -162,7 +162,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let codec = Zenoh080::new();

let frame = FrameHeader {
reliability: Reliability::default(),
reliability: Reliability::DEFAULT,
sn: TransportSn::MIN,
ext_qos: zenoh_protocol::transport::frame::ext::QoSType::default(),
};
Expand Down
2 changes: 1 addition & 1 deletion commons/zenoh-codec/src/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ where
type Error = DidntRead;

fn read(self, reader: &mut R) -> Result<NetworkMessage, Self::Error> {
let codec = Zenoh080Reliability::new(Reliability::default());
let codec = Zenoh080Reliability::new(Reliability::DEFAULT);
codec.read(reader)
}
}
Expand Down
35 changes: 34 additions & 1 deletion commons/zenoh-protocol/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ pub enum Reliability {
}

impl Reliability {
pub const DEFAULT: Self = Self::BestEffort;

#[cfg(feature = "test")]
pub fn rand() -> Self {
use rand::Rng;
Expand All @@ -376,6 +378,13 @@ pub struct Channel {
pub reliability: Reliability,
}

impl Channel {
pub const DEFAULT: Self = Self {
priority: Priority::DEFAULT,
reliability: Reliability::DEFAULT,
};
}

/// The kind of congestion control.
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
#[repr(u8)]
Expand All @@ -385,6 +394,10 @@ pub enum CongestionControl {
Block = 1,
}

impl CongestionControl {
pub const DEFAULT: Self = Self::Drop;
}

/// The subscription mode.
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
#[repr(u8)]
Expand All @@ -394,20 +407,31 @@ pub enum SubMode {
Pull = 1,
}

impl SubMode {
pub const DEFAULT: Self = Self::Push;
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct SubInfo {
pub reliability: Reliability,
pub mode: SubMode,
}

impl SubInfo {
pub const DEFAULT: Self = Self {
reliability: Reliability::DEFAULT,
mode: SubMode::DEFAULT,
};
}

#[derive(Debug, Default, Clone, PartialEq, Eq, Hash)]
pub struct QueryableInfo {
pub complete: u64, // Default 0: incomplete
pub distance: u64, // Default 0: no distance
}

/// The kind of consolidation.
#[derive(Debug, Clone, PartialEq, Eq, Copy)]
#[derive(Debug, Default, Clone, PartialEq, Eq, Copy)]
pub enum ConsolidationMode {
/// No consolidation applied: multiple samples may be received for the same key-timestamp.
None,
Expand All @@ -420,9 +444,14 @@ pub enum ConsolidationMode {
/// been observed with the same key.
Monotonic,
/// Holds back samples to only send the set of samples that had the highest timestamp for their key.
#[default]
Latest,
}

impl ConsolidationMode {
pub const DEFAULT: Self = Self::Latest;
}

/// The `zenoh::queryable::Queryable`s that should be target of a `zenoh::Session::get()`.
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub enum QueryTarget {
Expand All @@ -433,3 +462,7 @@ pub enum QueryTarget {
#[cfg(feature = "complete_n")]
Complete(u64),
}

impl QueryTarget {
pub const DEFAULT: Self = Self::BestMatching;
}
2 changes: 1 addition & 1 deletion commons/zenoh-protocol/src/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ pub mod ext {

impl<const ID: u8> Default for QoSType<{ ID }> {
fn default() -> Self {
Self::new(Priority::default(), CongestionControl::default(), false)
Self::new(Priority::DEFAULT, CongestionControl::default(), false)
}
}

Expand Down
2 changes: 1 addition & 1 deletion commons/zenoh-protocol/src/transport/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ pub mod ext {

impl<const ID: u8> Default for QoSType<{ ID }> {
fn default() -> Self {
Self::new(Priority::default())
Self::new(Priority::DEFAULT)
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_pub_thr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn main() {
env_logger::init();
let args = Args::parse();

let mut prio = Priority::default();
let mut prio = Priority::DEFAULT;
if let Some(p) = args.priority {
prio = p.try_into().unwrap();
}
Expand Down
2 changes: 1 addition & 1 deletion io/zenoh-transport/src/common/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ mod tests {
let tmsg: TransportMessage = KeepAlive.into();
let nmsg: NetworkMessage = Push {
wire_expr: WireExpr::empty(),
ext_qos: ext::QoSType::new(Priority::default(), CongestionControl::Block, false),
ext_qos: ext::QoSType::new(Priority::DEFAULT, CongestionControl::Block, false),
ext_tstamp: None,
ext_nodeid: ext::NodeIdType::default(),
payload: PushBody::Put(Put {
Expand Down
4 changes: 2 additions & 2 deletions io/zenoh-transport/src/common/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ impl TransmissionPipeline {
let mut stage_in = vec![];
let mut stage_out = vec![];

let default_queue_size = [config.queue_size[Priority::default() as usize]];
let default_queue_size = [config.queue_size[Priority::DEFAULT as usize]];
let size_iter = if priority.len() == 1 {
default_queue_size.iter()
} else {
Expand Down Expand Up @@ -602,7 +602,7 @@ impl TransmissionPipelineProducer {
let priority = msg.priority();
(priority as usize, priority)
} else {
(0, Priority::default())
(0, Priority::DEFAULT)
};
// Lock the channel. We are the only one that will be writing on it.
let mut queue = zlock!(self.stage_in[idx]);
Expand Down
4 changes: 2 additions & 2 deletions io/zenoh-transport/src/multicast/rx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl TransportMulticastInner {
let priority = ext_qos.priority();
let c = if self.is_qos() {
&peer.priority_rx[priority as usize]
} else if priority == Priority::default() {
} else if priority == Priority::DEFAULT {
&peer.priority_rx[0]
} else {
bail!(
Expand Down Expand Up @@ -181,7 +181,7 @@ impl TransportMulticastInner {
let priority = ext_qos.priority();
let c = if self.is_qos() {
&peer.priority_rx[priority as usize]
} else if priority == Priority::default() {
} else if priority == Priority::DEFAULT {
&peer.priority_rx[0]
} else {
bail!(
Expand Down
4 changes: 2 additions & 2 deletions io/zenoh-transport/src/unicast/universal/rx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl TransportUnicastUniversal {
let priority = ext_qos.priority();
let c = if self.is_qos() {
&self.priority_rx[priority as usize]
} else if priority == Priority::default() {
} else if priority == Priority::DEFAULT {
&self.priority_rx[0]
} else {
bail!(
Expand Down Expand Up @@ -124,7 +124,7 @@ impl TransportUnicastUniversal {

let c = if self.is_qos() {
&self.priority_rx[qos.priority() as usize]
} else if qos.priority() == Priority::default() {
} else if qos.priority() == Priority::DEFAULT {
&self.priority_rx[0]
} else {
bail!(
Expand Down
2 changes: 1 addition & 1 deletion io/zenoh-transport/tests/multicast_compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ mod tests {
// Define the reliability and congestion control
let channel = [
Channel {
priority: Priority::default(),
priority: Priority::DEFAULT,
reliability: Reliability::BestEffort,
},
Channel {
Expand Down
2 changes: 1 addition & 1 deletion io/zenoh-transport/tests/multicast_transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ mod tests {
// Define the reliability and congestion control
let channel = [
Channel {
priority: Priority::default(),
priority: Priority::DEFAULT,
reliability: Reliability::BestEffort,
},
Channel {
Expand Down
8 changes: 4 additions & 4 deletions io/zenoh-transport/tests/unicast_compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ mod tests {
// Define the reliability and congestion control
let channel = [
Channel {
priority: Priority::default(),
priority: Priority::DEFAULT,
reliability: Reliability::Reliable,
},
Channel {
Expand Down Expand Up @@ -472,7 +472,7 @@ mod tests {
// Define the reliability and congestion control
let channel = [
Channel {
priority: Priority::default(),
priority: Priority::DEFAULT,
reliability: Reliability::Reliable,
},
Channel {
Expand Down Expand Up @@ -505,7 +505,7 @@ mod tests {
// Define the reliability and congestion control
let channel = [
Channel {
priority: Priority::default(),
priority: Priority::DEFAULT,
reliability: Reliability::BestEffort,
},
Channel {
Expand Down Expand Up @@ -535,7 +535,7 @@ mod tests {
// Define the reliability and congestion control
let channel = [
Channel {
priority: Priority::default(),
priority: Priority::DEFAULT,
reliability: Reliability::BestEffort,
},
Channel {
Expand Down
4 changes: 2 additions & 2 deletions io/zenoh-transport/tests/unicast_concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ async fn transport_concurrent(endpoint01: Vec<EndPoint>, endpoint02: Vec<EndPoin
// Create the message to send
let message: NetworkMessage = Push {
wire_expr: "test".into(),
ext_qos: QoSType::new(Priority::default(), CongestionControl::Block, false),
ext_qos: QoSType::new(Priority::DEFAULT, CongestionControl::Block, false),
ext_tstamp: None,
ext_nodeid: NodeIdType::default(),
payload: Put {
Expand Down Expand Up @@ -299,7 +299,7 @@ async fn transport_concurrent(endpoint01: Vec<EndPoint>, endpoint02: Vec<EndPoin
// Create the message to send
let message: NetworkMessage = Push {
wire_expr: "test".into(),
ext_qos: QoSType::new(Priority::default(), CongestionControl::Block, false),
ext_qos: QoSType::new(Priority::DEFAULT, CongestionControl::Block, false),
ext_tstamp: None,
ext_nodeid: NodeIdType::default(),
payload: Put {
Expand Down
12 changes: 6 additions & 6 deletions io/zenoh-transport/tests/unicast_defragmentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ fn transport_unicast_defragmentation_tcp_only() {
// Define the reliability and congestion control
let channel = [
Channel {
priority: Priority::default(),
priority: Priority::DEFAULT,
reliability: Reliability::Reliable,
},
Channel {
priority: Priority::default(),
priority: Priority::DEFAULT,
reliability: Reliability::BestEffort,
},
Channel {
Expand Down Expand Up @@ -186,11 +186,11 @@ fn transport_unicast_defragmentation_ws_only() {
// Define the reliability and congestion control
let channel = [
Channel {
priority: Priority::default(),
priority: Priority::DEFAULT,
reliability: Reliability::Reliable,
},
Channel {
priority: Priority::default(),
priority: Priority::DEFAULT,
reliability: Reliability::BestEffort,
},
Channel {
Expand Down Expand Up @@ -226,11 +226,11 @@ fn transport_unicast_defragmentation_unixpipe_only() {
// Define the reliability and congestion control
let channel = [
Channel {
priority: Priority::default(),
priority: Priority::DEFAULT,
reliability: Reliability::Reliable,
},
Channel {
priority: Priority::default(),
priority: Priority::DEFAULT,
reliability: Reliability::BestEffort,
},
Channel {
Expand Down
2 changes: 1 addition & 1 deletion io/zenoh-transport/tests/unicast_intermittent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ async fn transport_intermittent(endpoint: &EndPoint, lowlatency_transport: bool)
// Create the message to send
let message: NetworkMessage = Push {
wire_expr: "test".into(),
ext_qos: QoSType::new(Priority::default(), CongestionControl::Block, false),
ext_qos: QoSType::new(Priority::DEFAULT, CongestionControl::Block, false),
ext_tstamp: None,
ext_nodeid: NodeIdType::default(),
payload: Put {
Expand Down
4 changes: 2 additions & 2 deletions io/zenoh-transport/tests/unicast_shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ mod tests {

let message: NetworkMessage = Push {
wire_expr: "test".into(),
ext_qos: QoSType::new(Priority::default(), CongestionControl::Block, false),
ext_qos: QoSType::new(Priority::DEFAULT, CongestionControl::Block, false),
ext_tstamp: None,
ext_nodeid: NodeIdType::default(),
payload: Put {
Expand Down Expand Up @@ -319,7 +319,7 @@ mod tests {

let message: NetworkMessage = Push {
wire_expr: "test".into(),
ext_qos: QoSType::new(Priority::default(), CongestionControl::Block, false),
ext_qos: QoSType::new(Priority::DEFAULT, CongestionControl::Block, false),
ext_tstamp: None,
ext_nodeid: NodeIdType::default(),
payload: Put {
Expand Down
Loading

0 comments on commit 89555f1

Please sign in to comment.