cmd/protoc-gen-go: correlate v1 ExtensionDesc with v2 ExtensionType
Unfortunately a good amount of code uses pointer comparisons on the
v1 ExtensionDesc to determine exactly which extension field is set,
rather than checking whether the extension descriptor semantically
describes the field that they are interested in.
To preserve this behavior in v1, we need a 1:1 mapping between
a v2 ExtensionType and a specific v1 ExtensionDesc.
Change-Id: I852b3cefb4585bd656e48e5adad6cc28795d02df
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/167759
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/cmd/protoc-gen-go/internal_gengo/reflect.go b/cmd/protoc-gen-go/internal_gengo/reflect.go
index 55fb42c..3e5300c 100644
--- a/cmd/protoc-gen-go/internal_gengo/reflect.go
+++ b/cmd/protoc-gen-go/internal_gengo/reflect.go
@@ -167,6 +167,9 @@
g.P("RawDescriptor: ", f.descriptorRawVar, ",")
g.P("GoTypes: ", goTypesVarName(f), ",")
g.P("DependencyIndexes: ", depIdxsVarName(f), ",")
+ if len(f.allExtensions) > 0 {
+ g.P("LegacyExtensions: ", extDecsVarName(f), ",")
+ }
if len(f.allEnums) > 0 {
g.P("EnumOutputTypes: ", enumTypesVarName(f), ",")
}
@@ -187,11 +190,6 @@
g.P("}")
}
- // Copy the local list of extension types into each global variable.
- for i, extension := range f.allExtensions {
- g.P(extensionVar(f.File, extension), ".Type = extensionTypes[", i, "]")
- }
-
// TODO: Add v2 registration and stop v1 registration in genInitFunction.
// The descriptor proto needs to register the option types with the
@@ -241,6 +239,9 @@
func messageTypesVarName(f *fileInfo) string {
return "xxx_" + f.GoDescriptorIdent.GoName + "_messageTypes"
}
+func extDecsVarName(f *fileInfo) string {
+ return "xxx_" + f.GoDescriptorIdent.GoName + "_extDescs"
+}
func initFuncName(f *protogen.File) string {
return "xxx_" + f.GoDescriptorIdent.GoName + "_init"
}