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 "presence" feature #49

Open
ghaskins opened this issue Nov 8, 2020 · 2 comments
Open

Support proto3 "presence" feature #49

ghaskins opened this issue Nov 8, 2020 · 2 comments

Comments

@ghaskins
Copy link
Member

ghaskins commented Nov 8, 2020

https://github.com/protocolbuffers/protobuf/blob/v3.12.0-rc1/docs/implementing_proto3_presence.md

@spencerwilson
Copy link

spencerwilson commented Oct 5, 2023

Since this issue was created, Protobuf 3.15.0 was released. Relevant changes:

My attention was drawn to this issue when I was struggling to access an optional field in emitted Clojure code:

  optional bool dryRun = 8;

was becoming

(= (get-in req [:grpc-params :-dryRun])
   {:dryRun false})

rather than the expected

(= (get-in req [:grpc-params :dryRun]) false)

(h/t to @sundbry, who explained: This is a consequence of the behavior described in implementing_proto3_presence.md: "When a user adds an optional field to proto3, this is internally rewritten as a one-field oneof, for backward-compatibility with reflection-based algorithms" The leading - is an accident of it being treated like oneof.)

This also comes through in the output of buf generate using the plugin in this repo:

% buf generate
Warning: plugin "clojure-wrapper" does not support required features.
  Feature "proto3 optional" is required by 1 file(s):
    my_file.proto

Among the work needed for this issue is upgrading the version of Google's plugin.proto to a more recent definition, one that includes the supported_features field.

In the meantime, I'll code against the synthetic oneof representation currently being generated by the plugin.

@ghaskins
Copy link
Member Author

ghaskins commented Oct 5, 2023

@spencerwilson I took a crack at the first part: protojure/google.protobuf#9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants