-
Notifications
You must be signed in to change notification settings - Fork 9
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
isSet or isNull flag for optional values? #21
Comments
There is no way to differentiate between a field that was not set and a field that was set to the default value. Moreover the application should not differentiate between this two cases. |
I think what:
and
are unrelated things. proto3 deprecates specifying of default values, that's all. Optional values is not deprecated by itself.
But here is no way to check this. Related discussion: msoucy/dproto#63 (comment) |
I'll take a short pause to sort out more. Very strange it actually looks for me |
Yep, my case is unability to check that some message is set or not. Description of C++ version of proto3:
|
There is a difference between scalar (single) fields and message (complex) fields. protoc3 removes the For messages, when you use generate the D definition as class, you can still use In general, I think that the application should not use |
Mmm.. why? Google disagreed with it (above) (I use structs)
This is also my case. I move from proto2 (provided by dproto) because it contains unresolved significant bug (msoucy/dproto#96) |
Google does not define the implementation details. I think that it will be a mistake to just port the C++ implementation. Should I/you close this issue? |
No, no. I not agreed.
Yes. But protocol provides information about set or not for any element and API can provide this too (maybe only for messages as in Google's C++ API to avoid creation of schemes that other libraries do not understand). I know widely used
Currently it can not be converted into proto3 to use with D because |
Not any element, scalar elements have no message Node {
required sint64 id = 1;
// Parallel arrays.
repeated uint32 keys = 2 [packed = true]; // String IDs.
repeated uint32 vals = 3 [packed = true]; // String IDs.
optional Info info = 4; // May be omitted in omitmeta
required sint64 lat = 8;
required sint64 lon = 9;
}
Instead of |
Maybe or maybe not - I just will never know that the data was read incorrectly by discussed package: if we remember that defaults in proto3 deprecated and zeroes is a very common meaning of something, then this is a problem |
I checked - that also is implemented in Dart and maybe another lanugages which I don't know. |
I don't quite get what you mean by that. By design Protobuf requires that the application should cope with default values. Otherwise in case of removing a field from the message definition will break the backward compatibility contract. |
Maybe they want to be API compatible with |
Custom default values is deprecated in proto3. And this package is not provides ability to check
That is, we also need to be able to check message fields for their set or not.
I think what this is issue, not Google's recommended design. |
This is by design as described in here. Quote:
The highlighted part is the contract that the application must fulfill. I see no reason why this should not apply for complex types as well. |
(Perhaps I misunderstand how defaultValue!Info works.) Message with all zeroed scalars: scalars should be treated as valid zeroes or it means what message was not passed by wire at all? |
As I sad the application should cope with this uncertainty. An old application should still function even if it receives data where a field is missing because in meantime it was deprecated. The protobuf contract is that the application should consider that any field can be missing (deprecated) and it is applications job to sensible react on that and decide whether it can continue or not. This is the so called forward compatibility. If you still insist on the possibility that a field is missing on propose, then the best solution is to generate that field type as |
I do not think that memory is more important than logical consistency of processed data. Ok, maybe someone will find this discussion sometime and be able to say something another for support of my position about "set flag". Thank! |
To future archaeologists: I asked Google Protobuf team about this topic and they confirmed point of view that additional functions such as |
In proto3 all fields are "optional".
How to test what field is set?
Please add example
The text was updated successfully, but these errors were encountered: