Skip to content

Commit

Permalink
NodeType::DEFAULT
Browse files Browse the repository at this point in the history
  • Loading branch information
Mallets committed Feb 9, 2024
1 parent 375fd01 commit 665ef02
Show file tree
Hide file tree
Showing 32 changed files with 97 additions and 95 deletions.
12 changes: 6 additions & 6 deletions commons/zenoh-codec/benches/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn criterion_benchmark(c: &mut Criterion) {
wire_expr: WireExpr::empty(),
ext_qos: ext::QoSType::DEFAULT,
ext_tstamp: None,
ext_nodeid: ext::NodeIdType::default(),
ext_nodeid: ext::NodeIdType::DEFAULT,
payload: PushBody::Put(Put {
timestamp: None,
encoding: Encoding::DEFAULT,
Expand Down Expand Up @@ -130,7 +130,7 @@ fn criterion_benchmark(c: &mut Criterion) {
wire_expr: WireExpr::empty(),
ext_qos: ext::QoSType::DEFAULT,
ext_tstamp: None,
ext_nodeid: ext::NodeIdType::default(),
ext_nodeid: ext::NodeIdType::DEFAULT,
payload: PushBody::Put(Put {
timestamp: None,
encoding: Encoding::DEFAULT,
Expand Down Expand Up @@ -171,7 +171,7 @@ fn criterion_benchmark(c: &mut Criterion) {
wire_expr: WireExpr::empty(),
ext_qos: ext::QoSType::DEFAULT,
ext_tstamp: None,
ext_nodeid: ext::NodeIdType::default(),
ext_nodeid: ext::NodeIdType::DEFAULT,
payload: PushBody::Put(Put {
timestamp: None,
encoding: Encoding::DEFAULT,
Expand Down Expand Up @@ -212,7 +212,7 @@ fn criterion_benchmark(c: &mut Criterion) {
wire_expr: WireExpr::empty(),
ext_qos: ext::QoSType::DEFAULT,
ext_tstamp: None,
ext_nodeid: ext::NodeIdType::default(),
ext_nodeid: ext::NodeIdType::DEFAULT,
payload: PushBody::Put(Put {
timestamp: None,
encoding: Encoding::DEFAULT,
Expand Down Expand Up @@ -240,7 +240,7 @@ fn criterion_benchmark(c: &mut Criterion) {
wire_expr: WireExpr::empty(),
ext_qos: ext::QoSType::DEFAULT,
ext_tstamp: None,
ext_nodeid: ext::NodeIdType::default(),
ext_nodeid: ext::NodeIdType::DEFAULT,
payload: PushBody::Put(Put {
timestamp: None,
encoding: Encoding::DEFAULT,
Expand Down Expand Up @@ -279,7 +279,7 @@ fn criterion_benchmark(c: &mut Criterion) {
wire_expr: WireExpr::empty(),
ext_qos: ext::QoSType::DEFAULT,
ext_tstamp: None,
ext_nodeid: ext::NodeIdType::default(),
ext_nodeid: ext::NodeIdType::DEFAULT,
payload: PushBody::Put(Put {
timestamp: None,
encoding: Encoding::DEFAULT,
Expand Down
6 changes: 3 additions & 3 deletions commons/zenoh-codec/src/network/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ where
let mut header = id::DECLARE;
let mut n_exts = ((ext_qos != &declare::ext::QoSType::DEFAULT) as u8)
+ (ext_tstamp.is_some() as u8)
+ ((ext_nodeid != &declare::ext::NodeIdType::default()) as u8);
+ ((ext_nodeid != &declare::ext::NodeIdType::DEFAULT) as u8);
if n_exts != 0 {
header |= declare::flag::Z;
}
Expand All @@ -119,7 +119,7 @@ where
n_exts -= 1;
self.write(&mut *writer, (ts, n_exts != 0))?;
}
if ext_nodeid != &declare::ext::NodeIdType::default() {
if ext_nodeid != &declare::ext::NodeIdType::DEFAULT {
n_exts -= 1;
self.write(&mut *writer, (*ext_nodeid, n_exts != 0))?;
}
Expand Down Expand Up @@ -159,7 +159,7 @@ where
// Extensions
let mut ext_qos = declare::ext::QoSType::DEFAULT;
let mut ext_tstamp = None;
let mut ext_nodeid = declare::ext::NodeIdType::default();
let mut ext_nodeid = declare::ext::NodeIdType::DEFAULT;

let mut has_ext = imsg::has_flag(self.header, declare::flag::Z);
while has_ext {
Expand Down
6 changes: 3 additions & 3 deletions commons/zenoh-codec/src/network/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ where
let mut header = id::PUSH;
let mut n_exts = ((ext_qos != &ext::QoSType::DEFAULT) as u8)
+ (ext_tstamp.is_some() as u8)
+ ((ext_nodeid != &ext::NodeIdType::default()) as u8);
+ ((ext_nodeid != &ext::NodeIdType::DEFAULT) as u8);
if n_exts != 0 {
header |= flag::Z;
}
Expand All @@ -70,7 +70,7 @@ where
n_exts -= 1;
self.write(&mut *writer, (ts, n_exts != 0))?;
}
if ext_nodeid != &ext::NodeIdType::default() {
if ext_nodeid != &ext::NodeIdType::DEFAULT {
n_exts -= 1;
self.write(&mut *writer, (*ext_nodeid, n_exts != 0))?;
}
Expand Down Expand Up @@ -118,7 +118,7 @@ where
// Extensions
let mut ext_qos = ext::QoSType::DEFAULT;
let mut ext_tstamp = None;
let mut ext_nodeid = ext::NodeIdType::default();
let mut ext_nodeid = ext::NodeIdType::DEFAULT;

let mut has_ext = imsg::has_flag(self.header, flag::Z);
while has_ext {
Expand Down
6 changes: 3 additions & 3 deletions commons/zenoh-codec/src/network/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ where
+ ((ext_target != &ext::TargetType::DEFAULT) as u8)
+ (ext_budget.is_some() as u8)
+ (ext_timeout.is_some() as u8)
+ ((ext_nodeid != &ext::NodeIdType::default()) as u8);
+ ((ext_nodeid != &ext::NodeIdType::DEFAULT) as u8);
if n_exts != 0 {
header |= flag::Z;
}
Expand Down Expand Up @@ -137,7 +137,7 @@ where
let e = ext::Timeout::new(to.as_millis() as u64);
self.write(&mut *writer, (&e, n_exts != 0))?;
}
if ext_nodeid != &ext::NodeIdType::default() {
if ext_nodeid != &ext::NodeIdType::DEFAULT {
n_exts -= 1;
self.write(&mut *writer, (*ext_nodeid, n_exts != 0))?;
}
Expand Down Expand Up @@ -187,7 +187,7 @@ where
// Extensions
let mut ext_qos = ext::QoSType::DEFAULT;
let mut ext_tstamp = None;
let mut ext_nodeid = ext::NodeIdType::default();
let mut ext_nodeid = ext::NodeIdType::DEFAULT;
let mut ext_target = ext::TargetType::DEFAULT;
let mut ext_limit = None;
let mut ext_timeout = None;
Expand Down
6 changes: 4 additions & 2 deletions commons/zenoh-protocol/src/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ pub mod ext {
}

impl<const ID: u8> NodeIdType<{ ID }> {
// node_id == 0 means the message has been generated by the node itself
pub const DEFAULT: Self = Self { node_id: 0 };

#[cfg(feature = "test")]
pub fn rand() -> Self {
use rand::Rng;
Expand All @@ -370,8 +373,7 @@ pub mod ext {

impl<const ID: u8> Default for NodeIdType<{ ID }> {
fn default() -> Self {
// node_id == 0 means the message has been generated by the node itself
Self { node_id: 0 }
Self::DEFAULT
}
}

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 @@ -576,7 +576,7 @@ mod tests {
wire_expr: WireExpr::empty(),
ext_qos: ext::QoSType::new(Priority::DEFAULT, CongestionControl::Block, false),
ext_tstamp: None,
ext_nodeid: ext::NodeIdType::default(),
ext_nodeid: ext::NodeIdType::DEFAULT,
payload: PushBody::Put(Put {
timestamp: None,
encoding: Encoding::DEFAULT,
Expand Down
6 changes: 3 additions & 3 deletions io/zenoh-transport/src/common/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ mod tests {
wire_expr: key,
ext_qos: ext::QoSType::new(Priority::Control, CongestionControl::Block, false),
ext_tstamp: None,
ext_nodeid: ext::NodeIdType::default(),
ext_nodeid: ext::NodeIdType::DEFAULT,
payload: PushBody::Put(Put {
timestamp: None,
encoding: Encoding::DEFAULT,
Expand Down Expand Up @@ -881,7 +881,7 @@ mod tests {
wire_expr: key,
ext_qos: ext::QoSType::new(Priority::Control, CongestionControl::Block, false),
ext_tstamp: None,
ext_nodeid: ext::NodeIdType::default(),
ext_nodeid: ext::NodeIdType::DEFAULT,
payload: PushBody::Put(Put {
timestamp: None,
encoding: Encoding::DEFAULT,
Expand Down Expand Up @@ -993,7 +993,7 @@ mod tests {
false,
),
ext_tstamp: None,
ext_nodeid: ext::NodeIdType::default(),
ext_nodeid: ext::NodeIdType::DEFAULT,
payload: PushBody::Put(Put {
timestamp: None,
encoding: Encoding::DEFAULT,
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 @@ -269,7 +269,7 @@ mod tests {
wire_expr: "test".into(),
ext_qos: QoSType::new(channel.priority, CongestionControl::Block, false),
ext_tstamp: None,
ext_nodeid: NodeIdType::default(),
ext_nodeid: NodeIdType::DEFAULT,
payload: Put {
payload: vec![0u8; msg_size].into(),
timestamp: None,
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 @@ -265,7 +265,7 @@ mod tests {
wire_expr: "test".into(),
ext_qos: QoSType::new(channel.priority, CongestionControl::Block, false),
ext_tstamp: None,
ext_nodeid: NodeIdType::default(),
ext_nodeid: NodeIdType::DEFAULT,
payload: Put {
payload: vec![0u8; msg_size].into(),
timestamp: None,
Expand Down
2 changes: 1 addition & 1 deletion io/zenoh-transport/tests/unicast_compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ mod tests {
wire_expr: "test".into(),
ext_qos: QoSType::new(channel.priority, cctrl, false),
ext_tstamp: None,
ext_nodeid: NodeIdType::default(),
ext_nodeid: NodeIdType::DEFAULT,
payload: Put {
payload: vec![0u8; msg_size].into(),
timestamp: None,
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 @@ -196,7 +196,7 @@ async fn transport_concurrent(endpoint01: Vec<EndPoint>, endpoint02: Vec<EndPoin
wire_expr: "test".into(),
ext_qos: QoSType::new(Priority::DEFAULT, CongestionControl::Block, false),
ext_tstamp: None,
ext_nodeid: NodeIdType::default(),
ext_nodeid: NodeIdType::DEFAULT,
payload: Put {
payload: vec![0u8; MSG_SIZE].into(),
timestamp: None,
Expand Down Expand Up @@ -301,7 +301,7 @@ async fn transport_concurrent(endpoint01: Vec<EndPoint>, endpoint02: Vec<EndPoin
wire_expr: "test".into(),
ext_qos: QoSType::new(Priority::DEFAULT, CongestionControl::Block, false),
ext_tstamp: None,
ext_nodeid: NodeIdType::default(),
ext_nodeid: NodeIdType::DEFAULT,
payload: Put {
payload: vec![0u8; MSG_SIZE].into(),
timestamp: None,
Expand Down
2 changes: 1 addition & 1 deletion io/zenoh-transport/tests/unicast_defragmentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async fn run(endpoint: &EndPoint, channel: Channel, msg_size: usize) {
wire_expr: "test".into(),
ext_qos: QoSType::new(channel.priority, CongestionControl::Block, false),
ext_tstamp: None,
ext_nodeid: NodeIdType::default(),
ext_nodeid: NodeIdType::DEFAULT,
payload: Put {
payload: vec![0u8; msg_size].into(),
timestamp: None,
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 @@ -299,7 +299,7 @@ async fn transport_intermittent(endpoint: &EndPoint, lowlatency_transport: bool)
wire_expr: "test".into(),
ext_qos: QoSType::new(Priority::DEFAULT, CongestionControl::Block, false),
ext_tstamp: None,
ext_nodeid: NodeIdType::default(),
ext_nodeid: NodeIdType::DEFAULT,
payload: Put {
payload: vec![0u8; MSG_SIZE].into(),
timestamp: None,
Expand Down
2 changes: 1 addition & 1 deletion io/zenoh-transport/tests/unicast_priorities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ async fn single_run(router_handler: Arc<SHRouter>, client_transport: TransportUn
wire_expr: "test".into(),
ext_qos: QoSType::new(*p, CongestionControl::Block, false),
ext_tstamp: None,
ext_nodeid: NodeIdType::default(),
ext_nodeid: NodeIdType::DEFAULT,
payload: Put {
payload: vec![0u8; *ms].into(),
timestamp: None,
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 @@ -273,7 +273,7 @@ mod tests {
wire_expr: "test".into(),
ext_qos: QoSType::new(Priority::DEFAULT, CongestionControl::Block, false),
ext_tstamp: None,
ext_nodeid: NodeIdType::default(),
ext_nodeid: NodeIdType::DEFAULT,
payload: Put {
payload: sbuf.into(),
timestamp: None,
Expand Down Expand Up @@ -321,7 +321,7 @@ mod tests {
wire_expr: "test".into(),
ext_qos: QoSType::new(Priority::DEFAULT, CongestionControl::Block, false),
ext_tstamp: None,
ext_nodeid: NodeIdType::default(),
ext_nodeid: NodeIdType::DEFAULT,
payload: Put {
payload: sbuf.into(),
timestamp: None,
Expand Down
2 changes: 1 addition & 1 deletion io/zenoh-transport/tests/unicast_simultaneous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ mod tests {
wire_expr: "test".into(),
ext_qos: QoSType::new(Priority::Control, CongestionControl::Block, false),
ext_tstamp: None,
ext_nodeid: NodeIdType::default(),
ext_nodeid: NodeIdType::DEFAULT,
payload: Put {
payload: vec![0u8; MSG_SIZE].into(),
timestamp: None,
Expand Down
2 changes: 1 addition & 1 deletion io/zenoh-transport/tests/unicast_transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ async fn test_transport(
wire_expr: "test".into(),
ext_qos: QoSType::new(channel.priority, cctrl, false),
ext_tstamp: None,
ext_nodeid: NodeIdType::default(),
ext_nodeid: NodeIdType::DEFAULT,
payload: Put {
payload: vec![0u8; msg_size].into(),
timestamp: None,
Expand Down
2 changes: 1 addition & 1 deletion zenoh/src/key_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ impl SyncResolve for KeyExprUndeclaration<'_> {
primitives.send_declare(zenoh_protocol::network::Declare {
ext_qos: declare::ext::QoSType::DECLARE,
ext_tstamp: None,
ext_nodeid: declare::ext::NodeIdType::default(),
ext_nodeid: declare::ext::NodeIdType::DEFAULT,
body: DeclareBody::UndeclareKeyExpr(UndeclareKeyExpr { id: expr_id }),
});

Expand Down
2 changes: 1 addition & 1 deletion zenoh/src/net/routing/dispatcher/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ pub fn pull_data(tables_ref: &RwLock<Tables>, face: &Arc<FaceState>, expr: WireE
wire_expr: key_expr,
ext_qos: ext::QoSType::PUSH,
ext_tstamp: None,
ext_nodeid: ext::NodeIdType::default(),
ext_nodeid: ext::NodeIdType::DEFAULT,
payload,
});
}
Expand Down
2 changes: 1 addition & 1 deletion zenoh/src/net/routing/dispatcher/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ impl Resource {
Declare {
ext_qos: ext::QoSType::DECLARE,
ext_tstamp: None,
ext_nodeid: ext::NodeIdType::default(),
ext_nodeid: ext::NodeIdType::DEFAULT,
body: DeclareBody::DeclareKeyExpr(DeclareKeyExpr {
id: expr_id,
wire_expr: nonwild_prefix.expr().into(),
Expand Down
8 changes: 4 additions & 4 deletions zenoh/src/net/routing/hat/client/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn propagate_simple_subscription_to(
Declare {
ext_qos: ext::QoSType::DECLARE,
ext_tstamp: None,
ext_nodeid: ext::NodeIdType::default(),
ext_nodeid: ext::NodeIdType::DEFAULT,
body: DeclareBody::DeclareSubscriber(DeclareSubscriber {
id: 0, // @TODO use proper SubscriberId (#703)
wire_expr: key_expr,
Expand Down Expand Up @@ -139,7 +139,7 @@ fn declare_client_subscription(
Declare {
ext_qos: ext::QoSType::DECLARE,
ext_tstamp: None,
ext_nodeid: ext::NodeIdType::default(),
ext_nodeid: ext::NodeIdType::DEFAULT,
body: DeclareBody::DeclareSubscriber(DeclareSubscriber {
id: 0, // @TODO use proper SubscriberId (#703)
wire_expr: res.expr().into(),
Expand Down Expand Up @@ -173,7 +173,7 @@ fn propagate_forget_simple_subscription(tables: &mut Tables, res: &Arc<Resource>
Declare {
ext_qos: ext::QoSType::DECLARE,
ext_tstamp: None,
ext_nodeid: ext::NodeIdType::default(),
ext_nodeid: ext::NodeIdType::DEFAULT,
body: DeclareBody::UndeclareSubscriber(UndeclareSubscriber {
id: 0, // @TODO use proper SubscriberId (#703)
ext_wire_expr: WireExprType { wire_expr },
Expand Down Expand Up @@ -211,7 +211,7 @@ pub(super) fn undeclare_client_subscription(
Declare {
ext_qos: ext::QoSType::DECLARE,
ext_tstamp: None,
ext_nodeid: ext::NodeIdType::default(),
ext_nodeid: ext::NodeIdType::DEFAULT,
body: DeclareBody::UndeclareSubscriber(UndeclareSubscriber {
id: 0, // @TODO use proper SubscriberId (#703)
ext_wire_expr: WireExprType { wire_expr },
Expand Down
6 changes: 3 additions & 3 deletions zenoh/src/net/routing/hat/client/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn propagate_simple_queryable(
Declare {
ext_qos: ext::QoSType::DECLARE,
ext_tstamp: None,
ext_nodeid: ext::NodeIdType::default(),
ext_nodeid: ext::NodeIdType::DEFAULT,
body: DeclareBody::DeclareQueryable(DeclareQueryable {
id: 0, // @TODO use proper QueryableId (#703)
wire_expr: key_expr,
Expand Down Expand Up @@ -168,7 +168,7 @@ fn propagate_forget_simple_queryable(tables: &mut Tables, res: &mut Arc<Resource
Declare {
ext_qos: ext::QoSType::DECLARE,
ext_tstamp: None,
ext_nodeid: ext::NodeIdType::default(),
ext_nodeid: ext::NodeIdType::DEFAULT,
body: DeclareBody::UndeclareQueryable(UndeclareQueryable {
id: 0, // @TODO use proper QueryableId (#703)
ext_wire_expr: WireExprType { wire_expr },
Expand Down Expand Up @@ -209,7 +209,7 @@ pub(super) fn undeclare_client_queryable(
Declare {
ext_qos: ext::QoSType::DECLARE,
ext_tstamp: None,
ext_nodeid: ext::NodeIdType::default(),
ext_nodeid: ext::NodeIdType::DEFAULT,
body: DeclareBody::UndeclareQueryable(UndeclareQueryable {
id: 0, // @TODO use proper QueryableId (#703)
ext_wire_expr: WireExprType { wire_expr },
Expand Down
Loading

0 comments on commit 665ef02

Please sign in to comment.