internal/impl: add MessageState to every generated message
We define MessageState, which is essentially an atomically set *MessageInfo.
By nesting this as the first field in every generated message, we can
implement the reflective methods on a *MessageState when obtained by
unsafe casting a concrete message pointer as a *MessageState.
The MessageInfo held by MessageState provides additional Go type information
to interpret the memory that comes after the contents of the MessageState.
Since we are nesting a MessageState in every message,
the memory use of every message instance grows by 8B.
On average, the body of ProtoReflect grows from 133B to 202B (+50%).
However, this is offset by XXX_Methods, which is 108B and
will be removed in a future CL. Taking into account the eventual removal
of XXX_Methods, this is a net reduction of 25%.
name old time/op new time/op delta
Name/Value-4 70.3ns ± 2% 17.5ns ± 6% -75.08% (p=0.000 n=10+10)
Name/Nil-4 70.6ns ± 3% 33.4ns ± 2% -52.66% (p=0.000 n=10+10)
name old alloc/op new alloc/op delta
Name/Value-4 16.0B ± 0% 0.0B -100.00% (p=0.000 n=10+10)
Name/Nil-4 16.0B ± 0% 0.0B -100.00% (p=0.000 n=10+10)
name old allocs/op new allocs/op delta
Name/Value-4 1.00 ± 0% 0.00 -100.00% (p=0.000 n=10+10)
Name/Nil-4 1.00 ± 0% 0.00 -100.00% (p=0.000 n=10+10)
Change-Id: I92bd58dc681c57c92612fd5ba7fc066aea34e95a
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/185460
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/encoding/testprotos/pb2/test.pb.go b/encoding/testprotos/pb2/test.pb.go
index 49cf8e8..1cadf09 100644
--- a/encoding/testprotos/pb2/test.pb.go
+++ b/encoding/testprotos/pb2/test.pb.go
@@ -133,6 +133,7 @@
// Scalars contains optional scalar fields.
type Scalars struct {
+ state protoimpl.MessageState
OptBool *bool `protobuf:"varint,1,opt,name=opt_bool,json=optBool" json:"opt_bool,omitempty"`
OptInt32 *int32 `protobuf:"varint,2,opt,name=opt_int32,json=optInt32" json:"opt_int32,omitempty"`
OptInt64 *int64 `protobuf:"varint,3,opt,name=opt_int64,json=optInt64" json:"opt_int64,omitempty"`
@@ -163,10 +164,18 @@
func (*Scalars) ProtoMessage() {}
func (x *Scalars) ProtoReflect() protoreflect.Message {
- return file_pb2_test_proto_msgTypes[0].MessageOf(x)
+ mi := &file_pb2_test_proto_msgTypes[0]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
}
-func (m *Scalars) XXX_Methods() *protoiface.Methods {
+func (x *Scalars) XXX_Methods() *protoiface.Methods {
return file_pb2_test_proto_msgTypes[0].Methods()
}
@@ -282,6 +291,7 @@
// Message contains enum fields.
type Enums struct {
+ state protoimpl.MessageState
OptEnum *Enum `protobuf:"varint,1,opt,name=opt_enum,json=optEnum,enum=pb2.Enum" json:"opt_enum,omitempty"`
RptEnum []Enum `protobuf:"varint,2,rep,name=rpt_enum,json=rptEnum,enum=pb2.Enum" json:"rpt_enum,omitempty"`
OptNestedEnum *Enums_NestedEnum `protobuf:"varint,3,opt,name=opt_nested_enum,json=optNestedEnum,enum=pb2.Enums_NestedEnum" json:"opt_nested_enum,omitempty"`
@@ -301,10 +311,18 @@
func (*Enums) ProtoMessage() {}
func (x *Enums) ProtoReflect() protoreflect.Message {
- return file_pb2_test_proto_msgTypes[1].MessageOf(x)
+ mi := &file_pb2_test_proto_msgTypes[1]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
}
-func (m *Enums) XXX_Methods() *protoiface.Methods {
+func (x *Enums) XXX_Methods() *protoiface.Methods {
return file_pb2_test_proto_msgTypes[1].Methods()
}
@@ -343,6 +361,7 @@
// Message contains repeated fields.
type Repeats struct {
+ state protoimpl.MessageState
RptBool []bool `protobuf:"varint,1,rep,name=rpt_bool,json=rptBool" json:"rpt_bool,omitempty"`
RptInt32 []int32 `protobuf:"varint,2,rep,name=rpt_int32,json=rptInt32" json:"rpt_int32,omitempty"`
RptInt64 []int64 `protobuf:"varint,3,rep,name=rpt_int64,json=rptInt64" json:"rpt_int64,omitempty"`
@@ -367,10 +386,18 @@
func (*Repeats) ProtoMessage() {}
func (x *Repeats) ProtoReflect() protoreflect.Message {
- return file_pb2_test_proto_msgTypes[2].MessageOf(x)
+ mi := &file_pb2_test_proto_msgTypes[2]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
}
-func (m *Repeats) XXX_Methods() *protoiface.Methods {
+func (x *Repeats) XXX_Methods() *protoiface.Methods {
return file_pb2_test_proto_msgTypes[2].Methods()
}
@@ -444,6 +471,7 @@
// Message type used as submessage.
type Nested struct {
+ state protoimpl.MessageState
OptString *string `protobuf:"bytes,1,opt,name=opt_string,json=optString" json:"opt_string,omitempty"`
OptNested *Nested `protobuf:"bytes,2,opt,name=opt_nested,json=optNested" json:"opt_nested,omitempty"`
sizeCache protoimpl.SizeCache
@@ -461,10 +489,18 @@
func (*Nested) ProtoMessage() {}
func (x *Nested) ProtoReflect() protoreflect.Message {
- return file_pb2_test_proto_msgTypes[3].MessageOf(x)
+ mi := &file_pb2_test_proto_msgTypes[3]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
}
-func (m *Nested) XXX_Methods() *protoiface.Methods {
+func (x *Nested) XXX_Methods() *protoiface.Methods {
return file_pb2_test_proto_msgTypes[3].Methods()
}
@@ -489,6 +525,7 @@
// Message contains message and group fields.
type Nests struct {
+ state protoimpl.MessageState
OptNested *Nested `protobuf:"bytes,1,opt,name=opt_nested,json=optNested" json:"opt_nested,omitempty"`
Optgroup *Nests_OptGroup `protobuf:"group,2,opt,name=OptGroup,json=optgroup" json:"optgroup,omitempty"`
RptNested []*Nested `protobuf:"bytes,4,rep,name=rpt_nested,json=rptNested" json:"rpt_nested,omitempty"`
@@ -508,10 +545,18 @@
func (*Nests) ProtoMessage() {}
func (x *Nests) ProtoReflect() protoreflect.Message {
- return file_pb2_test_proto_msgTypes[4].MessageOf(x)
+ mi := &file_pb2_test_proto_msgTypes[4]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
}
-func (m *Nests) XXX_Methods() *protoiface.Methods {
+func (x *Nests) XXX_Methods() *protoiface.Methods {
return file_pb2_test_proto_msgTypes[4].Methods()
}
@@ -550,6 +595,7 @@
// Message contains required fields.
type Requireds struct {
+ state protoimpl.MessageState
ReqBool *bool `protobuf:"varint,1,req,name=req_bool,json=reqBool" json:"req_bool,omitempty"`
ReqSfixed64 *int64 `protobuf:"fixed64,2,req,name=req_sfixed64,json=reqSfixed64" json:"req_sfixed64,omitempty"`
ReqDouble *float64 `protobuf:"fixed64,3,req,name=req_double,json=reqDouble" json:"req_double,omitempty"`
@@ -571,10 +617,18 @@
func (*Requireds) ProtoMessage() {}
func (x *Requireds) ProtoReflect() protoreflect.Message {
- return file_pb2_test_proto_msgTypes[5].MessageOf(x)
+ mi := &file_pb2_test_proto_msgTypes[5]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
}
-func (m *Requireds) XXX_Methods() *protoiface.Methods {
+func (x *Requireds) XXX_Methods() *protoiface.Methods {
return file_pb2_test_proto_msgTypes[5].Methods()
}
@@ -627,6 +681,7 @@
// Message contains both required and optional fields.
type PartialRequired struct {
+ state protoimpl.MessageState
ReqString *string `protobuf:"bytes,1,req,name=req_string,json=reqString" json:"req_string,omitempty"`
OptString *string `protobuf:"bytes,2,opt,name=opt_string,json=optString" json:"opt_string,omitempty"`
sizeCache protoimpl.SizeCache
@@ -644,10 +699,18 @@
func (*PartialRequired) ProtoMessage() {}
func (x *PartialRequired) ProtoReflect() protoreflect.Message {
- return file_pb2_test_proto_msgTypes[6].MessageOf(x)
+ mi := &file_pb2_test_proto_msgTypes[6]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
}
-func (m *PartialRequired) XXX_Methods() *protoiface.Methods {
+func (x *PartialRequired) XXX_Methods() *protoiface.Methods {
return file_pb2_test_proto_msgTypes[6].Methods()
}
@@ -671,6 +734,7 @@
}
type NestedWithRequired struct {
+ state protoimpl.MessageState
ReqString *string `protobuf:"bytes,1,req,name=req_string,json=reqString" json:"req_string,omitempty"`
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
@@ -687,10 +751,18 @@
func (*NestedWithRequired) ProtoMessage() {}
func (x *NestedWithRequired) ProtoReflect() protoreflect.Message {
- return file_pb2_test_proto_msgTypes[7].MessageOf(x)
+ mi := &file_pb2_test_proto_msgTypes[7]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
}
-func (m *NestedWithRequired) XXX_Methods() *protoiface.Methods {
+func (x *NestedWithRequired) XXX_Methods() *protoiface.Methods {
return file_pb2_test_proto_msgTypes[7].Methods()
}
@@ -707,6 +779,7 @@
}
type IndirectRequired struct {
+ state protoimpl.MessageState
OptNested *NestedWithRequired `protobuf:"bytes,1,opt,name=opt_nested,json=optNested" json:"opt_nested,omitempty"`
RptNested []*NestedWithRequired `protobuf:"bytes,2,rep,name=rpt_nested,json=rptNested" json:"rpt_nested,omitempty"`
StrToNested map[string]*NestedWithRequired `protobuf:"bytes,3,rep,name=str_to_nested,json=strToNested" json:"str_to_nested,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
@@ -728,10 +801,18 @@
func (*IndirectRequired) ProtoMessage() {}
func (x *IndirectRequired) ProtoReflect() protoreflect.Message {
- return file_pb2_test_proto_msgTypes[8].MessageOf(x)
+ mi := &file_pb2_test_proto_msgTypes[8]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
}
-func (m *IndirectRequired) XXX_Methods() *protoiface.Methods {
+func (x *IndirectRequired) XXX_Methods() *protoiface.Methods {
return file_pb2_test_proto_msgTypes[8].Methods()
}
@@ -786,6 +867,7 @@
func (*IndirectRequired_OneofNested) isIndirectRequired_Union() {}
type Extensions struct {
+ state protoimpl.MessageState
OptString *string `protobuf:"bytes,1,opt,name=opt_string,json=optString" json:"opt_string,omitempty"`
OptBool *bool `protobuf:"varint,101,opt,name=opt_bool,json=optBool" json:"opt_bool,omitempty"`
OptInt32 *int32 `protobuf:"varint,2,opt,name=opt_int32,json=optInt32" json:"opt_int32,omitempty"`
@@ -805,10 +887,18 @@
func (*Extensions) ProtoMessage() {}
func (x *Extensions) ProtoReflect() protoreflect.Message {
- return file_pb2_test_proto_msgTypes[9].MessageOf(x)
+ mi := &file_pb2_test_proto_msgTypes[9]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
}
-func (m *Extensions) XXX_Methods() *protoiface.Methods {
+func (x *Extensions) XXX_Methods() *protoiface.Methods {
return file_pb2_test_proto_msgTypes[9].Methods()
}
@@ -848,6 +938,7 @@
}
type ExtensionsContainer struct {
+ state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
@@ -863,10 +954,18 @@
func (*ExtensionsContainer) ProtoMessage() {}
func (x *ExtensionsContainer) ProtoReflect() protoreflect.Message {
- return file_pb2_test_proto_msgTypes[10].MessageOf(x)
+ mi := &file_pb2_test_proto_msgTypes[10]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
}
-func (m *ExtensionsContainer) XXX_Methods() *protoiface.Methods {
+func (x *ExtensionsContainer) XXX_Methods() *protoiface.Methods {
return file_pb2_test_proto_msgTypes[10].Methods()
}
@@ -876,6 +975,7 @@
}
type MessageSet struct {
+ state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
extensionFields protoimpl.ExtensionFields
@@ -892,10 +992,18 @@
func (*MessageSet) ProtoMessage() {}
func (x *MessageSet) ProtoReflect() protoreflect.Message {
- return file_pb2_test_proto_msgTypes[11].MessageOf(x)
+ mi := &file_pb2_test_proto_msgTypes[11]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
}
-func (m *MessageSet) XXX_Methods() *protoiface.Methods {
+func (x *MessageSet) XXX_Methods() *protoiface.Methods {
return file_pb2_test_proto_msgTypes[11].Methods()
}
@@ -914,6 +1022,7 @@
}
type MessageSetExtension struct {
+ state protoimpl.MessageState
OptString *string `protobuf:"bytes,1,opt,name=opt_string,json=optString" json:"opt_string,omitempty"`
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
@@ -930,10 +1039,18 @@
func (*MessageSetExtension) ProtoMessage() {}
func (x *MessageSetExtension) ProtoReflect() protoreflect.Message {
- return file_pb2_test_proto_msgTypes[12].MessageOf(x)
+ mi := &file_pb2_test_proto_msgTypes[12]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
}
-func (m *MessageSetExtension) XXX_Methods() *protoiface.Methods {
+func (x *MessageSetExtension) XXX_Methods() *protoiface.Methods {
return file_pb2_test_proto_msgTypes[12].Methods()
}
@@ -950,6 +1067,7 @@
}
type FakeMessageSet struct {
+ state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
extensionFields protoimpl.ExtensionFields
@@ -966,10 +1084,18 @@
func (*FakeMessageSet) ProtoMessage() {}
func (x *FakeMessageSet) ProtoReflect() protoreflect.Message {
- return file_pb2_test_proto_msgTypes[13].MessageOf(x)
+ mi := &file_pb2_test_proto_msgTypes[13]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
}
-func (m *FakeMessageSet) XXX_Methods() *protoiface.Methods {
+func (x *FakeMessageSet) XXX_Methods() *protoiface.Methods {
return file_pb2_test_proto_msgTypes[13].Methods()
}
@@ -988,6 +1114,7 @@
}
type FakeMessageSetExtension struct {
+ state protoimpl.MessageState
OptString *string `protobuf:"bytes,1,opt,name=opt_string,json=optString" json:"opt_string,omitempty"`
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
@@ -1004,10 +1131,18 @@
func (*FakeMessageSetExtension) ProtoMessage() {}
func (x *FakeMessageSetExtension) ProtoReflect() protoreflect.Message {
- return file_pb2_test_proto_msgTypes[14].MessageOf(x)
+ mi := &file_pb2_test_proto_msgTypes[14]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
}
-func (m *FakeMessageSetExtension) XXX_Methods() *protoiface.Methods {
+func (x *FakeMessageSetExtension) XXX_Methods() *protoiface.Methods {
return file_pb2_test_proto_msgTypes[14].Methods()
}
@@ -1025,6 +1160,7 @@
// Message contains well-known type fields.
type KnownTypes struct {
+ state protoimpl.MessageState
OptBool *wrapperspb.BoolValue `protobuf:"bytes,1,opt,name=opt_bool,json=optBool" json:"opt_bool,omitempty"`
OptInt32 *wrapperspb.Int32Value `protobuf:"bytes,2,opt,name=opt_int32,json=optInt32" json:"opt_int32,omitempty"`
OptInt64 *wrapperspb.Int64Value `protobuf:"bytes,3,opt,name=opt_int64,json=optInt64" json:"opt_int64,omitempty"`
@@ -1058,10 +1194,18 @@
func (*KnownTypes) ProtoMessage() {}
func (x *KnownTypes) ProtoReflect() protoreflect.Message {
- return file_pb2_test_proto_msgTypes[15].MessageOf(x)
+ mi := &file_pb2_test_proto_msgTypes[15]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
}
-func (m *KnownTypes) XXX_Methods() *protoiface.Methods {
+func (x *KnownTypes) XXX_Methods() *protoiface.Methods {
return file_pb2_test_proto_msgTypes[15].Methods()
}
@@ -1197,6 +1341,7 @@
}
type Nests_OptGroup struct {
+ state protoimpl.MessageState
OptString *string `protobuf:"bytes,1,opt,name=opt_string,json=optString" json:"opt_string,omitempty"`
OptNested *Nested `protobuf:"bytes,2,opt,name=opt_nested,json=optNested" json:"opt_nested,omitempty"`
Optnestedgroup *Nests_OptGroup_OptNestedGroup `protobuf:"group,3,opt,name=OptNestedGroup,json=optnestedgroup" json:"optnestedgroup,omitempty"`
@@ -1215,10 +1360,18 @@
func (*Nests_OptGroup) ProtoMessage() {}
func (x *Nests_OptGroup) ProtoReflect() protoreflect.Message {
- return file_pb2_test_proto_msgTypes[16].MessageOf(x)
+ mi := &file_pb2_test_proto_msgTypes[16]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
}
-func (m *Nests_OptGroup) XXX_Methods() *protoiface.Methods {
+func (x *Nests_OptGroup) XXX_Methods() *protoiface.Methods {
return file_pb2_test_proto_msgTypes[16].Methods()
}
@@ -1249,6 +1402,7 @@
}
type Nests_RptGroup struct {
+ state protoimpl.MessageState
RptString []string `protobuf:"bytes,1,rep,name=rpt_string,json=rptString" json:"rpt_string,omitempty"`
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
@@ -1265,10 +1419,18 @@
func (*Nests_RptGroup) ProtoMessage() {}
func (x *Nests_RptGroup) ProtoReflect() protoreflect.Message {
- return file_pb2_test_proto_msgTypes[17].MessageOf(x)
+ mi := &file_pb2_test_proto_msgTypes[17]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
}
-func (m *Nests_RptGroup) XXX_Methods() *protoiface.Methods {
+func (x *Nests_RptGroup) XXX_Methods() *protoiface.Methods {
return file_pb2_test_proto_msgTypes[17].Methods()
}
@@ -1285,6 +1447,7 @@
}
type Nests_OptGroup_OptNestedGroup struct {
+ state protoimpl.MessageState
OptFixed32 *uint32 `protobuf:"fixed32,1,opt,name=opt_fixed32,json=optFixed32" json:"opt_fixed32,omitempty"`
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
@@ -1301,10 +1464,18 @@
func (*Nests_OptGroup_OptNestedGroup) ProtoMessage() {}
func (x *Nests_OptGroup_OptNestedGroup) ProtoReflect() protoreflect.Message {
- return file_pb2_test_proto_msgTypes[18].MessageOf(x)
+ mi := &file_pb2_test_proto_msgTypes[18]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
}
-func (m *Nests_OptGroup_OptNestedGroup) XXX_Methods() *protoiface.Methods {
+func (x *Nests_OptGroup_OptNestedGroup) XXX_Methods() *protoiface.Methods {
return file_pb2_test_proto_msgTypes[18].Methods()
}
@@ -2043,9 +2214,11 @@
if !protoimpl.UnsafeEnabled {
file_pb2_test_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Scalars); i {
- case 15:
- return &v.sizeCache
+ case 0:
+ return &v.state
case 16:
+ return &v.sizeCache
+ case 17:
return &v.unknownFields
default:
return nil
@@ -2053,9 +2226,11 @@
}
file_pb2_test_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Enums); i {
- case 4:
- return &v.sizeCache
+ case 0:
+ return &v.state
case 5:
+ return &v.sizeCache
+ case 6:
return &v.unknownFields
default:
return nil
@@ -2063,9 +2238,11 @@
}
file_pb2_test_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Repeats); i {
- case 9:
- return &v.sizeCache
+ case 0:
+ return &v.state
case 10:
+ return &v.sizeCache
+ case 11:
return &v.unknownFields
default:
return nil
@@ -2073,9 +2250,11 @@
}
file_pb2_test_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Nested); i {
- case 2:
- return &v.sizeCache
+ case 0:
+ return &v.state
case 3:
+ return &v.sizeCache
+ case 4:
return &v.unknownFields
default:
return nil
@@ -2083,9 +2262,11 @@
}
file_pb2_test_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Nests); i {
- case 4:
- return &v.sizeCache
+ case 0:
+ return &v.state
case 5:
+ return &v.sizeCache
+ case 6:
return &v.unknownFields
default:
return nil
@@ -2093,9 +2274,11 @@
}
file_pb2_test_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Requireds); i {
- case 6:
- return &v.sizeCache
+ case 0:
+ return &v.state
case 7:
+ return &v.sizeCache
+ case 8:
return &v.unknownFields
default:
return nil
@@ -2103,9 +2286,11 @@
}
file_pb2_test_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*PartialRequired); i {
- case 2:
- return &v.sizeCache
+ case 0:
+ return &v.state
case 3:
+ return &v.sizeCache
+ case 4:
return &v.unknownFields
default:
return nil
@@ -2113,9 +2298,11 @@
}
file_pb2_test_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*NestedWithRequired); i {
- case 1:
- return &v.sizeCache
+ case 0:
+ return &v.state
case 2:
+ return &v.sizeCache
+ case 3:
return &v.unknownFields
default:
return nil
@@ -2123,9 +2310,11 @@
}
file_pb2_test_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*IndirectRequired); i {
- case 4:
- return &v.sizeCache
+ case 0:
+ return &v.state
case 5:
+ return &v.sizeCache
+ case 6:
return &v.unknownFields
default:
return nil
@@ -2133,11 +2322,13 @@
}
file_pb2_test_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Extensions); i {
- case 3:
- return &v.sizeCache
+ case 0:
+ return &v.state
case 4:
- return &v.unknownFields
+ return &v.sizeCache
case 5:
+ return &v.unknownFields
+ case 6:
return &v.extensionFields
default:
return nil
@@ -2146,8 +2337,10 @@
file_pb2_test_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ExtensionsContainer); i {
case 0:
- return &v.sizeCache
+ return &v.state
case 1:
+ return &v.sizeCache
+ case 2:
return &v.unknownFields
default:
return nil
@@ -2156,10 +2349,12 @@
file_pb2_test_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*MessageSet); i {
case 0:
- return &v.sizeCache
+ return &v.state
case 1:
- return &v.unknownFields
+ return &v.sizeCache
case 2:
+ return &v.unknownFields
+ case 3:
return &v.extensionFields
default:
return nil
@@ -2167,9 +2362,11 @@
}
file_pb2_test_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*MessageSetExtension); i {
- case 1:
- return &v.sizeCache
+ case 0:
+ return &v.state
case 2:
+ return &v.sizeCache
+ case 3:
return &v.unknownFields
default:
return nil
@@ -2178,10 +2375,12 @@
file_pb2_test_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*FakeMessageSet); i {
case 0:
- return &v.sizeCache
+ return &v.state
case 1:
- return &v.unknownFields
+ return &v.sizeCache
case 2:
+ return &v.unknownFields
+ case 3:
return &v.extensionFields
default:
return nil
@@ -2189,9 +2388,11 @@
}
file_pb2_test_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*FakeMessageSetExtension); i {
- case 1:
- return &v.sizeCache
+ case 0:
+ return &v.state
case 2:
+ return &v.sizeCache
+ case 3:
return &v.unknownFields
default:
return nil
@@ -2199,9 +2400,11 @@
}
file_pb2_test_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*KnownTypes); i {
- case 18:
- return &v.sizeCache
+ case 0:
+ return &v.state
case 19:
+ return &v.sizeCache
+ case 20:
return &v.unknownFields
default:
return nil
@@ -2209,9 +2412,11 @@
}
file_pb2_test_proto_msgTypes[16].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Nests_OptGroup); i {
- case 3:
- return &v.sizeCache
+ case 0:
+ return &v.state
case 4:
+ return &v.sizeCache
+ case 5:
return &v.unknownFields
default:
return nil
@@ -2219,9 +2424,11 @@
}
file_pb2_test_proto_msgTypes[17].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Nests_RptGroup); i {
- case 1:
- return &v.sizeCache
+ case 0:
+ return &v.state
case 2:
+ return &v.sizeCache
+ case 3:
return &v.unknownFields
default:
return nil
@@ -2229,9 +2436,11 @@
}
file_pb2_test_proto_msgTypes[18].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Nests_OptGroup_OptNestedGroup); i {
- case 1:
- return &v.sizeCache
+ case 0:
+ return &v.state
case 2:
+ return &v.sizeCache
+ case 3:
return &v.unknownFields
default:
return nil
diff --git a/encoding/testprotos/pb3/test.pb.go b/encoding/testprotos/pb3/test.pb.go
index 50ecdcc..411965e 100644
--- a/encoding/testprotos/pb3/test.pb.go
+++ b/encoding/testprotos/pb3/test.pb.go
@@ -112,6 +112,7 @@
// Scalars contains scalar field types.
type Scalars struct {
+ state protoimpl.MessageState
SBool bool `protobuf:"varint,1,opt,name=s_bool,json=sBool,proto3" json:"s_bool,omitempty"`
SInt32 int32 `protobuf:"varint,2,opt,name=s_int32,json=sInt32,proto3" json:"s_int32,omitempty"`
SInt64 int64 `protobuf:"varint,3,opt,name=s_int64,json=sInt64,proto3" json:"s_int64,omitempty"`
@@ -142,10 +143,18 @@
func (*Scalars) ProtoMessage() {}
func (x *Scalars) ProtoReflect() protoreflect.Message {
- return file_pb3_test_proto_msgTypes[0].MessageOf(x)
+ mi := &file_pb3_test_proto_msgTypes[0]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
}
-func (m *Scalars) XXX_Methods() *protoiface.Methods {
+func (x *Scalars) XXX_Methods() *protoiface.Methods {
return file_pb3_test_proto_msgTypes[0].Methods()
}
@@ -261,6 +270,7 @@
// Message contains enum fields.
type Enums struct {
+ state protoimpl.MessageState
SEnum Enum `protobuf:"varint,1,opt,name=s_enum,json=sEnum,proto3,enum=pb3.Enum" json:"s_enum,omitempty"`
SNestedEnum Enums_NestedEnum `protobuf:"varint,3,opt,name=s_nested_enum,json=sNestedEnum,proto3,enum=pb3.Enums_NestedEnum" json:"s_nested_enum,omitempty"`
sizeCache protoimpl.SizeCache
@@ -278,10 +288,18 @@
func (*Enums) ProtoMessage() {}
func (x *Enums) ProtoReflect() protoreflect.Message {
- return file_pb3_test_proto_msgTypes[1].MessageOf(x)
+ mi := &file_pb3_test_proto_msgTypes[1]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
}
-func (m *Enums) XXX_Methods() *protoiface.Methods {
+func (x *Enums) XXX_Methods() *protoiface.Methods {
return file_pb3_test_proto_msgTypes[1].Methods()
}
@@ -306,6 +324,7 @@
// Message contains nested message field.
type Nests struct {
+ state protoimpl.MessageState
SNested *Nested `protobuf:"bytes,2,opt,name=s_nested,json=sNested,proto3" json:"s_nested,omitempty"`
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
@@ -322,10 +341,18 @@
func (*Nests) ProtoMessage() {}
func (x *Nests) ProtoReflect() protoreflect.Message {
- return file_pb3_test_proto_msgTypes[2].MessageOf(x)
+ mi := &file_pb3_test_proto_msgTypes[2]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
}
-func (m *Nests) XXX_Methods() *protoiface.Methods {
+func (x *Nests) XXX_Methods() *protoiface.Methods {
return file_pb3_test_proto_msgTypes[2].Methods()
}
@@ -343,6 +370,7 @@
// Message type used as submessage.
type Nested struct {
+ state protoimpl.MessageState
SString string `protobuf:"bytes,1,opt,name=s_string,json=sString,proto3" json:"s_string,omitempty"`
SNested *Nested `protobuf:"bytes,2,opt,name=s_nested,json=sNested,proto3" json:"s_nested,omitempty"`
sizeCache protoimpl.SizeCache
@@ -360,10 +388,18 @@
func (*Nested) ProtoMessage() {}
func (x *Nested) ProtoReflect() protoreflect.Message {
- return file_pb3_test_proto_msgTypes[3].MessageOf(x)
+ mi := &file_pb3_test_proto_msgTypes[3]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
}
-func (m *Nested) XXX_Methods() *protoiface.Methods {
+func (x *Nested) XXX_Methods() *protoiface.Methods {
return file_pb3_test_proto_msgTypes[3].Methods()
}
@@ -388,6 +424,7 @@
// Message contains oneof field.
type Oneofs struct {
+ state protoimpl.MessageState
// Types that are valid to be assigned to Union:
// *Oneofs_OneofEnum
// *Oneofs_OneofString
@@ -408,10 +445,18 @@
func (*Oneofs) ProtoMessage() {}
func (x *Oneofs) ProtoReflect() protoreflect.Message {
- return file_pb3_test_proto_msgTypes[4].MessageOf(x)
+ mi := &file_pb3_test_proto_msgTypes[4]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
}
-func (m *Oneofs) XXX_Methods() *protoiface.Methods {
+func (x *Oneofs) XXX_Methods() *protoiface.Methods {
return file_pb3_test_proto_msgTypes[4].Methods()
}
@@ -472,6 +517,7 @@
// Message contains map fields.
type Maps struct {
+ state protoimpl.MessageState
Int32ToStr map[int32]string `protobuf:"bytes,1,rep,name=int32_to_str,json=int32ToStr,proto3" json:"int32_to_str,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
BoolToUint32 map[bool]uint32 `protobuf:"bytes,2,rep,name=bool_to_uint32,json=boolToUint32,proto3" json:"bool_to_uint32,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"`
Uint64ToEnum map[uint64]Enum `protobuf:"bytes,3,rep,name=uint64_to_enum,json=uint64ToEnum,proto3" json:"uint64_to_enum,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3,enum=pb3.Enum"`
@@ -492,10 +538,18 @@
func (*Maps) ProtoMessage() {}
func (x *Maps) ProtoReflect() protoreflect.Message {
- return file_pb3_test_proto_msgTypes[5].MessageOf(x)
+ mi := &file_pb3_test_proto_msgTypes[5]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
}
-func (m *Maps) XXX_Methods() *protoiface.Methods {
+func (x *Maps) XXX_Methods() *protoiface.Methods {
return file_pb3_test_proto_msgTypes[5].Methods()
}
@@ -541,6 +595,7 @@
// Message for testing json_name option.
type JSONNames struct {
+ state protoimpl.MessageState
SString string `protobuf:"bytes,1,opt,name=s_string,json=foo_bar,proto3" json:"s_string,omitempty"`
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
@@ -557,10 +612,18 @@
func (*JSONNames) ProtoMessage() {}
func (x *JSONNames) ProtoReflect() protoreflect.Message {
- return file_pb3_test_proto_msgTypes[6].MessageOf(x)
+ mi := &file_pb3_test_proto_msgTypes[6]
+ if protoimpl.UnsafeEnabled && x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
}
-func (m *JSONNames) XXX_Methods() *protoiface.Methods {
+func (x *JSONNames) XXX_Methods() *protoiface.Methods {
return file_pb3_test_proto_msgTypes[6].Methods()
}
@@ -748,9 +811,11 @@
if !protoimpl.UnsafeEnabled {
file_pb3_test_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Scalars); i {
- case 15:
- return &v.sizeCache
+ case 0:
+ return &v.state
case 16:
+ return &v.sizeCache
+ case 17:
return &v.unknownFields
default:
return nil
@@ -758,9 +823,11 @@
}
file_pb3_test_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Enums); i {
- case 2:
- return &v.sizeCache
+ case 0:
+ return &v.state
case 3:
+ return &v.sizeCache
+ case 4:
return &v.unknownFields
default:
return nil
@@ -768,16 +835,8 @@
}
file_pb3_test_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Nests); i {
- case 1:
- return &v.sizeCache
- case 2:
- return &v.unknownFields
- default:
- return nil
- }
- }
- file_pb3_test_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
- switch v := v.(*Nested); i {
+ case 0:
+ return &v.state
case 2:
return &v.sizeCache
case 3:
@@ -786,11 +845,25 @@
return nil
}
}
+ file_pb3_test_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
+ switch v := v.(*Nested); i {
+ case 0:
+ return &v.state
+ case 3:
+ return &v.sizeCache
+ case 4:
+ return &v.unknownFields
+ default:
+ return nil
+ }
+ }
file_pb3_test_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Oneofs); i {
- case 1:
- return &v.sizeCache
+ case 0:
+ return &v.state
case 2:
+ return &v.sizeCache
+ case 3:
return &v.unknownFields
default:
return nil
@@ -798,9 +871,11 @@
}
file_pb3_test_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Maps); i {
- case 5:
- return &v.sizeCache
+ case 0:
+ return &v.state
case 6:
+ return &v.sizeCache
+ case 7:
return &v.unknownFields
default:
return nil
@@ -808,9 +883,11 @@
}
file_pb3_test_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*JSONNames); i {
- case 1:
- return &v.sizeCache
+ case 0:
+ return &v.state
case 2:
+ return &v.sizeCache
+ case 3:
return &v.unknownFields
default:
return nil