cmd/protoc-gen-go: used named types for special fields
Using a named fields gives us the flexibility to change the underlying
representation of special fields without needing to regenerate user code.
We add a named type for ExtensionFields, UnknownFields, and SizeCache.
Change-Id: I107cf82899850ea76665310ce79def60f0f7ab97
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/172402
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/internal/testprotos/test/test.pb.go b/internal/testprotos/test/test.pb.go
index 6eb43c8..263dd3a 100644
--- a/internal/testprotos/test/test.pb.go
+++ b/internal/testprotos/test/test.pb.go
@@ -315,8 +315,8 @@
// *TestAllTypes_OneofEnum
OneofField isTestAllTypes_OneofField `protobuf_oneof:"oneof_field"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
- XXX_unrecognized []byte `json:"-"`
- XXX_sizecache int32 `json:"-"`
+ XXX_unrecognized protoimpl.UnknownFields `json:"-"`
+ XXX_sizecache protoimpl.SizeCache `json:"-"`
}
func (x *TestAllTypes) Reset() {
@@ -1058,8 +1058,8 @@
// *TestDeprecatedMessage_DeprecatedOneofField
DeprecatedOneof isTestDeprecatedMessage_DeprecatedOneof `protobuf_oneof:"deprecated_oneof"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
- XXX_unrecognized []byte `json:"-"`
- XXX_sizecache int32 `json:"-"`
+ XXX_unrecognized protoimpl.UnknownFields `json:"-"`
+ XXX_sizecache protoimpl.SizeCache `json:"-"`
}
func (x *TestDeprecatedMessage) Reset() {
@@ -1126,11 +1126,11 @@
func (*TestDeprecatedMessage_DeprecatedOneofField) isTestDeprecatedMessage_DeprecatedOneof() {}
type ForeignMessage struct {
- C *int32 `protobuf:"varint,1,opt,name=c" json:"c,omitempty"`
- D *int32 `protobuf:"varint,2,opt,name=d" json:"d,omitempty"`
- XXX_NoUnkeyedLiteral struct{} `json:"-"`
- XXX_unrecognized []byte `json:"-"`
- XXX_sizecache int32 `json:"-"`
+ C *int32 `protobuf:"varint,1,opt,name=c" json:"c,omitempty"`
+ D *int32 `protobuf:"varint,2,opt,name=d" json:"d,omitempty"`
+ XXX_NoUnkeyedLiteral struct{} `json:"-"`
+ XXX_unrecognized protoimpl.UnknownFields `json:"-"`
+ XXX_sizecache protoimpl.SizeCache `json:"-"`
}
func (x *ForeignMessage) Reset() {
@@ -1171,9 +1171,9 @@
}
type TestReservedFields struct {
- XXX_NoUnkeyedLiteral struct{} `json:"-"`
- XXX_unrecognized []byte `json:"-"`
- XXX_sizecache int32 `json:"-"`
+ XXX_NoUnkeyedLiteral struct{} `json:"-"`
+ XXX_unrecognized protoimpl.UnknownFields `json:"-"`
+ XXX_sizecache protoimpl.SizeCache `json:"-"`
}
func (x *TestReservedFields) Reset() {
@@ -1200,10 +1200,10 @@
}
type TestAllExtensions struct {
- XXX_NoUnkeyedLiteral struct{} `json:"-"`
- XXX_InternalExtensions protoimpl.ExtensionFieldsV1 `json:"-"`
- XXX_unrecognized []byte `json:"-"`
- XXX_sizecache int32 `json:"-"`
+ XXX_NoUnkeyedLiteral struct{} `json:"-"`
+ XXX_InternalExtensions protoimpl.ExtensionFields `json:"-"`
+ XXX_unrecognized protoimpl.UnknownFields `json:"-"`
+ XXX_sizecache protoimpl.SizeCache `json:"-"`
}
func (x *TestAllExtensions) Reset() {
@@ -1239,10 +1239,10 @@
}
type OptionalGroupExtension struct {
- A *int32 `protobuf:"varint,17,opt,name=a" json:"a,omitempty"`
- XXX_NoUnkeyedLiteral struct{} `json:"-"`
- XXX_unrecognized []byte `json:"-"`
- XXX_sizecache int32 `json:"-"`
+ A *int32 `protobuf:"varint,17,opt,name=a" json:"a,omitempty"`
+ XXX_NoUnkeyedLiteral struct{} `json:"-"`
+ XXX_unrecognized protoimpl.UnknownFields `json:"-"`
+ XXX_sizecache protoimpl.SizeCache `json:"-"`
}
func (x *OptionalGroupExtension) Reset() {
@@ -1276,10 +1276,10 @@
}
type RepeatedGroupExtension struct {
- A *int32 `protobuf:"varint,47,opt,name=a" json:"a,omitempty"`
- XXX_NoUnkeyedLiteral struct{} `json:"-"`
- XXX_unrecognized []byte `json:"-"`
- XXX_sizecache int32 `json:"-"`
+ A *int32 `protobuf:"varint,47,opt,name=a" json:"a,omitempty"`
+ XXX_NoUnkeyedLiteral struct{} `json:"-"`
+ XXX_unrecognized protoimpl.UnknownFields `json:"-"`
+ XXX_sizecache protoimpl.SizeCache `json:"-"`
}
func (x *RepeatedGroupExtension) Reset() {
@@ -1313,9 +1313,9 @@
}
type TestNestedExtension struct {
- XXX_NoUnkeyedLiteral struct{} `json:"-"`
- XXX_unrecognized []byte `json:"-"`
- XXX_sizecache int32 `json:"-"`
+ XXX_NoUnkeyedLiteral struct{} `json:"-"`
+ XXX_unrecognized protoimpl.UnknownFields `json:"-"`
+ XXX_sizecache protoimpl.SizeCache `json:"-"`
}
func (x *TestNestedExtension) Reset() {
@@ -1342,10 +1342,10 @@
}
type TestRequired struct {
- RequiredField *int32 `protobuf:"varint,1,req,name=required_field,json=requiredField" json:"required_field,omitempty"`
- XXX_NoUnkeyedLiteral struct{} `json:"-"`
- XXX_unrecognized []byte `json:"-"`
- XXX_sizecache int32 `json:"-"`
+ RequiredField *int32 `protobuf:"varint,1,req,name=required_field,json=requiredField" json:"required_field,omitempty"`
+ XXX_NoUnkeyedLiteral struct{} `json:"-"`
+ XXX_unrecognized protoimpl.UnknownFields `json:"-"`
+ XXX_sizecache protoimpl.SizeCache `json:"-"`
}
func (x *TestRequired) Reset() {
@@ -1383,8 +1383,8 @@
RepeatedMessage []*TestRequired `protobuf:"bytes,2,rep,name=repeated_message,json=repeatedMessage" json:"repeated_message,omitempty"`
MapMessage map[int32]*TestRequired `protobuf:"bytes,3,rep,name=map_message,json=mapMessage" json:"map_message,omitempty" protobuf_key:"varint,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
- XXX_unrecognized []byte `json:"-"`
- XXX_sizecache int32 `json:"-"`
+ XXX_unrecognized protoimpl.UnknownFields `json:"-"`
+ XXX_sizecache protoimpl.SizeCache `json:"-"`
}
func (x *TestRequiredForeign) Reset() {
@@ -1435,8 +1435,8 @@
Optionalgroup *TestRequiredGroupFields_OptionalGroup `protobuf:"group,1,opt,name=OptionalGroup,json=optionalgroup" json:"optionalgroup,omitempty"`
Repeatedgroup []*TestRequiredGroupFields_RepeatedGroup `protobuf:"group,3,rep,name=RepeatedGroup,json=repeatedgroup" json:"repeatedgroup,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
- XXX_unrecognized []byte `json:"-"`
- XXX_sizecache int32 `json:"-"`
+ XXX_unrecognized protoimpl.UnknownFields `json:"-"`
+ XXX_sizecache protoimpl.SizeCache `json:"-"`
}
func (x *TestRequiredGroupFields) Reset() {
@@ -1478,9 +1478,9 @@
// Test that RPC services work.
type FooRequest struct {
- XXX_NoUnkeyedLiteral struct{} `json:"-"`
- XXX_unrecognized []byte `json:"-"`
- XXX_sizecache int32 `json:"-"`
+ XXX_NoUnkeyedLiteral struct{} `json:"-"`
+ XXX_unrecognized protoimpl.UnknownFields `json:"-"`
+ XXX_sizecache protoimpl.SizeCache `json:"-"`
}
func (x *FooRequest) Reset() {
@@ -1507,9 +1507,9 @@
}
type FooResponse struct {
- XXX_NoUnkeyedLiteral struct{} `json:"-"`
- XXX_unrecognized []byte `json:"-"`
- XXX_sizecache int32 `json:"-"`
+ XXX_NoUnkeyedLiteral struct{} `json:"-"`
+ XXX_unrecognized protoimpl.UnknownFields `json:"-"`
+ XXX_sizecache protoimpl.SizeCache `json:"-"`
}
func (x *FooResponse) Reset() {
@@ -1536,11 +1536,11 @@
}
type TestAllTypes_NestedMessage struct {
- A *int32 `protobuf:"varint,1,opt,name=a" json:"a,omitempty"`
- Corecursive *TestAllTypes `protobuf:"bytes,2,opt,name=corecursive" json:"corecursive,omitempty"`
- XXX_NoUnkeyedLiteral struct{} `json:"-"`
- XXX_unrecognized []byte `json:"-"`
- XXX_sizecache int32 `json:"-"`
+ A *int32 `protobuf:"varint,1,opt,name=a" json:"a,omitempty"`
+ Corecursive *TestAllTypes `protobuf:"bytes,2,opt,name=corecursive" json:"corecursive,omitempty"`
+ XXX_NoUnkeyedLiteral struct{} `json:"-"`
+ XXX_unrecognized protoimpl.UnknownFields `json:"-"`
+ XXX_sizecache protoimpl.SizeCache `json:"-"`
}
func (x *TestAllTypes_NestedMessage) Reset() {
@@ -1581,10 +1581,10 @@
}
type TestAllTypes_OptionalGroup struct {
- A *int32 `protobuf:"varint,17,opt,name=a" json:"a,omitempty"`
- XXX_NoUnkeyedLiteral struct{} `json:"-"`
- XXX_unrecognized []byte `json:"-"`
- XXX_sizecache int32 `json:"-"`
+ A *int32 `protobuf:"varint,17,opt,name=a" json:"a,omitempty"`
+ XXX_NoUnkeyedLiteral struct{} `json:"-"`
+ XXX_unrecognized protoimpl.UnknownFields `json:"-"`
+ XXX_sizecache protoimpl.SizeCache `json:"-"`
}
func (x *TestAllTypes_OptionalGroup) Reset() {
@@ -1618,10 +1618,10 @@
}
type TestAllTypes_RepeatedGroup struct {
- A *int32 `protobuf:"varint,47,opt,name=a" json:"a,omitempty"`
- XXX_NoUnkeyedLiteral struct{} `json:"-"`
- XXX_unrecognized []byte `json:"-"`
- XXX_sizecache int32 `json:"-"`
+ A *int32 `protobuf:"varint,47,opt,name=a" json:"a,omitempty"`
+ XXX_NoUnkeyedLiteral struct{} `json:"-"`
+ XXX_unrecognized protoimpl.UnknownFields `json:"-"`
+ XXX_sizecache protoimpl.SizeCache `json:"-"`
}
func (x *TestAllTypes_RepeatedGroup) Reset() {
@@ -1655,10 +1655,10 @@
}
type TestRequiredGroupFields_OptionalGroup struct {
- A *int32 `protobuf:"varint,2,req,name=a" json:"a,omitempty"`
- XXX_NoUnkeyedLiteral struct{} `json:"-"`
- XXX_unrecognized []byte `json:"-"`
- XXX_sizecache int32 `json:"-"`
+ A *int32 `protobuf:"varint,2,req,name=a" json:"a,omitempty"`
+ XXX_NoUnkeyedLiteral struct{} `json:"-"`
+ XXX_unrecognized protoimpl.UnknownFields `json:"-"`
+ XXX_sizecache protoimpl.SizeCache `json:"-"`
}
func (x *TestRequiredGroupFields_OptionalGroup) Reset() {
@@ -1692,10 +1692,10 @@
}
type TestRequiredGroupFields_RepeatedGroup struct {
- A *int32 `protobuf:"varint,4,req,name=a" json:"a,omitempty"`
- XXX_NoUnkeyedLiteral struct{} `json:"-"`
- XXX_unrecognized []byte `json:"-"`
- XXX_sizecache int32 `json:"-"`
+ A *int32 `protobuf:"varint,4,req,name=a" json:"a,omitempty"`
+ XXX_NoUnkeyedLiteral struct{} `json:"-"`
+ XXX_unrecognized protoimpl.UnknownFields `json:"-"`
+ XXX_sizecache protoimpl.SizeCache `json:"-"`
}
func (x *TestRequiredGroupFields_RepeatedGroup) Reset() {