all: implement support for proto3 optional semantics
In the upcoming 3.12.x release of protoc, the proto3 language will be
amended to support true presence for scalars. This CL adds support
to both the generator and runtime to support these semantics.
Newly added public API:
protogen.Plugin.SupportedFeatures
protoreflect.FieldDescriptor.HasPresence
protoreflect.FieldDescriptor.HasOptionalKeyword
protoreflect.OneofDescriptor.IsSynthetic
Change-Id: I7c86bf66d0ae56642109beb5f2132184593747ad
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/230698
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/compiler/protogen/protogen.go b/compiler/protogen/protogen.go
index 118be73..e3b9e7f 100644
--- a/compiler/protogen/protogen.go
+++ b/compiler/protogen/protogen.go
@@ -104,6 +104,11 @@
Files []*File
FilesByPath map[string]*File
+ // SupportedFeatures is the set of protobuf language features supported by
+ // this generator plugin. See the documentation for
+ // google.protobuf.CodeGeneratorResponse.supported_features for details.
+ SupportedFeatures uint64
+
fileReg *protoregistry.Files
enumsByName map[protoreflect.FullName]*Enum
messagesByName map[protoreflect.FullName]*Message
@@ -438,6 +443,9 @@
})
}
}
+ if gen.SupportedFeatures > 0 {
+ resp.SupportedFeatures = proto.Uint64(gen.SupportedFeatures)
+ }
return resp
}