Skip to content

Commit 971c712

Browse files
jhumpgopherbot
authored andcommitted
gofeatures: allow setting legacy_unmarshal_json_enum feature at file level
All of the other features, including custom features for C++ and Java, allow setting a file-wide default. This makes it easier to migrate proto2 files, so that the feature can be set at the file level instead of needing to manually annotate each enum element. This adds the same convenience to the (pb.go).legacy_unmarshal_json_enum feature that is defined in this repo. Change-Id: If3a925674a9daeed464b589747b7f78a0200118b Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/589336 Auto-Submit: Lasse Folger <lassefolger@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Lasse Folger <lassefolger@google.com> Reviewed-by: Michael Stapelberg <stapelberg@google.com>
1 parent 3b8611b commit 971c712

File tree

4 files changed

+379
-20
lines changed

4 files changed

+379
-20
lines changed

cmd/protoc-gen-go/testdata/protoeditions/legacy_enum.pb.go

Lines changed: 320 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2024 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
edition = "2023";
6+
7+
package goproto.protoc.protoeditions;
8+
9+
import "google/protobuf/go_features.proto";
10+
11+
option go_package = "google.golang.org/protobuf/cmd/protoc-gen-go/testdata/protoeditions";
12+
option features.(pb.go).legacy_unmarshal_json_enum = true;
13+
14+
// EnumTypeWithLegacyUnmarshalJSON comment.
15+
enum EnumTypeWithLegacyUnmarshalJSON {
16+
option features.enum_type = CLOSED;
17+
18+
// EnumTypeWithLegacyUnmarshalJSON_ONE comment.
19+
FIRST = 1;
20+
// EnumTypeWithLegacyUnmarshalJSON_TWO comment.
21+
SECOND = 2;
22+
}
23+
24+
message ContainerForNestedEnum {
25+
// NestedEnumType1A comment.
26+
enum NestedEnum {
27+
// NestedEnum_VALUE comment.
28+
VALUE = 0;
29+
}
30+
}
31+
32+
enum EnumWithoutUnmarshalJSON {
33+
option features.(pb.go).legacy_unmarshal_json_enum = false;
34+
35+
WITHOUT_UNMARSHAL_JSON_FOO = 0;
36+
WITHOUT_UNMARSHAL_JSON_BAR = 1;
37+
WITHOUT_UNMARSHAL_JSON_BAZ = 2;
38+
}

src/google/protobuf/go_features.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ message GoFeatures {
2222
optional bool legacy_unmarshal_json_enum = 1 [
2323
retention = RETENTION_RUNTIME,
2424
targets = TARGET_TYPE_ENUM,
25+
targets = TARGET_TYPE_FILE,
2526
feature_support = {
2627
edition_introduced: EDITION_2023,
2728
edition_deprecated: EDITION_2023,

0 commit comments

Comments
 (0)