Skip to content

Commit

Permalink
Remove ZenohMessage accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierHecart committed Jul 1, 2020
1 parent 37069fa commit 10cd510
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 51 deletions.
35 changes: 18 additions & 17 deletions zenoh-protocol/src/proto/demux.rs
Expand Up @@ -32,48 +32,49 @@ impl<P: Primitives + Send + Sync> DeMux<P> {
impl<P: Primitives + Send + Sync> MsgHandler for DeMux<P> {

async fn handle_message(&self, msg: ZenohMessage) -> ZResult<()> {
match msg.get_body() {
let reliability = msg.is_reliable();
match msg.body {
ZenohBody::Declare{ declarations, .. } => {
for declaration in declarations {
match declaration {
Declaration::Resource { rid, key } => {
self.primitives.resource(*rid, key).await;
self.primitives.resource(rid, &key).await;
}
Declaration::Publisher { key } => {
self.primitives.publisher(key).await;
self.primitives.publisher(&key).await;
}
Declaration::Subscriber { key, info } => {
self.primitives.subscriber(key, info).await;
self.primitives.subscriber(&key, &info).await;
}
Declaration::Queryable { key } => {
self.primitives.queryable(key).await;
self.primitives.queryable(&key).await;
}
Declaration::ForgetResource { rid } => {
self.primitives.forget_resource(*rid).await;
self.primitives.forget_resource(rid).await;
}
Declaration::ForgetPublisher { key } => {
self.primitives.forget_publisher(key).await;
self.primitives.forget_publisher(&key).await;
}
Declaration::ForgetSubscriber { key } => {
self.primitives.forget_subscriber(key).await;
self.primitives.forget_subscriber(&key).await;
}
Declaration::ForgetQueryable { key } => {
self.primitives.forget_queryable(key).await;
self.primitives.forget_queryable(&key).await;
}
}

}
},

ZenohBody::Data { key, info, payload, .. } => {
match &msg.reply_context {
match msg.reply_context {
None => {
self.primitives.data(key, msg.is_reliable(), info, payload.clone()).await;
self.primitives.data(&key, reliability, &info, payload).await;
}
Some(rep) => {
match &rep.replier_id {
match rep.replier_id {
Some(replier_id) => {
let reply = Reply::ReplyData {source_kind: rep.source_kind, replier_id: replier_id.clone(), reskey: key.clone(), info: info.clone(), payload: payload.clone()};
let reply = Reply::ReplyData {source_kind: rep.source_kind, replier_id, reskey: key, info, payload};
self.primitives.reply(rep.qid, reply).await}
None => return zerror!(ZErrorKind::Other {descr: "ReplyData with no replier_id".to_string()})
}
Expand All @@ -82,23 +83,23 @@ impl<P: Primitives + Send + Sync> MsgHandler for DeMux<P> {
},

ZenohBody::Unit { .. } => {
if let Some(rep) = &msg.reply_context {
if let Some(rep) = msg.reply_context {
if rep.is_final {
let reply = Reply::ReplyFinal {};
self.primitives.reply(rep.qid, reply).await
} else {
let reply = Reply::SourceFinal {source_kind: rep.source_kind, replier_id: rep.replier_id.clone().unwrap()};
let reply = Reply::SourceFinal {source_kind: rep.source_kind, replier_id: rep.replier_id.unwrap()};
self.primitives.reply(rep.qid, reply).await
}
}
},

ZenohBody::Query{ key, predicate, qid, target, consolidation, .. } => {
self.primitives.query(key, predicate, *qid, target.clone().unwrap_or_default(), consolidation.clone()).await;
self.primitives.query(&key, &predicate, qid, target.unwrap_or_default(), consolidation).await;
},

ZenohBody::Pull{ key, pull_id, max_samples, .. } => {
self.primitives.pull(zmsg::has_flag(msg.header, zmsg::flag::F), key, *pull_id, max_samples).await;
self.primitives.pull(zmsg::has_flag(msg.header, zmsg::flag::F), &key, pull_id, &max_samples).await;
}
}

Expand Down
36 changes: 5 additions & 31 deletions zenoh-protocol/src/proto/msg.rs
Expand Up @@ -327,11 +327,11 @@ pub enum ZenohBody {

#[derive(Clone, PartialEq)]
pub struct ZenohMessage {
pub(crate) header: u8,
pub(crate) body: ZenohBody,
pub(crate) channel: Channel,
pub(crate) reply_context: Option<ReplyContext>,
pub(crate) attachment: Option<Attachment>
pub header: u8,
pub body: ZenohBody,
pub channel: Channel,
pub reply_context: Option<ReplyContext>,
pub attachment: Option<Attachment>
}

impl std::fmt::Debug for ZenohMessage {
Expand Down Expand Up @@ -455,32 +455,6 @@ impl ZenohMessage {
pub fn is_reply(&self) -> bool {
self.reply_context.is_some()
}

// -- Accessor
#[inline]
pub fn get_body(&self) -> &ZenohBody {
&self.body
}

#[inline]
pub fn get_attachment(&self) -> &Option<Attachment> {
&self.attachment
}

#[inline]
pub fn get_attachment_mut(&mut self) -> &mut Option<Attachment> {
&mut self.attachment
}

#[inline]
pub fn get_reply_context(&self) -> &Option<ReplyContext> {
&self.reply_context
}

#[inline]
pub fn get_reply_context_mut(&mut self) -> &mut Option<ReplyContext> {
&mut self.reply_context
}
}

/*************************************/
Expand Down
6 changes: 3 additions & 3 deletions zenoh-protocol/src/proto/msg_writer.rs
Expand Up @@ -172,15 +172,15 @@ impl WBuf {
}

pub fn write_zenoh_message(&mut self, msg: &ZenohMessage) -> bool {
if let Some(attachment) = msg.get_attachment() {
if let Some(attachment) = &msg.attachment {
check!(self.write_deco_attachment(attachment, false));
}
if let Some(reply_context) = msg.get_reply_context() {
if let Some(reply_context) = &msg.reply_context {
check!(self.write_deco_reply(reply_context));
}

check!(self.write(msg.header));
match msg.get_body() {
match &msg.body {
ZenohBody::Declare { declarations } => {
check!(self.write_declarations(&declarations));
},
Expand Down

0 comments on commit 10cd510

Please sign in to comment.