Skip to content

Commit

Permalink
with removed
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin committed Mar 28, 2024
1 parent 2ff6bc2 commit 5bbef9c
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 37 deletions.
10 changes: 2 additions & 8 deletions plugins/zenoh-plugin-rest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ async fn query(mut req: Request<(Arc<Session>, String)>) -> tide::Result<Respons
.content_type()
.map(|m| Encoding::from(m.to_string()))
.unwrap_or_default();
query = query.with_value(Value::from(body).with_encoding(encoding));
query = query.with_value(Value::from(body).encoding(encoding));
}
match query.res().await {
Ok(receiver) => {
Expand Down Expand Up @@ -464,13 +464,7 @@ async fn write(mut req: Request<(Arc<Session>, String)>) -> tide::Result<Respons
// @TODO: Define the right congestion control value
let session = &req.state().0;
let res = match method_to_kind(req.method()) {
SampleKind::Put => {
session
.put(&key_expr, bytes)
.with_encoding(encoding)
.res()
.await
}
SampleKind::Put => session.put(&key_expr, bytes).encoding(encoding).res().await,
SampleKind::Delete => session.delete(&key_expr).res().await,
};
match res {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl AlignQueryable {
AlignData::Data(k, (v, ts)) => {
query
.reply(k, v.payload)
.with_encoding(v.encoding)
.encoding(v.encoding)
.timestamp(ts)
.res()
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl Aligner {
payload, encoding, ..
} = value;
let sample = PutSampleBuilder::new(key, payload)
.with_encoding(encoding)
.encoding(encoding)
.timestamp(ts)
.res_sync();
log::debug!("[ALIGNER] Adding {:?} to storage", sample);
Expand Down
10 changes: 5 additions & 5 deletions plugins/zenoh-plugin-storage-manager/src/replica/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ impl StorageService {
payload, encoding, ..
} = data.value;
PutSampleBuilder::new(KeyExpr::from(k.clone()), payload)
.with_encoding(encoding)
.encoding(encoding)
.timestamp(data.timestamp)
.res_sync()
}
Expand Down Expand Up @@ -344,7 +344,7 @@ impl StorageService {
.put(
stripped_key,
Value::new(sample_to_store.payload().clone())
.with_encoding(sample_to_store.encoding().clone()),
.encoding(sample_to_store.encoding().clone()),
*sample_to_store.timestamp().unwrap(),
)
.await
Expand Down Expand Up @@ -532,7 +532,7 @@ impl StorageService {
} = entry.value;
if let Err(e) = q
.reply(key.clone(), payload)
.with_encoding(encoding)
.encoding(encoding)
.timestamp(entry.timestamp)
.res_async()
.await
Expand Down Expand Up @@ -567,7 +567,7 @@ impl StorageService {
} = entry.value;
if let Err(e) = q
.reply(q.key_expr().clone(), payload)
.with_encoding(encoding)
.encoding(encoding)
.timestamp(entry.timestamp)
.res_async()
.await
Expand Down Expand Up @@ -719,7 +719,7 @@ fn construct_update(data: String) -> Update {
for slice in result.3 {
payload.push_zslice(slice.to_vec().into());
}
let value = Value::new(payload).with_encoding(result.2);
let value = Value::new(payload).encoding(result.2);
let data = StoredData {
value,
timestamp: Timestamp::from_str(&result.1).unwrap(), // @TODO: remove the unwrap()
Expand Down
4 changes: 2 additions & 2 deletions zenoh/src/net/runtime/adminspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ impl Primitives for AdminSpace {
parameters,
value: query
.ext_body
.map(|b| Value::from(b.payload).with_encoding(b.encoding)),
.map(|b| Value::from(b.payload).encoding(b.encoding)),
qid: msg.id,
zid,
primitives,
Expand Down Expand Up @@ -578,7 +578,7 @@ fn router_data(context: &AdminContext, query: Query) {
};
if let Err(e) = query
.reply(reply_key, payload)
.with_encoding(Encoding::APPLICATION_JSON)
.encoding(Encoding::APPLICATION_JSON)
.res_sync()
{
log::error!("Error sending AdminSpace reply: {:?}", e);
Expand Down
8 changes: 4 additions & 4 deletions zenoh/src/publication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,14 @@ impl SampleBuilderTrait for DeleteBuilder<'_, '_> {
}

impl ValueBuilderTrait for PutBuilder<'_, '_> {
fn with_encoding<T: Into<Encoding>>(self, encoding: T) -> Self {
fn encoding<T: Into<Encoding>>(self, encoding: T) -> Self {
Self {
encoding: encoding.into(),
..self
}
}

fn with_payload<IntoPayload>(self, payload: IntoPayload) -> Self
fn payload<IntoPayload>(self, payload: IntoPayload) -> Self
where
IntoPayload: Into<Payload>,
{
Expand Down Expand Up @@ -782,14 +782,14 @@ impl SampleBuilderTrait for PutPublication<'_> {
}

impl ValueBuilderTrait for PutPublication<'_> {
fn with_encoding<T: Into<Encoding>>(self, encoding: T) -> Self {
fn encoding<T: Into<Encoding>>(self, encoding: T) -> Self {
Self {
encoding: encoding.into(),
..self
}
}

fn with_payload<IntoPayload>(self, payload: IntoPayload) -> Self
fn payload<IntoPayload>(self, payload: IntoPayload) -> Self
where
IntoPayload: Into<Payload>,
{
Expand Down
8 changes: 4 additions & 4 deletions zenoh/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ impl QoSBuilderTrait for GetBuilder<'_, '_, DefaultHandler> {
}

impl<Handler> ValueBuilderTrait for GetBuilder<'_, '_, Handler> {
fn with_encoding<T: Into<Encoding>>(self, encoding: T) -> Self {
let value = Some(self.value.unwrap_or_default().with_encoding(encoding));
fn encoding<T: Into<Encoding>>(self, encoding: T) -> Self {
let value = Some(self.value.unwrap_or_default().encoding(encoding));
Self { value, ..self }
}

fn with_payload<T: Into<Payload>>(self, payload: T) -> Self {
let value = Some(self.value.unwrap_or_default().with_payload(payload));
fn payload<T: Into<Payload>>(self, payload: T) -> Self {
let value = Some(self.value.unwrap_or_default().payload(payload));
Self { value, ..self }
}
}
Expand Down
10 changes: 5 additions & 5 deletions zenoh/src/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl<'a> ReplySampleBuilder<'a> {
query: self.query,
sample_builder: self.sample_builder.into(),
};
builder.with_payload(payload)
builder.payload(payload)
}
pub fn delete(self) -> ReplyDelBuilder<'a> {
ReplyDelBuilder {
Expand Down Expand Up @@ -366,16 +366,16 @@ impl QoSBuilderTrait for ReplyBuilder<'_> {
}

impl ValueBuilderTrait for ReplyBuilder<'_> {
fn with_encoding<T: Into<Encoding>>(self, encoding: T) -> Self {
fn encoding<T: Into<Encoding>>(self, encoding: T) -> Self {
Self {
sample_builder: self.sample_builder.with_encoding(encoding),
sample_builder: self.sample_builder.encoding(encoding),
..self
}
}

fn with_payload<T: Into<Payload>>(self, payload: T) -> Self {
fn payload<T: Into<Payload>>(self, payload: T) -> Self {
Self {
sample_builder: self.sample_builder.with_payload(payload),
sample_builder: self.sample_builder.payload(payload),
..self
}
}
Expand Down
2 changes: 1 addition & 1 deletion zenoh/src/sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ impl Sample {

impl From<Sample> for Value {
fn from(sample: Sample) -> Self {
Value::new(sample.payload).with_encoding(sample.encoding)
Value::new(sample.payload).encoding(sample.encoding)
}
}

Expand Down
8 changes: 4 additions & 4 deletions zenoh/src/sample_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ pub trait SampleBuilderTrait {

pub trait ValueBuilderTrait {
/// Set the [`Encoding`]
fn with_encoding<T: Into<Encoding>>(self, encoding: T) -> Self;
fn encoding<T: Into<Encoding>>(self, encoding: T) -> Self;
/// Sets the payload
fn with_payload<T: Into<Payload>>(self, payload: T) -> Self;
fn payload<T: Into<Payload>>(self, payload: T) -> Self;
}

#[derive(Debug)]
Expand Down Expand Up @@ -213,13 +213,13 @@ impl QoSBuilderTrait for PutSampleBuilder {
}

impl ValueBuilderTrait for PutSampleBuilder {
fn with_encoding<T: Into<Encoding>>(self, encoding: T) -> Self {
fn encoding<T: Into<Encoding>>(self, encoding: T) -> Self {
Self(SampleBuilder(Sample {
encoding: encoding.into(),
..self.0 .0
}))
}
fn with_payload<T: Into<Payload>>(self, payload: T) -> Self {
fn payload<T: Into<Payload>>(self, payload: T) -> Self {
Self(SampleBuilder(Sample {
payload: payload.into(),
..self.0 .0
Expand Down
4 changes: 2 additions & 2 deletions zenoh/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ impl Value {
}

impl ValueBuilderTrait for Value {
fn with_encoding<T: Into<Encoding>>(self, encoding: T) -> Self {
fn encoding<T: Into<Encoding>>(self, encoding: T) -> Self {
Self {
encoding: encoding.into(),
..self
}
}
fn with_payload<T: Into<Payload>>(self, payload: T) -> Self {
fn payload<T: Into<Payload>>(self, payload: T) -> Self {
Self {
payload: payload.into(),
..self
Expand Down

0 comments on commit 5bbef9c

Please sign in to comment.