Skip to content

Commit

Permalink
SampleBuilder put/delete
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin committed Mar 28, 2024
1 parent ddb93a2 commit ab96aab
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
4 changes: 2 additions & 2 deletions plugins/zenoh-plugin-storage-manager/src/replica/aligner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::str;
use zenoh::key_expr::{KeyExpr, OwnedKeyExpr};
use zenoh::payload::StringOrBase64;
use zenoh::prelude::r#async::*;
use zenoh::sample::builder::{PutSampleBuilder, TimestampBuilderTrait, ValueBuilderTrait};
use zenoh::sample::builder::{SampleBuilder, TimestampBuilderTrait, ValueBuilderTrait};
use zenoh::time::Timestamp;
use zenoh::Session;

Expand Down Expand Up @@ -109,7 +109,7 @@ impl Aligner {
let Value {
payload, encoding, ..
} = value;
let sample = PutSampleBuilder::new(key, payload)
let sample = SampleBuilder::put(key, payload)
.encoding(encoding)
.timestamp(ts)
.into();
Expand Down
8 changes: 3 additions & 5 deletions plugins/zenoh-plugin-storage-manager/src/replica/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ use zenoh::buffers::ZBuf;
use zenoh::key_expr::KeyExpr;
use zenoh::prelude::r#async::*;
use zenoh::query::{ConsolidationMode, QueryTarget};
use zenoh::sample::builder::{
DeleteSampleBuilder, PutSampleBuilder, SampleBuilder, TimestampBuilderTrait, ValueBuilderTrait,
};
use zenoh::sample::builder::{SampleBuilder, TimestampBuilderTrait, ValueBuilderTrait};
use zenoh::sample::{Sample, SampleKind};
use zenoh::time::{new_reception_timestamp, Timestamp, NTP64};
use zenoh::value::Value;
Expand Down Expand Up @@ -309,15 +307,15 @@ impl StorageService {
let Value {
payload, encoding, ..
} = data.value;
PutSampleBuilder::new(KeyExpr::from(k.clone()), payload)
SampleBuilder::put(KeyExpr::from(k.clone()), payload)
.encoding(encoding)
.timestamp(data.timestamp)
.into()
}
Some(Update {
kind: SampleKind::Delete,
data,
}) => DeleteSampleBuilder::new(KeyExpr::from(k.clone()))
}) => SampleBuilder::delete(KeyExpr::from(k.clone()))
.timestamp(data.timestamp)
.into(),
None => SampleBuilder::from(sample.clone())
Expand Down
4 changes: 2 additions & 2 deletions zenoh/src/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ impl Query {
IntoKeyExpr: Into<KeyExpr<'static>>,
IntoPayload: Into<Payload>,
{
let sample_builder = PutSampleBuilder::new(key_expr, payload)
.with_qos(response::ext::QoSType::RESPONSE.into());
let sample_builder =
SampleBuilder::put(key_expr, payload).with_qos(response::ext::QoSType::RESPONSE.into());
ReplyBuilder {
query: self,
sample_builder,
Expand Down
27 changes: 13 additions & 14 deletions zenoh/src/sample/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,21 @@ pub trait ValueBuilderTrait {
pub struct SampleBuilder(Sample);

impl SampleBuilder {
pub fn new<IntoKeyExpr>(key_expr: IntoKeyExpr) -> Self
pub fn put<IntoKeyExpr, IntoPayload>(
key_expr: IntoKeyExpr,
payload: IntoPayload,
) -> PutSampleBuilder
where
IntoKeyExpr: Into<KeyExpr<'static>>,
IntoPayload: Into<Payload>,
{
Self(Sample {
key_expr: key_expr.into(),
payload: Payload::empty(),
kind: SampleKind::default(),
encoding: Encoding::default(),
timestamp: None,
qos: QoS::default(),
#[cfg(feature = "unstable")]
source_info: SourceInfo::empty(),
#[cfg(feature = "unstable")]
attachment: None,
})
PutSampleBuilder::new(key_expr, payload)
}
pub fn delete<IntoKeyExpr>(key_expr: IntoKeyExpr) -> DeleteSampleBuilder
where
IntoKeyExpr: Into<KeyExpr<'static>>,
{
DeleteSampleBuilder::new(key_expr)
}
/// Allows to change keyexpr of [`Sample`]
pub fn keyexpr<IntoKeyExpr>(self, key_expr: IntoKeyExpr) -> Self
Expand Down Expand Up @@ -149,7 +148,7 @@ impl From<SampleBuilder> for PutSampleBuilder {
}

impl PutSampleBuilder {
pub fn new<IntoKeyExpr, IntoPayload>(key_expr: IntoKeyExpr, payload: IntoPayload) -> Self
fn new<IntoKeyExpr, IntoPayload>(key_expr: IntoKeyExpr, payload: IntoPayload) -> Self
where
IntoKeyExpr: Into<KeyExpr<'static>>,
IntoPayload: Into<Payload>,
Expand Down

0 comments on commit ab96aab

Please sign in to comment.