From 7bc133d63859f7f8e61189a44a30ae8404ea0eae Mon Sep 17 00:00:00 2001 From: ChenYing Kuo Date: Tue, 23 Jan 2024 11:57:25 +0800 Subject: [PATCH 1/3] Able to set encoding to query value. Signed-off-by: ChenYing Kuo --- zenoh/src/query.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/zenoh/src/query.rs b/zenoh/src/query.rs index c4f3fb35e9..7a7c3c8ae0 100644 --- a/zenoh/src/query.rs +++ b/zenoh/src/query.rs @@ -306,6 +306,18 @@ impl<'a, 'b, Handler> GetBuilder<'a, 'b, Handler> { self } + /// Change the encoding of the query value. + #[inline] + pub fn encoding(mut self, encoding: IntoEncoding) -> Self + where + IntoEncoding: Into, + { + if let Some(ref mut value) = self.value { + value.encoding = encoding.into(); + } + self + } + #[zenoh_macros::unstable] pub fn with_attachment(mut self, attachment: Attachment) -> Self { self.attachment = Some(attachment); From 1700074555ee166c26155c78b89405959f5c071d Mon Sep 17 00:00:00 2001 From: ChenYing Kuo Date: Mon, 29 Jan 2024 11:30:33 +0800 Subject: [PATCH 2/3] Add empty value if there is no Value while adding encoding to query. Signed-off-by: ChenYing Kuo --- zenoh/src/query.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/zenoh/src/query.rs b/zenoh/src/query.rs index 7a7c3c8ae0..6ca73de661 100644 --- a/zenoh/src/query.rs +++ b/zenoh/src/query.rs @@ -312,8 +312,9 @@ impl<'a, 'b, Handler> GetBuilder<'a, 'b, Handler> { where IntoEncoding: Into, { - if let Some(ref mut value) = self.value { - value.encoding = encoding.into(); + match self.value { + Some(ref mut value) => value.encoding = encoding.into(), + None => self.value = Some(Value::empty().encoding(encoding.into())), } self } From b8f19265cf246adcecb3bd981f07fbae6da4903f Mon Sep 17 00:00:00 2001 From: ChenYing Kuo Date: Mon, 29 Jan 2024 11:57:00 +0800 Subject: [PATCH 3/3] Add some description about encoding for get in document. Signed-off-by: ChenYing Kuo --- zenoh/src/query.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/zenoh/src/query.rs b/zenoh/src/query.rs index 6ca73de661..cc70021013 100644 --- a/zenoh/src/query.rs +++ b/zenoh/src/query.rs @@ -297,6 +297,7 @@ impl<'a, 'b, Handler> GetBuilder<'a, 'b, Handler> { } /// Set query value. + /// The existing value and encoding will be overwritten. #[inline] pub fn with_value(mut self, value: IntoValue) -> Self where @@ -306,7 +307,8 @@ impl<'a, 'b, Handler> GetBuilder<'a, 'b, Handler> { self } - /// Change the encoding of the query value. + /// Set the encoding of the existing query value. + /// The empty value will be created if value is not set. #[inline] pub fn encoding(mut self, encoding: IntoEncoding) -> Self where