Skip to content

Commit

Permalink
internal: generate extension numbers, fix editions parsing
Browse files Browse the repository at this point in the history
Before this commit, message-level Go editions features were not parsed
correctly.

Change-Id: I94ead5428fadae5fd70ed991fa405ce9388e9660
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/603015
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Stapelberg <stapelberg@google.com>
Reviewed-by: Lasse Folger <lassefolger@google.com>
  • Loading branch information
stapelberg authored and gopherbot committed Aug 6, 2024
1 parent 2a82025 commit 75479a3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
15 changes: 15 additions & 0 deletions internal/cmd/generate-protos/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ func generateIdentifiers(gen *protogen.Plugin, file *protogen.File) {

var processEnums func([]*protogen.Enum)
var processMessages func([]*protogen.Message)
var processExtensions func([]*protogen.Extension)
const protoreflectPackage = protogen.GoImportPath("google.golang.org/protobuf/reflect/protoreflect")
processEnums = func(enums []*protogen.Enum) {
for _, enum := range enums {
Expand Down Expand Up @@ -377,10 +378,24 @@ func generateIdentifiers(gen *protogen.Plugin, file *protogen.File) {

processEnums(message.Enums)
processMessages(message.Messages)
processExtensions(message.Extensions)
}
}
processExtensions = func(extensions []*protogen.Extension) {
if len(extensions) == 0 {
return
}

g.P("// Extension numbers")
g.P("const (")
for _, ext := range extensions {
g.P(ext.Extendee.GoIdent.GoName, "_", ext.GoName, "_ext_number ", protoreflectPackage.Ident("FieldNumber"), " = ", ext.Desc.Number())
}
g.P(")")
}
processEnums(file.Enums)
processMessages(file.Messages)
processExtensions(file.Extensions)
}

// generateSourceContextStringer generates the implementation for the
Expand Down
2 changes: 1 addition & 1 deletion internal/filedesc/editions.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func unmarshalFeatureSet(b []byte, parent EditionFeatures) EditionFeatures {
v, m := protowire.ConsumeBytes(b)
b = b[m:]
switch num {
case genid.GoFeatures_LegacyUnmarshalJsonEnum_field_number:
case genid.FeatureSet_Go_ext_number:
parent = unmarshalGoFeature(v, parent)
}
}
Expand Down
5 changes: 5 additions & 0 deletions internal/genid/go_features_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 75479a3

Please sign in to comment.