protojure/protoc-plugin

Support proto3 "presence" feature

ghaskins opened this issue · 2 comments

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.

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