-
Notifications
You must be signed in to change notification settings - Fork 109
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
Show instance not working for first/default enum values #445
Comments
For anyone still interested, this is a consequence of using proto3 without explicitly optional fields. Default scalar values in proto3 are indistinguishable from the field never having been explicitly set, so it would be semantically valid to skip the output of a default value field with text format. In fact, serialization officially does not include default scalar values even if they have been explicitly set (unless the field is explicitly marked as optional). |
Thank you for spelling that out. It's been a while since I've been close to this so I almost don't have an investment anymore, but.... It does seem like a bit of a workaround to define a field as Am I thinking about this in the wrong way, or is this just the cost of doing business? (i.e. the price to pay for defining complex types in a protobuf) |
In any version of proto, you never need to check whether a field was set or not, if it's OK to use the default value if a field was unset. Even in proto2 and the default for Protobuf Editions 2023, the default value will be returned for a field if it was not unset. I.e., if one ignores field presence, all versions of protobuf behave the same from the code's perspective; proto3 just lacks the ability to determine whether a field has a default value because it was set explicitly or if because it was cleared or was never set in the first place. |
I've got the following defined in a protobuf (proto3)
which I've generated into the following haskell code with the compiler
and when I use this in my test project and I try to show the whole record
but it doesn't print the
direction
field when I have it set to the first/default valueI think that I've removed all doubt that my custom code/protobuf has caused this behavior, and for some reason the generated haskell types are the culprit
The text was updated successfully, but these errors were encountered: