Skip to content
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

Support proto3 default value for enums #30

Open
geekingfrog opened this issue Feb 21, 2018 · 6 comments
Open

Support proto3 default value for enums #30

geekingfrog opened this issue Feb 21, 2018 · 6 comments
Labels
Milestone

Comments

@geekingfrog
Copy link

Thanks for the project, really useful and overall nice to work with.
I have noticed a bug regarding default values. For an enum, if it's set to a default value, then it will not show up in the clojure structure, and when deserializing it, the resulting object will not have any value for the enum.

I have created a simple test case exhibiting the problem at https://github.com/geekingfrog/clojure-protobuf-bug-default-enum
There is a java reference which shows the correct behavior, and a simple clojure file to compare.

@oubiwann
Copy link
Member

Thanks for the ticket, and for minimal test case showing how to duplicate!

This may be what's behind #22 and #25 ...

@oubiwann oubiwann added the bug label Feb 24, 2018
@oubiwann
Copy link
Member

oubiwann commented Jul 3, 2018

This should now be fixed by @jvia’s PR #31 — thanks!

@oubiwann
Copy link
Member

oubiwann commented Jul 3, 2018

Actually, I take it back -- this issue will be addressed when #22 is fixed.

Nope; #22 was unrelated, really.

@oubiwann
Copy link
Member

oubiwann commented Jul 3, 2018

Digging into this more, looking at what the tutorial does here: https://clojusc.github.io/protobuf/current/1050-tutorial.html

If you walk through the setup, have imported the example classes (and inner classes), you can do this:

[protobuf.dev] λ=> (protobuf/create AddressBookProtos$Person$PhoneNumber {:number "1"})

Which gives this:

{:number "1", :type :home}

As you can see, the default is added for the enum value. I'll check your example code again next ...

@oubiwann
Copy link
Member

oubiwann commented Jul 3, 2018

Okay, so more details: the tutorial is proto2; your example is proto3. In the tutorial, the default value to use is indicated by the line optional PhoneType type = 2 [default = home];.

In proto3, the default for enums is specified by the rule "For enums, the default value is the first defined enum value, which must be 0."

The Java lib supports proto3, so the Clojure one can too. This actually isn't a bug, but a missing feature. I'll update the ticket.

@oubiwann oubiwann added feature and removed bug labels Jul 3, 2018
@oubiwann oubiwann changed the title Missing default enum values Support proto3 default value for enums Jul 3, 2018
@oubiwann
Copy link
Member

oubiwann commented Jul 3, 2018

I've added this ticket to a new epic ticket for providing full support for proto3.

@oubiwann oubiwann added this to the 1.2.0 milestone Jul 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants