Skip to content

Commit

Permalink
Define EntityId type
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierHecart committed Feb 7, 2024
1 parent 585db56 commit d521496
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions commons/zenoh-codec/src/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use zenoh_buffers::{
};
use zenoh_protocol::{
common::{imsg, ZExtZ64, ZExtZBufHeader},
core::{Reliability, ZenohId},
core::{EntityId, Reliability, ZenohId},
network::{ext::EntityIdType, *},
};

Expand Down Expand Up @@ -263,7 +263,7 @@ where
let lodec = Zenoh080Length::new(length);
let zid: ZenohId = lodec.read(&mut *reader)?;

let eid: u32 = self.codec.read(&mut *reader)?;
let eid: EntityId = self.codec.read(&mut *reader)?;

Ok((ext::EntityIdType { zid, eid }, more))
}
Expand Down
4 changes: 2 additions & 2 deletions commons/zenoh-codec/src/zenoh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use zenoh_buffers::{
use zenoh_protocol::common::{iext, ZExtUnit};
use zenoh_protocol::{
common::{imsg, ZExtZBufHeader},
core::{Encoding, ZenohId},
core::{Encoding, EntityId, ZenohId},
zenoh::{ext, id, PushBody, RequestBody, ResponseBody},
};

Expand Down Expand Up @@ -199,7 +199,7 @@ where
let lodec = Zenoh080Length::new(length);
let zid: ZenohId = lodec.read(&mut *reader)?;

let eid: u32 = self.codec.read(&mut *reader)?;
let eid: EntityId = self.codec.read(&mut *reader)?;
let sn: u32 = self.codec.read(&mut *reader)?;

Ok((ext::SourceInfoType { zid, eid, sn }, more))
Expand Down
2 changes: 2 additions & 0 deletions commons/zenoh-protocol/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ impl<'de> serde::Deserialize<'de> for ZenohId {
}
}

pub type EntityId = u32;

#[repr(u8)]
#[derive(Debug, Default, Copy, Clone, Eq, Hash, PartialEq)]
pub enum Priority {
Expand Down
8 changes: 6 additions & 2 deletions commons/zenoh-protocol/src/network/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,11 @@ pub mod keyexpr {
}

pub mod subscriber {
use crate::core::EntityId;

use super::*;

pub type SubscriberId = u32;
pub type SubscriberId = EntityId;

pub mod flag {
pub const N: u8 = 1 << 5; // 0x20 Named if N==1 then the key expr has name/suffix
Expand Down Expand Up @@ -451,9 +453,11 @@ pub mod subscriber {
}

pub mod queryable {
use crate::core::EntityId;

use super::*;

pub type QueryableId = u32;
pub type QueryableId = EntityId;

pub mod flag {
pub const N: u8 = 1 << 5; // 0x20 Named if N==1 then the key expr has name/suffix
Expand Down
6 changes: 3 additions & 3 deletions commons/zenoh-protocol/src/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl From<ResponseFinal> for NetworkMessage {
pub mod ext {
use crate::{
common::{imsg, ZExtZ64},
core::{CongestionControl, Priority, ZenohId},
core::{CongestionControl, EntityId, Priority, ZenohId},
};
use core::fmt;

Expand Down Expand Up @@ -412,7 +412,7 @@ pub mod ext {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EntityIdType<const ID: u8> {
pub zid: ZenohId,
pub eid: u32,
pub eid: EntityId,
}

impl<const ID: u8> EntityIdType<{ ID }> {
Expand All @@ -422,7 +422,7 @@ pub mod ext {
let mut rng = rand::thread_rng();

let zid = ZenohId::rand();
let eid: u32 = rng.gen();
let eid: EntityId = rng.gen();
Self { zid, eid }
}
}
Expand Down
6 changes: 3 additions & 3 deletions commons/zenoh-protocol/src/zenoh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl From<Ack> for ResponseBody {
pub mod ext {
use zenoh_buffers::ZBuf;

use crate::core::{Encoding, ZenohId};
use crate::core::{Encoding, EntityId, ZenohId};

/// 7 6 5 4 3 2 1 0
/// +-+-+-+-+-+-+-+-+
Expand All @@ -184,7 +184,7 @@ pub mod ext {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SourceInfoType<const ID: u8> {
pub zid: ZenohId,
pub eid: u32,
pub eid: EntityId,
pub sn: u32,
}

Expand All @@ -195,7 +195,7 @@ pub mod ext {
let mut rng = rand::thread_rng();

let zid = ZenohId::rand();
let eid: u32 = rng.gen();
let eid: EntityId = rng.gen();
let sn: u32 = rng.gen();
Self { zid, eid, sn }
}
Expand Down
4 changes: 2 additions & 2 deletions zenoh/src/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use std::future::Ready;
use std::ops::Deref;
use std::sync::Arc;
use zenoh_core::{AsyncResolve, Resolvable, SyncResolve};
use zenoh_protocol::core::WireExpr;
use zenoh_protocol::core::{EntityId, WireExpr};
use zenoh_protocol::network::{response, Mapping, RequestId, Response, ResponseFinal};
use zenoh_protocol::zenoh::ext::ValueType;
use zenoh_protocol::zenoh::reply::ext::ConsolidationType;
Expand Down Expand Up @@ -66,7 +66,7 @@ impl Drop for QueryInner {
#[derive(Clone)]
pub struct Query {
pub(crate) inner: Arc<QueryInner>,
pub(crate) eid: u32,
pub(crate) eid: EntityId,
}

impl Query {
Expand Down

0 comments on commit d521496

Please sign in to comment.