Skip to content

Commit

Permalink
zenoh-protocol tagging
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin committed Feb 8, 2024
1 parent 9a4c6ef commit 840cb2e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
42 changes: 30 additions & 12 deletions commons/zenoh-protocol/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,45 @@ use zenoh_result::{bail, zerror};
pub type TimestampId = uhlc::ID;

/// Constants and helpers for zenoh `whatami` flags.
// ignore_tagging
pub mod whatami;
pub use whatami::*;

pub use zenoh_keyexpr::key_expr;

// ignore_tagging
pub mod wire_expr;
pub use wire_expr::*;

// ignore_tagging
mod cowstr;
pub use cowstr::CowStr;
// ignore_tagging
mod encoding;
pub use encoding::{Encoding, KnownEncoding};

// ignore_tagging
pub mod locator;
// ignore_tagging
pub use locator::*;

// ignore_tagging
pub mod endpoint;
pub use endpoint::*;

// ignore_tagging
pub mod resolution;
pub use resolution::*;

#[derive(Debug, Clone, PartialEq, Eq)]
// tags{}
pub struct Property {
pub key: u64,
pub value: Vec<u8>,
}

/// The kind of a `Sample`.
// tags{sample.options.kind}
#[repr(u8)]
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
pub enum SampleKind {
Expand Down Expand Up @@ -94,25 +104,31 @@ impl TryFrom<u64> for SampleKind {
/// The global unique id of a zenoh peer.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
// tags{zenoh_id}
pub struct ZenohId(uhlc::ID);

impl ZenohId {
// tags{zenoh_id.MAX_SIZE}
pub const MAX_SIZE: usize = 16;

#[inline]
// tags{zenoh_id.size}
pub fn size(&self) -> usize {
self.0.size()
}

#[inline]
// tags{zenoh_id.to_le_bytes}
pub fn to_le_bytes(&self) -> [u8; uhlc::ID::MAX_SIZE] {
self.0.to_le_bytes()
}

// tags{zenoh_id.rand}
pub fn rand() -> ZenohId {
ZenohId(uhlc::ID::rand())
}

// tags{zenoh_id.into_keyexpr}
pub fn into_keyexpr(self) -> OwnedKeyExpr {
self.into()
}
Expand All @@ -125,6 +141,7 @@ impl Default for ZenohId {
}

// Mimics uhlc::SizeError,
// tags{}
#[derive(Debug, Clone, Copy)]
pub struct SizeError(usize);

Expand Down Expand Up @@ -301,6 +318,7 @@ impl<'de> serde::Deserialize<'de> for ZenohId {

#[repr(u8)]
#[derive(Debug, Default, Copy, Clone, Eq, Hash, PartialEq)]
// tags{}
pub enum Priority {
Control = 0,
RealTime = 1,
Expand All @@ -315,10 +333,13 @@ pub enum Priority {

impl Priority {
/// The lowest Priority
// tags{}
pub const MIN: Self = Self::Background;
/// The highest Priority
// tags{}
pub const MAX: Self = Self::Control;
/// The number of available priorities
// tags{}
pub const NUM: usize = 1 + Self::MIN as usize - Self::MAX as usize;
}

Expand Down Expand Up @@ -347,6 +368,7 @@ impl TryFrom<u8> for Priority {

#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
#[repr(u8)]
// tags{options.reliability}
pub enum Reliability {
#[default]
BestEffort,
Expand All @@ -355,6 +377,7 @@ pub enum Reliability {

impl Reliability {
#[cfg(feature = "test")]
// tags{}
pub fn rand() -> Self {
use rand::Rng;

Expand All @@ -369,14 +392,18 @@ impl Reliability {
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Default)]
// tags{}
pub struct Channel {
// tags{}
pub priority: Priority,
// tags{}
pub reliability: Reliability,
}

/// The kind of congestion control.
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
#[repr(u8)]
// tags{options.congestion_control}
pub enum CongestionControl {
#[default]
Drop = 0,
Expand All @@ -386,26 +413,16 @@ pub enum CongestionControl {
/// The subscription mode.
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
#[repr(u8)]
// tags{options.subscriber.mode}
pub enum SubMode {
#[default]
Push = 0,
Pull = 1,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct SubInfo {
pub reliability: Reliability,
pub mode: SubMode,
}

#[derive(Debug, Default, Clone, PartialEq, Eq, Hash)]
pub struct QueryableInfo {
pub complete: u64, // Default 0: incomplete
pub distance: u64, // Default 0: no distance
}

/// The kind of consolidation.
#[derive(Debug, Clone, PartialEq, Eq, Copy)]
// tags{options.consolidation_mode}
pub enum ConsolidationMode {
/// No consolidation applied: multiple samples may be received for the same key-timestamp.
None,
Expand All @@ -423,6 +440,7 @@ pub enum ConsolidationMode {

/// The `zenoh::queryable::Queryable`s that should be target of a `zenoh::Session::get()`.
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
// tags{query.options.target}
pub enum QueryTarget {
#[default]
BestMatching,
Expand Down
6 changes: 6 additions & 0 deletions commons/zenoh-protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@
#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;

// ignore_tagging
pub mod common;
pub mod core;
// ignore_tagging
pub mod network;
// ignore_tagging
pub mod scouting;
// ignore_tagging
pub mod transport;
// ignore_tagging
pub mod zenoh;

// Zenoh version
// tags{}
pub const VERSION: u8 = 0x08;

// Zenoh protocol uses the following conventions for message definition and representation.
Expand Down

0 comments on commit 840cb2e

Please sign in to comment.