Skip to content

Commit

Permalink
into to encoding returned
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin committed Mar 28, 2024
1 parent aafd2a4 commit fb6509d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 33 deletions.
Original file line number Diff line number Diff line change
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.into());
let value = Value::new(payload).with_encoding(result.2);
let data = StoredData {
value,
timestamp: Timestamp::from_str(&result.1).unwrap(), // @TODO: remove the unwrap()
Expand Down
2 changes: 1 addition & 1 deletion 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.into())),
.map(|b| Value::from(b.payload).with_encoding(b.encoding)),
qid: msg.id,
zid,
primitives,
Expand Down
14 changes: 10 additions & 4 deletions zenoh/src/publication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,11 @@ impl SampleBuilderTrait for DeleteBuilder<'_, '_> {
}

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

fn with_payload<IntoPayload>(self, payload: IntoPayload) -> Self
Expand Down Expand Up @@ -779,8 +782,11 @@ impl SampleBuilderTrait for PutPublication<'_> {
}

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

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

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

fn with_payload<IntoPayload>(self, payload: IntoPayload) -> Self
where
IntoPayload: Into<Payload>,
{
fn with_payload<T: Into<Payload>>(self, payload: T) -> Self {
let value = Some(self.value.unwrap_or_default().with_payload(payload));
Self { value, ..self }
}
Expand Down
7 changes: 2 additions & 5 deletions zenoh/src/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,17 +366,14 @@ impl QoSBuilderTrait for ReplyBuilder<'_> {
}

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

fn with_payload<IntoPayload>(self, payload: IntoPayload) -> Self
where
IntoPayload: Into<Payload>,
{
fn with_payload<T: Into<Payload>>(self, payload: T) -> Self {
Self {
sample_builder: self.sample_builder.with_payload(payload),
..self
Expand Down
17 changes: 6 additions & 11 deletions zenoh/src/sample_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub trait QoSBuilderTrait {
}

pub trait TimestampBuilderTrait {
/// Sets of clears timestamp
/// Sets of clears timestamp
fn timestamp<T: Into<Option<Timestamp>>>(self, timestamp: T) -> Self;
}

Expand All @@ -56,11 +56,9 @@ pub trait SampleBuilderTrait {

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

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

impl ValueBuilderTrait for PutSampleBuilder {
fn with_encoding(self, encoding: Encoding) -> Self {
fn with_encoding<T: Into<Encoding>>(self, encoding: T) -> Self {
Self(SampleBuilder(Sample {
encoding,
encoding: encoding.into(),
..self.0 .0
}))
}
fn with_payload<IntoPayload>(self, payload: IntoPayload) -> Self
where
IntoPayload: Into<Payload>,
{
fn with_payload<T: Into<Payload>>(self, payload: T) -> Self {
Self(SampleBuilder(Sample {
payload: payload.into(),
..self.0 .0
Expand Down
12 changes: 6 additions & 6 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(self, encoding: Encoding) -> Self {
Self { encoding, ..self }
fn with_encoding<T: Into<Encoding>>(self, encoding: T) -> Self {
Self {
encoding: encoding.into(),
..self
}
}
fn with_payload<IntoPayload>(self, payload: IntoPayload) -> Self
where
IntoPayload: Into<Payload>,
{
fn with_payload<T: Into<Payload>>(self, payload: T) -> Self {
Self {
payload: payload.into(),
..self
Expand Down

0 comments on commit fb6509d

Please sign in to comment.