-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Able to set encoding to query value #656
Conversation
fe676b4
to
dde2932
Compare
Signed-off-by: ChenYing Kuo <[email protected]>
dde2932
to
7bc133d
Compare
If user miss the order of operations and set encoding before value, current code just silently ignores Unlike in let getbuilder = self
.session
.get(&zenoh_key)
.encoding(Encoding::Exact(KnownEncoding::AppCustom)); This still might be confusing, that the code below will lose the encoding set, but on the other hand this is how builders works: new value overrides old one. let getbuilder = self
.session
.get(&zenoh_key)
.encoding(Encoding::Exact(KnownEncoding::AppCustom))
.with_value(buf) OF course this should be specified in the documentation, that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see above: the problem that the code does nothing if optional value is not set. But value may be added later and this will be confusing that encoding
operation did nothing
Signed-off-by: ChenYing Kuo <[email protected]>
Signed-off-by: ChenYing Kuo <[email protected]>
Good idea. I've added some changes now. |
I'm still not convinced about the proposed changes. Let me take the problem for a more broad perspective. By definition a Value is tuple of At this point one may argue that this symmetry is not reflected in the PutBuilder and the Sample received by the subscriber. However, the main difference is that a put takes a mandatory Value while get doesn't. Therefore, encoding is guaranteed to always operate on a existing Value. With the proposed changes the guarantee is not upheld. Moreover, an To provide the sought after guarantee, the |
I tried to restrict setting encoding by adding new builder type (in fact by parametrizing existing builder, but that's the same thing). The result is not satisfying. Look at this piece of code: let mut query = req.state().0.get(&selector).consolidation(consolidation);
if !body.is_empty() {
let encoding: Encoding = req
.content_type()
.map(|m| m.to_string().into())
.unwrap_or_default();
query = query.with_value(Value::from(body).encoding(encoding));
} With different types for builders it compiles with error
This is expected: we can't anymore update builder differently depending on incoming parameters. |
My opinion on this is that:
TL;DR: I'm in favour of not having a |
We may follow this pattern in all builder methods which accepts complex objects. Maybe it can be convenient: let getbuilder = self
.session
.get(&zenoh_key)
.with_build_value() // switch to builder for Value
.payload("Foo")
.encoding(Encoding::Exact(KnownEncoding::AppCustom));
.res_with() // return to original builder
.timeout(100)
.res()?; This approach allows to use chain of calls specific for parameter type inside the chain of calls of main object. |
Linked it in issue #716 to continue discussion, closing this issue |
Currently, PutBuilder supports encoding
But now
get
doesn't support encoding, so we need to create value firstIt might be easier and cleaner for users to use
get
with encoding support.