Skip to content
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

Allow DeclareInterest for any keyexpr #739

Merged
merged 3 commits into from
Feb 26, 2024
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
41 changes: 22 additions & 19 deletions commons/zenoh-codec/src/network/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use zenoh_protocol::{
network::{
declare::{
self, common, interest, keyexpr, queryable, subscriber, token, Declare, DeclareBody,
Interest,
},
id, Mapping,
},
Expand Down Expand Up @@ -845,24 +846,20 @@ where
fn write(self, writer: &mut W, x: &interest::DeclareInterest) -> Self::Output {
let interest::DeclareInterest {
id,
interest: _,
wire_expr,
interest,
} = x;

// Header
let mut header = declare::id::D_INTEREST;
if wire_expr.mapping != Mapping::DEFAULT {
header |= subscriber::flag::M;
}
if wire_expr.has_suffix() {
header |= subscriber::flag::N;
}
let header = declare::id::D_INTEREST | x.flags();
self.write(&mut *writer, header)?;

// Body
self.write(&mut *writer, id)?;
self.write(&mut *writer, wire_expr)?;
self.write(&mut *writer, interest.as_u8())?;
self.write(&mut *writer, x.options())?;
if let Some(we) = wire_expr.as_ref() {
self.write(&mut *writer, we)?;
}

Ok(())
}
Expand Down Expand Up @@ -894,14 +891,20 @@ where

// Body
let id: interest::InterestId = self.codec.read(&mut *reader)?;
let ccond = Zenoh080Condition::new(imsg::has_flag(self.header, token::flag::N));
let mut wire_expr: WireExpr<'static> = ccond.read(&mut *reader)?;
wire_expr.mapping = if imsg::has_flag(self.header, token::flag::M) {
Mapping::Sender
} else {
Mapping::Receiver
};
let interest: u8 = self.codec.read(&mut *reader)?;
let options: u8 = self.codec.read(&mut *reader)?;
let interest = Interest::from((imsg::flags(self.header), options));

let mut wire_expr = None;
if interest.restricted() {
let ccond = Zenoh080Condition::new(interest.named());
let mut we: WireExpr<'static> = ccond.read(&mut *reader)?;
we.mapping = if interest.mapping() {
Mapping::Sender
} else {
Mapping::Receiver
};
wire_expr = Some(we);
}

// Extensions
let has_ext = imsg::has_flag(self.header, token::flag::Z);
Expand All @@ -911,8 +914,8 @@ where

Ok(interest::DeclareInterest {
id,
interest,
wire_expr,
interest: interest.into(),
})
}
}
Expand Down
Loading