Skip to content

Commit

Permalink
QueryableInfo::DEFAULT
Browse files Browse the repository at this point in the history
  • Loading branch information
Mallets committed Feb 9, 2024
1 parent 665ef02 commit d93e933
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
12 changes: 6 additions & 6 deletions commons/zenoh-codec/src/network/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ where

// Header
let mut header = declare::id::D_SUBSCRIBER;
let mut n_exts = (ext_info != &subscriber::ext::SubscriberInfo::default()) as u8;
let mut n_exts = (ext_info != &subscriber::ext::SubscriberInfo::DEFAULT) as u8;
if n_exts != 0 {
header |= subscriber::flag::Z;
}
Expand All @@ -357,7 +357,7 @@ where
self.write(&mut *writer, wire_expr)?;

// Extensions
if ext_info != &subscriber::ext::SubscriberInfo::default() {
if ext_info != &subscriber::ext::SubscriberInfo::DEFAULT {
n_exts -= 1;
self.write(&mut *writer, (*ext_info, n_exts != 0))?;
}
Expand Down Expand Up @@ -402,7 +402,7 @@ where
};

// Extensions
let mut ext_info = subscriber::ext::SubscriberInfo::default();
let mut ext_info = subscriber::ext::SubscriberInfo::DEFAULT;

let mut has_ext = imsg::has_flag(self.header, subscriber::flag::Z);
while has_ext {
Expand Down Expand Up @@ -524,7 +524,7 @@ where

// Header
let mut header = declare::id::D_QUERYABLE;
let mut n_exts = (ext_info != &queryable::ext::QueryableInfo::default()) as u8;
let mut n_exts = (ext_info != &queryable::ext::QueryableInfo::DEFAULT) as u8;
if n_exts != 0 {
header |= subscriber::flag::Z;
}
Expand All @@ -539,7 +539,7 @@ where
// Body
self.write(&mut *writer, id)?;
self.write(&mut *writer, wire_expr)?;
if ext_info != &queryable::ext::QueryableInfo::default() {
if ext_info != &queryable::ext::QueryableInfo::DEFAULT {
n_exts -= 1;
self.write(&mut *writer, (*ext_info, n_exts != 0))?;
}
Expand Down Expand Up @@ -584,7 +584,7 @@ where
};

// Extensions
let mut ext_info = queryable::ext::QueryableInfo::default();
let mut ext_info = queryable::ext::QueryableInfo::DEFAULT;

let mut has_ext = imsg::has_flag(self.header, queryable::flag::Z);
while has_ext {
Expand Down
28 changes: 26 additions & 2 deletions commons/zenoh-protocol/src/network/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ pub enum Mode {
}

impl Mode {
pub const DEFAULT: Self = Self::Push;

#[cfg(feature = "test")]
fn rand() -> Self {
use rand::Rng;
Expand Down Expand Up @@ -344,7 +346,7 @@ pub mod subscriber {
/// - if P==1 then the subscription is pull, else it is push
/// - rsv: Reserved
/// ```
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SubscriberInfo {
pub reliability: Reliability,
pub mode: Mode,
Expand All @@ -354,6 +356,11 @@ pub mod subscriber {
pub const R: u64 = 1;
pub const P: u64 = 1 << 1;

pub const DEFAULT: Self = Self {
reliability: Reliability::DEFAULT,
mode: Mode::DEFAULT,
};

#[cfg(feature = "test")]
pub fn rand() -> Self {
let reliability = Reliability::rand();
Expand All @@ -363,6 +370,12 @@ pub mod subscriber {
}
}

impl Default for SubscriberInfo {
fn default() -> Self {
Self::DEFAULT
}
}

impl From<Info> for SubscriberInfo {
fn from(ext: Info) -> Self {
let reliability = if imsg::has_option(ext.value, SubscriberInfo::R) {
Expand Down Expand Up @@ -502,13 +515,18 @@ pub mod queryable {
/// +---------------+
/// ~ distance ~
/// +---------------+
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct QueryableInfo {
pub complete: u8, // Default 0: incomplete // @TODO: maybe a bitflag
pub distance: u32, // Default 0: no distance
}

impl QueryableInfo {
pub const DEFAULT: Self = Self {
complete: 0,
distance: 0,
};

#[cfg(feature = "test")]
pub fn rand() -> Self {
use rand::Rng;
Expand All @@ -520,6 +538,12 @@ pub mod queryable {
}
}

impl Default for QueryableInfo {
fn default() -> Self {
Self::DEFAULT
}
}

impl From<Info> for QueryableInfo {
fn from(ext: Info) -> Self {
let complete = ext.value as u8;
Expand Down
2 changes: 1 addition & 1 deletion zenoh/src/liveliness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ where
&Some(KeyExpr::from(*KE_PREFIX_LIVELINESS)),
Locality::default(),
callback,
&SubscriberInfo::default(),
&SubscriberInfo::DEFAULT,
)
.map(|sub_state| Subscriber {
subscriber: SubscriberInner {
Expand Down
2 changes: 1 addition & 1 deletion zenoh/src/net/runtime/adminspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl AdminSpace {
body: DeclareBody::DeclareSubscriber(DeclareSubscriber {
id: 0, // @TODO use proper SubscriberId (#703)
wire_expr: [&root_key, "/config/**"].concat().into(),
ext_info: SubscriberInfo::default(),
ext_info: SubscriberInfo::DEFAULT,
}),
});
}
Expand Down
2 changes: 1 addition & 1 deletion zenoh/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,7 @@ impl Session {
body: DeclareBody::DeclareSubscriber(DeclareSubscriber {
id: id as u32,
wire_expr: key_expr.to_wire(self).to_owned(),
ext_info: SubscriberInfo::default(),
ext_info: SubscriberInfo::DEFAULT,
}),
});
Ok(tok_state)
Expand Down

0 comments on commit d93e933

Please sign in to comment.