Skip to content

Commit

Permalink
tags
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin committed Feb 16, 2024
1 parent 069a373 commit ecdc8b0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
12 changes: 12 additions & 0 deletions commons/zenoh-buffers/src/zbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,42 @@ fn get_mut_unchecked<T>(arc: &mut Arc<T>) -> &mut T {
}

#[derive(Debug, Clone, Default, Eq)]
// tags{zbuf, buffer}
// tags{zbuf.clone, buffer.rcinc}
pub struct ZBuf {
slices: SingleOrVec<ZSlice>,
}

impl ZBuf {
#[must_use]
// tags{zbuf.create, buffer.create}
pub fn empty() -> Self {
Self::default()
}

// tags{zbuf.clear}
pub fn clear(&mut self) {
self.slices.clear();
}

// tags{zbuf.slices.iter}
pub fn zslices(&self) -> impl Iterator<Item = &ZSlice> + '_ {
self.slices.as_ref().iter()
}

// tags{zbuf.slices.iter}
pub fn zslices_mut(&mut self) -> impl Iterator<Item = &mut ZSlice> + '_ {
self.slices.as_mut().iter_mut()
}

// tags{zbuf.slices.push}
pub fn push_zslice(&mut self, zslice: ZSlice) {
if !zslice.is_empty() {
self.slices.push(zslice);
}
}

// tags{zbuf.splice}
pub fn splice<Range: RangeBounds<usize>>(&mut self, erased: Range, replacement: &[u8]) {
let start = match erased.start_bound() {
core::ops::Bound::Included(n) => *n,
Expand Down Expand Up @@ -139,6 +147,7 @@ impl ZBuf {
// Buffer
impl Buffer for ZBuf {
#[inline(always)]
// tags{zbuf.len, buffer.len}
fn len(&self) -> usize {
self.slices
.as_ref()
Expand All @@ -151,12 +160,14 @@ impl Buffer for ZBuf {
impl SplitBuffer for ZBuf {
type Slices<'a> = iter::Map<core::slice::Iter<'a, ZSlice>, fn(&'a ZSlice) -> &'a [u8]>;

// tags{zbuf.slices.get}
fn slices(&self) -> Self::Slices<'_> {
self.slices.as_ref().iter().map(ZSlice::as_slice)
}
}

impl PartialEq for ZBuf {
// tags{zbuf.compare, buffer.compare}
fn eq(&self, other: &Self) -> bool {
let mut self_slices = self.slices();
let mut other_slices = other.slices();
Expand Down Expand Up @@ -383,6 +394,7 @@ impl<'a> SiphonableReader for ZBufReader<'a> {
}

#[cfg(feature = "std")]
// tags{zbuf.read, buffer.read}
impl<'a> std::io::Read for ZBufReader<'a> {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
match <Self as Reader>::read(self, buf) {
Expand Down
1 change: 1 addition & 0 deletions commons/zenoh-protocol/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use core::{
hash::Hash,
str::FromStr,
};
// tags{timestamp}
pub use uhlc::{Timestamp, NTP64};
use zenoh_keyexpr::OwnedKeyExpr;
use zenoh_result::{bail, zerror};
Expand Down
20 changes: 10 additions & 10 deletions zenoh/src/sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub type SourceSn = u64;
/// The locality of samples to be received by subscribers or targeted by publishers.
#[zenoh_macros::unstable]
#[derive(Clone, Copy, Debug, Default, Serialize, PartialEq, Eq)]
// tags{sample.options.locality}
// tags{options.sample.locality}
pub enum Locality {
SessionLocal,
Remote,
Expand All @@ -45,30 +45,30 @@ pub(crate) enum Locality {
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
// tags{sample.options.data_info}
// tags{options.sample.data_info}
pub(crate) struct DataInfo {
// tags{sample.options.data_info.kind}
// tags{options.sample.data_info.kind}
pub kind: SampleKind,
// tags{sample.options.data_info.encoding}
// tags{options.sample.data_info.encoding}
pub encoding: Option<Encoding>,
// tags{sample.options.data_info.timestamp}
// tags{options.sample.data_info.timestamp}
pub timestamp: Option<Timestamp>,
// tags{sample.options.data_info.source_id}
// tags{options.sample.data_info.source_id}
pub source_id: Option<ZenohId>,
// tags{sample.options.data_info.source_sn}
// tags{options.sample.data_info.source_sn}
pub source_sn: Option<SourceSn>,
}

/// Informations on the source of a zenoh [`Sample`].
#[zenoh_macros::unstable]
#[derive(Debug, Clone)]
// tags{sample.options.source_info}
// tags{options.sample.source_info}
pub struct SourceInfo {
/// The [`ZenohId`] of the zenoh instance that published the concerned [`Sample`].
// tags{sample.options.source_info.source_id}
// tags{options.sample.source_info.source_id}
pub source_id: Option<ZenohId>,
/// The sequence number of the [`Sample`] from the source.
// tags{sample.options.source_info.source_sn}
// tags{options.sample.source_info.source_sn}
pub source_sn: Option<SourceSn>,
}

Expand Down
2 changes: 1 addition & 1 deletion zenoh/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use zenoh_shm::SharedMemoryBuf;
/// A zenoh Value.
#[non_exhaustive]
#[derive(Clone)]
// tags{value}
// tags{value, buffer}
pub struct Value {
/// The payload of this Value.
pub payload: ZBuf,
Expand Down

0 comments on commit ecdc8b0

Please sign in to comment.