diff --git a/Makefile b/Makefile index 4c9f6c0a..1d655bf2 100644 --- a/Makefile +++ b/Makefile @@ -60,6 +60,7 @@ gen-testproto: get-grpc-testproto gen-wkt-testproto install testproto/empty/empty.proto \ testproto/pool/pool.proto \ testproto/pool/pool_with_slice_reuse.proto \ + testproto/pool/pool_with_map_reuse.proto \ testproto/pool/pool_with_oneof.proto \ testproto/proto3opt/opt.proto \ testproto/proto2/scalars.proto \ diff --git a/features/pool/pool.go b/features/pool/pool.go index 4f7efdca..c57202a6 100644 --- a/features/pool/pool.go +++ b/features/pool/pool.go @@ -68,6 +68,21 @@ func (p *pool) message(message *protogen.Message) { } p.P(fmt.Sprintf("f%d", len(saved)), ` := m.`, fieldName, `[:0]`) saved = append(saved, field) + } else if field.Desc.IsMap() { + switch field.Desc.MapValue().Kind() { + case protoreflect.MessageKind, protoreflect.GroupKind: + valueField := field.Message.Fields[1] + p.P(`for _, v := range m.`, fieldName, `{`) + if p.ShouldPool(valueField.Message) { + p.P(`v.ResetVT()`) + } else { + p.P(`v.Reset()`) + } + p.P(`}`) + } + p.P(`clear(m.`, fieldName, `)`) + p.P(fmt.Sprintf("f%d", len(saved)), ` := m.`, fieldName) + saved = append(saved, field) } else if field.Oneof != nil && !field.Oneof.Desc.IsSynthetic() { if p.ShouldPool(field.Message) { p.P(`if oneof, ok := m.`, field.Oneof.GoName, `.(*`, field.GoIdent, `); ok {`) diff --git a/testproto/pool/pool_test.go b/testproto/pool/pool_test.go index be9085fc..94403169 100644 --- a/testproto/pool/pool_test.go +++ b/testproto/pool/pool_test.go @@ -186,3 +186,22 @@ func Test_Pool_Optional(t *testing.T) { mFromPool := MemoryPoolExtensionFromVTPool() require.True(t, mFromPool.EqualVT(&MemoryPoolExtension{})) } + +func Test_Pool_Reuse_Map(t *testing.T) { + allocs := testing.AllocsPerRun(10, func() { + obj := MapReuseTest1FromVTPool() + if obj.GetIntToStringMap() == nil { + obj.IntToStringMap = make(map[int32]string) + } + obj.IntToStringMap[1] = "test1" + obj.IntToStringMap[2] = "test2" + obj.IntToStringMap[3] = "test3" + if obj.GetStringToEnumMap() == nil { + obj.StringToEnumMap = make(map[string]MapReuseTest1_TEST) + } + obj.StringToEnumMap["test1"] = MapReuseTest1_test1 + obj.StringToEnumMap["test2"] = MapReuseTest1_test2 + obj.ReturnToVTPool() + }) + require.Less(t, int(allocs), 1) +} diff --git a/testproto/pool/pool_with_map_reuse.pb.go b/testproto/pool/pool_with_map_reuse.pb.go new file mode 100644 index 00000000..8ce6b81d --- /dev/null +++ b/testproto/pool/pool_with_map_reuse.pb.go @@ -0,0 +1,411 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc v3.21.12 +// source: pool/pool_with_map_reuse.proto + +package pool + +import ( + _ "github.com/planetscale/vtprotobuf/vtproto" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type MapReuseTest1_TEST int32 + +const ( + MapReuseTest1_test1 MapReuseTest1_TEST = 0 + MapReuseTest1_test2 MapReuseTest1_TEST = 1 +) + +// Enum value maps for MapReuseTest1_TEST. +var ( + MapReuseTest1_TEST_name = map[int32]string{ + 0: "test1", + 1: "test2", + } + MapReuseTest1_TEST_value = map[string]int32{ + "test1": 0, + "test2": 1, + } +) + +func (x MapReuseTest1_TEST) Enum() *MapReuseTest1_TEST { + p := new(MapReuseTest1_TEST) + *p = x + return p +} + +func (x MapReuseTest1_TEST) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (MapReuseTest1_TEST) Descriptor() protoreflect.EnumDescriptor { + return file_pool_pool_with_map_reuse_proto_enumTypes[0].Descriptor() +} + +func (MapReuseTest1_TEST) Type() protoreflect.EnumType { + return &file_pool_pool_with_map_reuse_proto_enumTypes[0] +} + +func (x MapReuseTest1_TEST) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use MapReuseTest1_TEST.Descriptor instead. +func (MapReuseTest1_TEST) EnumDescriptor() ([]byte, []int) { + return file_pool_pool_with_map_reuse_proto_rawDescGZIP(), []int{0, 0} +} + +type MapReuseTest1 struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + IntToStringMap map[int32]string `protobuf:"bytes,1,rep,name=intToStringMap,proto3" json:"intToStringMap,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + StringToEnumMap map[string]MapReuseTest1_TEST `protobuf:"bytes,2,rep,name=stringToEnumMap,proto3" json:"stringToEnumMap,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3,enum=MapReuseTest1_TEST"` +} + +func (x *MapReuseTest1) Reset() { + *x = MapReuseTest1{} + if protoimpl.UnsafeEnabled { + mi := &file_pool_pool_with_map_reuse_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MapReuseTest1) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MapReuseTest1) ProtoMessage() {} + +func (x *MapReuseTest1) ProtoReflect() protoreflect.Message { + mi := &file_pool_pool_with_map_reuse_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) +} + +// Deprecated: Use MapReuseTest1.ProtoReflect.Descriptor instead. +func (*MapReuseTest1) Descriptor() ([]byte, []int) { + return file_pool_pool_with_map_reuse_proto_rawDescGZIP(), []int{0} +} + +func (x *MapReuseTest1) GetIntToStringMap() map[int32]string { + if x != nil { + return x.IntToStringMap + } + return nil +} + +func (x *MapReuseTest1) GetStringToEnumMap() map[string]MapReuseTest1_TEST { + if x != nil { + return x.StringToEnumMap + } + return nil +} + +type TestObjWithoutPool struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Age uint64 `protobuf:"varint,2,opt,name=age,proto3" json:"age,omitempty"` +} + +func (x *TestObjWithoutPool) Reset() { + *x = TestObjWithoutPool{} + if protoimpl.UnsafeEnabled { + mi := &file_pool_pool_with_map_reuse_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TestObjWithoutPool) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TestObjWithoutPool) ProtoMessage() {} + +func (x *TestObjWithoutPool) ProtoReflect() protoreflect.Message { + mi := &file_pool_pool_with_map_reuse_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) +} + +// Deprecated: Use TestObjWithoutPool.ProtoReflect.Descriptor instead. +func (*TestObjWithoutPool) Descriptor() ([]byte, []int) { + return file_pool_pool_with_map_reuse_proto_rawDescGZIP(), []int{1} +} + +func (x *TestObjWithoutPool) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *TestObjWithoutPool) GetAge() uint64 { + if x != nil { + return x.Age + } + return 0 +} + +type MapReuseTest2 struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + IntToMapReuseTest1Map map[int32]*MapReuseTest1 `protobuf:"bytes,1,rep,name=intToMapReuseTest1Map,proto3" json:"intToMapReuseTest1Map,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + IntToTestObjWithoutPoolMap map[int32]*TestObjWithoutPool `protobuf:"bytes,2,rep,name=intToTestObjWithoutPoolMap,proto3" json:"intToTestObjWithoutPoolMap,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + Count uint32 `protobuf:"varint,3,opt,name=count,proto3" json:"count,omitempty"` +} + +func (x *MapReuseTest2) Reset() { + *x = MapReuseTest2{} + if protoimpl.UnsafeEnabled { + mi := &file_pool_pool_with_map_reuse_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MapReuseTest2) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MapReuseTest2) ProtoMessage() {} + +func (x *MapReuseTest2) ProtoReflect() protoreflect.Message { + mi := &file_pool_pool_with_map_reuse_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) +} + +// Deprecated: Use MapReuseTest2.ProtoReflect.Descriptor instead. +func (*MapReuseTest2) Descriptor() ([]byte, []int) { + return file_pool_pool_with_map_reuse_proto_rawDescGZIP(), []int{2} +} + +func (x *MapReuseTest2) GetIntToMapReuseTest1Map() map[int32]*MapReuseTest1 { + if x != nil { + return x.IntToMapReuseTest1Map + } + return nil +} + +func (x *MapReuseTest2) GetIntToTestObjWithoutPoolMap() map[int32]*TestObjWithoutPool { + if x != nil { + return x.IntToTestObjWithoutPoolMap + } + return nil +} + +func (x *MapReuseTest2) GetCount() uint32 { + if x != nil { + return x.Count + } + return 0 +} + +var File_pool_pool_with_map_reuse_proto protoreflect.FileDescriptor + +var file_pool_pool_with_map_reuse_proto_rawDesc = []byte{ + 0x0a, 0x1e, 0x70, 0x6f, 0x6f, 0x6c, 0x2f, 0x70, 0x6f, 0x6f, 0x6c, 0x5f, 0x77, 0x69, 0x74, 0x68, + 0x5f, 0x6d, 0x61, 0x70, 0x5f, 0x72, 0x65, 0x75, 0x73, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x1a, 0x33, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x6c, 0x61, + 0x6e, 0x65, 0x74, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2f, 0x76, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2f, 0x76, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x65, 0x78, 0x74, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xea, 0x02, 0x0a, 0x0d, 0x4d, 0x61, 0x70, 0x52, 0x65, 0x75, + 0x73, 0x65, 0x54, 0x65, 0x73, 0x74, 0x31, 0x12, 0x4a, 0x0a, 0x0e, 0x69, 0x6e, 0x74, 0x54, 0x6f, + 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x4d, 0x61, 0x70, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x22, 0x2e, 0x4d, 0x61, 0x70, 0x52, 0x65, 0x75, 0x73, 0x65, 0x54, 0x65, 0x73, 0x74, 0x31, 0x2e, + 0x49, 0x6e, 0x74, 0x54, 0x6f, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x4d, 0x61, 0x70, 0x45, 0x6e, + 0x74, 0x72, 0x79, 0x52, 0x0e, 0x69, 0x6e, 0x74, 0x54, 0x6f, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, + 0x4d, 0x61, 0x70, 0x12, 0x4d, 0x0a, 0x0f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x54, 0x6f, 0x45, + 0x6e, 0x75, 0x6d, 0x4d, 0x61, 0x70, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x4d, + 0x61, 0x70, 0x52, 0x65, 0x75, 0x73, 0x65, 0x54, 0x65, 0x73, 0x74, 0x31, 0x2e, 0x53, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x54, 0x6f, 0x45, 0x6e, 0x75, 0x6d, 0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, + 0x79, 0x52, 0x0f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x54, 0x6f, 0x45, 0x6e, 0x75, 0x6d, 0x4d, + 0x61, 0x70, 0x1a, 0x41, 0x0a, 0x13, 0x49, 0x6e, 0x74, 0x54, 0x6f, 0x53, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x57, 0x0a, 0x14, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x54, + 0x6f, 0x45, 0x6e, 0x75, 0x6d, 0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, + 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, + 0x29, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x13, + 0x2e, 0x4d, 0x61, 0x70, 0x52, 0x65, 0x75, 0x73, 0x65, 0x54, 0x65, 0x73, 0x74, 0x31, 0x2e, 0x54, + 0x45, 0x53, 0x54, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x1c, + 0x0a, 0x04, 0x54, 0x45, 0x53, 0x54, 0x12, 0x09, 0x0a, 0x05, 0x74, 0x65, 0x73, 0x74, 0x31, 0x10, + 0x00, 0x12, 0x09, 0x0a, 0x05, 0x74, 0x65, 0x73, 0x74, 0x32, 0x10, 0x01, 0x3a, 0x04, 0xa8, 0xa6, + 0x1f, 0x01, 0x22, 0x3a, 0x0a, 0x12, 0x54, 0x65, 0x73, 0x74, 0x4f, 0x62, 0x6a, 0x57, 0x69, 0x74, + 0x68, 0x6f, 0x75, 0x74, 0x50, 0x6f, 0x6f, 0x6c, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, + 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x03, 0x61, 0x67, 0x65, 0x22, 0xba, + 0x03, 0x0a, 0x0d, 0x4d, 0x61, 0x70, 0x52, 0x65, 0x75, 0x73, 0x65, 0x54, 0x65, 0x73, 0x74, 0x32, + 0x12, 0x5f, 0x0a, 0x15, 0x69, 0x6e, 0x74, 0x54, 0x6f, 0x4d, 0x61, 0x70, 0x52, 0x65, 0x75, 0x73, + 0x65, 0x54, 0x65, 0x73, 0x74, 0x31, 0x4d, 0x61, 0x70, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x29, 0x2e, 0x4d, 0x61, 0x70, 0x52, 0x65, 0x75, 0x73, 0x65, 0x54, 0x65, 0x73, 0x74, 0x32, 0x2e, + 0x49, 0x6e, 0x74, 0x54, 0x6f, 0x4d, 0x61, 0x70, 0x52, 0x65, 0x75, 0x73, 0x65, 0x54, 0x65, 0x73, + 0x74, 0x31, 0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x15, 0x69, 0x6e, 0x74, 0x54, + 0x6f, 0x4d, 0x61, 0x70, 0x52, 0x65, 0x75, 0x73, 0x65, 0x54, 0x65, 0x73, 0x74, 0x31, 0x4d, 0x61, + 0x70, 0x12, 0x6e, 0x0a, 0x1a, 0x69, 0x6e, 0x74, 0x54, 0x6f, 0x54, 0x65, 0x73, 0x74, 0x4f, 0x62, + 0x6a, 0x57, 0x69, 0x74, 0x68, 0x6f, 0x75, 0x74, 0x50, 0x6f, 0x6f, 0x6c, 0x4d, 0x61, 0x70, 0x18, + 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2e, 0x2e, 0x4d, 0x61, 0x70, 0x52, 0x65, 0x75, 0x73, 0x65, + 0x54, 0x65, 0x73, 0x74, 0x32, 0x2e, 0x49, 0x6e, 0x74, 0x54, 0x6f, 0x54, 0x65, 0x73, 0x74, 0x4f, + 0x62, 0x6a, 0x57, 0x69, 0x74, 0x68, 0x6f, 0x75, 0x74, 0x50, 0x6f, 0x6f, 0x6c, 0x4d, 0x61, 0x70, + 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x1a, 0x69, 0x6e, 0x74, 0x54, 0x6f, 0x54, 0x65, 0x73, 0x74, + 0x4f, 0x62, 0x6a, 0x57, 0x69, 0x74, 0x68, 0x6f, 0x75, 0x74, 0x50, 0x6f, 0x6f, 0x6c, 0x4d, 0x61, + 0x70, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, + 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x1a, 0x58, 0x0a, 0x1a, 0x49, 0x6e, 0x74, 0x54, 0x6f, + 0x4d, 0x61, 0x70, 0x52, 0x65, 0x75, 0x73, 0x65, 0x54, 0x65, 0x73, 0x74, 0x31, 0x4d, 0x61, 0x70, + 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x24, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x4d, 0x61, 0x70, 0x52, 0x65, 0x75, 0x73, + 0x65, 0x54, 0x65, 0x73, 0x74, 0x31, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, + 0x01, 0x1a, 0x62, 0x0a, 0x1f, 0x49, 0x6e, 0x74, 0x54, 0x6f, 0x54, 0x65, 0x73, 0x74, 0x4f, 0x62, + 0x6a, 0x57, 0x69, 0x74, 0x68, 0x6f, 0x75, 0x74, 0x50, 0x6f, 0x6f, 0x6c, 0x4d, 0x61, 0x70, 0x45, + 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x29, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x54, 0x65, 0x73, 0x74, 0x4f, 0x62, 0x6a, 0x57, + 0x69, 0x74, 0x68, 0x6f, 0x75, 0x74, 0x50, 0x6f, 0x6f, 0x6c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x3a, 0x02, 0x38, 0x01, 0x3a, 0x04, 0xa8, 0xa6, 0x1f, 0x01, 0x42, 0x10, 0x5a, 0x0e, 0x74, + 0x65, 0x73, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x6f, 0x6f, 0x6c, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_pool_pool_with_map_reuse_proto_rawDescOnce sync.Once + file_pool_pool_with_map_reuse_proto_rawDescData = file_pool_pool_with_map_reuse_proto_rawDesc +) + +func file_pool_pool_with_map_reuse_proto_rawDescGZIP() []byte { + file_pool_pool_with_map_reuse_proto_rawDescOnce.Do(func() { + file_pool_pool_with_map_reuse_proto_rawDescData = protoimpl.X.CompressGZIP(file_pool_pool_with_map_reuse_proto_rawDescData) + }) + return file_pool_pool_with_map_reuse_proto_rawDescData +} + +var file_pool_pool_with_map_reuse_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_pool_pool_with_map_reuse_proto_msgTypes = make([]protoimpl.MessageInfo, 7) +var file_pool_pool_with_map_reuse_proto_goTypes = []interface{}{ + (MapReuseTest1_TEST)(0), // 0: MapReuseTest1.TEST + (*MapReuseTest1)(nil), // 1: MapReuseTest1 + (*TestObjWithoutPool)(nil), // 2: TestObjWithoutPool + (*MapReuseTest2)(nil), // 3: MapReuseTest2 + nil, // 4: MapReuseTest1.IntToStringMapEntry + nil, // 5: MapReuseTest1.StringToEnumMapEntry + nil, // 6: MapReuseTest2.IntToMapReuseTest1MapEntry + nil, // 7: MapReuseTest2.IntToTestObjWithoutPoolMapEntry +} +var file_pool_pool_with_map_reuse_proto_depIdxs = []int32{ + 4, // 0: MapReuseTest1.intToStringMap:type_name -> MapReuseTest1.IntToStringMapEntry + 5, // 1: MapReuseTest1.stringToEnumMap:type_name -> MapReuseTest1.StringToEnumMapEntry + 6, // 2: MapReuseTest2.intToMapReuseTest1Map:type_name -> MapReuseTest2.IntToMapReuseTest1MapEntry + 7, // 3: MapReuseTest2.intToTestObjWithoutPoolMap:type_name -> MapReuseTest2.IntToTestObjWithoutPoolMapEntry + 0, // 4: MapReuseTest1.StringToEnumMapEntry.value:type_name -> MapReuseTest1.TEST + 1, // 5: MapReuseTest2.IntToMapReuseTest1MapEntry.value:type_name -> MapReuseTest1 + 2, // 6: MapReuseTest2.IntToTestObjWithoutPoolMapEntry.value:type_name -> TestObjWithoutPool + 7, // [7:7] is the sub-list for method output_type + 7, // [7:7] is the sub-list for method input_type + 7, // [7:7] is the sub-list for extension type_name + 7, // [7:7] is the sub-list for extension extendee + 0, // [0:7] is the sub-list for field type_name +} + +func init() { file_pool_pool_with_map_reuse_proto_init() } +func file_pool_pool_with_map_reuse_proto_init() { + if File_pool_pool_with_map_reuse_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_pool_pool_with_map_reuse_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MapReuseTest1); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_pool_pool_with_map_reuse_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TestObjWithoutPool); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_pool_pool_with_map_reuse_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MapReuseTest2); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_pool_pool_with_map_reuse_proto_rawDesc, + NumEnums: 1, + NumMessages: 7, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_pool_pool_with_map_reuse_proto_goTypes, + DependencyIndexes: file_pool_pool_with_map_reuse_proto_depIdxs, + EnumInfos: file_pool_pool_with_map_reuse_proto_enumTypes, + MessageInfos: file_pool_pool_with_map_reuse_proto_msgTypes, + }.Build() + File_pool_pool_with_map_reuse_proto = out.File + file_pool_pool_with_map_reuse_proto_rawDesc = nil + file_pool_pool_with_map_reuse_proto_goTypes = nil + file_pool_pool_with_map_reuse_proto_depIdxs = nil +} diff --git a/testproto/pool/pool_with_map_reuse.proto b/testproto/pool/pool_with_map_reuse.proto new file mode 100644 index 00000000..e2f53b33 --- /dev/null +++ b/testproto/pool/pool_with_map_reuse.proto @@ -0,0 +1,26 @@ +syntax = "proto3"; +option go_package = "testproto/pool"; + +import "github.com/planetscale/vtprotobuf/vtproto/ext.proto"; + +message MapReuseTest1 { + option (vtproto.mempool) = true; + enum TEST { + test1 = 0; + test2 = 1; + } + map intToStringMap = 1; + map stringToEnumMap = 2; +} + +message TestObjWithoutPool { + string name = 1; + uint64 age = 2; +} + +message MapReuseTest2 { + option (vtproto.mempool) = true; + map intToMapReuseTest1Map = 1; + map intToTestObjWithoutPoolMap = 2; + uint32 count = 3; +} diff --git a/testproto/pool/pool_with_map_reuse_vtproto.pb.go b/testproto/pool/pool_with_map_reuse_vtproto.pb.go new file mode 100644 index 00000000..607be59f --- /dev/null +++ b/testproto/pool/pool_with_map_reuse_vtproto.pb.go @@ -0,0 +1,2114 @@ +// Code generated by protoc-gen-go-vtproto. DO NOT EDIT. +// protoc-gen-go-vtproto version: (devel) +// source: pool/pool_with_map_reuse.proto + +package pool + +import ( + fmt "fmt" + protohelpers "github.com/planetscale/vtprotobuf/protohelpers" + proto "google.golang.org/protobuf/proto" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + io "io" + sync "sync" + unsafe "unsafe" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +func (m *MapReuseTest1) CloneVT() *MapReuseTest1 { + if m == nil { + return (*MapReuseTest1)(nil) + } + r := MapReuseTest1FromVTPool() + if rhs := m.IntToStringMap; rhs != nil { + tmpContainer := make(map[int32]string, len(rhs)) + for k, v := range rhs { + tmpContainer[k] = v + } + r.IntToStringMap = tmpContainer + } + if rhs := m.StringToEnumMap; rhs != nil { + tmpContainer := make(map[string]MapReuseTest1_TEST, len(rhs)) + for k, v := range rhs { + tmpContainer[k] = v + } + r.StringToEnumMap = tmpContainer + } + if len(m.unknownFields) > 0 { + r.unknownFields = make([]byte, len(m.unknownFields)) + copy(r.unknownFields, m.unknownFields) + } + return r +} + +func (m *MapReuseTest1) CloneMessageVT() proto.Message { + return m.CloneVT() +} + +func (m *TestObjWithoutPool) CloneVT() *TestObjWithoutPool { + if m == nil { + return (*TestObjWithoutPool)(nil) + } + r := new(TestObjWithoutPool) + r.Name = m.Name + r.Age = m.Age + if len(m.unknownFields) > 0 { + r.unknownFields = make([]byte, len(m.unknownFields)) + copy(r.unknownFields, m.unknownFields) + } + return r +} + +func (m *TestObjWithoutPool) CloneMessageVT() proto.Message { + return m.CloneVT() +} + +func (m *MapReuseTest2) CloneVT() *MapReuseTest2 { + if m == nil { + return (*MapReuseTest2)(nil) + } + r := MapReuseTest2FromVTPool() + r.Count = m.Count + if rhs := m.IntToMapReuseTest1Map; rhs != nil { + tmpContainer := make(map[int32]*MapReuseTest1, len(rhs)) + for k, v := range rhs { + tmpContainer[k] = v.CloneVT() + } + r.IntToMapReuseTest1Map = tmpContainer + } + if rhs := m.IntToTestObjWithoutPoolMap; rhs != nil { + tmpContainer := make(map[int32]*TestObjWithoutPool, len(rhs)) + for k, v := range rhs { + tmpContainer[k] = v.CloneVT() + } + r.IntToTestObjWithoutPoolMap = tmpContainer + } + if len(m.unknownFields) > 0 { + r.unknownFields = make([]byte, len(m.unknownFields)) + copy(r.unknownFields, m.unknownFields) + } + return r +} + +func (m *MapReuseTest2) CloneMessageVT() proto.Message { + return m.CloneVT() +} + +func (this *MapReuseTest1) EqualVT(that *MapReuseTest1) bool { + if this == that { + return true + } else if this == nil || that == nil { + return false + } + if len(this.IntToStringMap) != len(that.IntToStringMap) { + return false + } + for i, vx := range this.IntToStringMap { + vy, ok := that.IntToStringMap[i] + if !ok { + return false + } + if vx != vy { + return false + } + } + if len(this.StringToEnumMap) != len(that.StringToEnumMap) { + return false + } + for i, vx := range this.StringToEnumMap { + vy, ok := that.StringToEnumMap[i] + if !ok { + return false + } + if vx != vy { + return false + } + } + return string(this.unknownFields) == string(that.unknownFields) +} + +func (this *MapReuseTest1) EqualMessageVT(thatMsg proto.Message) bool { + that, ok := thatMsg.(*MapReuseTest1) + if !ok { + return false + } + return this.EqualVT(that) +} +func (this *TestObjWithoutPool) EqualVT(that *TestObjWithoutPool) bool { + if this == that { + return true + } else if this == nil || that == nil { + return false + } + if this.Name != that.Name { + return false + } + if this.Age != that.Age { + return false + } + return string(this.unknownFields) == string(that.unknownFields) +} + +func (this *TestObjWithoutPool) EqualMessageVT(thatMsg proto.Message) bool { + that, ok := thatMsg.(*TestObjWithoutPool) + if !ok { + return false + } + return this.EqualVT(that) +} +func (this *MapReuseTest2) EqualVT(that *MapReuseTest2) bool { + if this == that { + return true + } else if this == nil || that == nil { + return false + } + if len(this.IntToMapReuseTest1Map) != len(that.IntToMapReuseTest1Map) { + return false + } + for i, vx := range this.IntToMapReuseTest1Map { + vy, ok := that.IntToMapReuseTest1Map[i] + if !ok { + return false + } + if p, q := vx, vy; p != q { + if p == nil { + p = &MapReuseTest1{} + } + if q == nil { + q = &MapReuseTest1{} + } + if !p.EqualVT(q) { + return false + } + } + } + if len(this.IntToTestObjWithoutPoolMap) != len(that.IntToTestObjWithoutPoolMap) { + return false + } + for i, vx := range this.IntToTestObjWithoutPoolMap { + vy, ok := that.IntToTestObjWithoutPoolMap[i] + if !ok { + return false + } + if p, q := vx, vy; p != q { + if p == nil { + p = &TestObjWithoutPool{} + } + if q == nil { + q = &TestObjWithoutPool{} + } + if !p.EqualVT(q) { + return false + } + } + } + if this.Count != that.Count { + return false + } + return string(this.unknownFields) == string(that.unknownFields) +} + +func (this *MapReuseTest2) EqualMessageVT(thatMsg proto.Message) bool { + that, ok := thatMsg.(*MapReuseTest2) + if !ok { + return false + } + return this.EqualVT(that) +} +func (m *MapReuseTest1) MarshalVT() (dAtA []byte, err error) { + if m == nil { + return nil, nil + } + size := m.SizeVT() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBufferVT(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MapReuseTest1) MarshalToVT(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVT(dAtA[:size]) +} + +func (m *MapReuseTest1) MarshalToSizedBufferVT(dAtA []byte) (int, error) { + if m == nil { + return 0, nil + } + i := len(dAtA) + _ = i + var l int + _ = l + if m.unknownFields != nil { + i -= len(m.unknownFields) + copy(dAtA[i:], m.unknownFields) + } + if len(m.StringToEnumMap) > 0 { + for k := range m.StringToEnumMap { + v := m.StringToEnumMap[k] + baseI := i + i = protohelpers.EncodeVarint(dAtA, i, uint64(v)) + i-- + dAtA[i] = 0x10 + i -= len(k) + copy(dAtA[i:], k) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(k))) + i-- + dAtA[i] = 0xa + i = protohelpers.EncodeVarint(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0x12 + } + } + if len(m.IntToStringMap) > 0 { + for k := range m.IntToStringMap { + v := m.IntToStringMap[k] + baseI := i + i -= len(v) + copy(dAtA[i:], v) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(v))) + i-- + dAtA[i] = 0x12 + i = protohelpers.EncodeVarint(dAtA, i, uint64(k)) + i-- + dAtA[i] = 0x8 + i = protohelpers.EncodeVarint(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *TestObjWithoutPool) MarshalVT() (dAtA []byte, err error) { + if m == nil { + return nil, nil + } + size := m.SizeVT() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBufferVT(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *TestObjWithoutPool) MarshalToVT(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVT(dAtA[:size]) +} + +func (m *TestObjWithoutPool) MarshalToSizedBufferVT(dAtA []byte) (int, error) { + if m == nil { + return 0, nil + } + i := len(dAtA) + _ = i + var l int + _ = l + if m.unknownFields != nil { + i -= len(m.unknownFields) + copy(dAtA[i:], m.unknownFields) + } + if m.Age != 0 { + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.Age)) + i-- + dAtA[i] = 0x10 + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MapReuseTest2) MarshalVT() (dAtA []byte, err error) { + if m == nil { + return nil, nil + } + size := m.SizeVT() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBufferVT(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MapReuseTest2) MarshalToVT(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVT(dAtA[:size]) +} + +func (m *MapReuseTest2) MarshalToSizedBufferVT(dAtA []byte) (int, error) { + if m == nil { + return 0, nil + } + i := len(dAtA) + _ = i + var l int + _ = l + if m.unknownFields != nil { + i -= len(m.unknownFields) + copy(dAtA[i:], m.unknownFields) + } + if m.Count != 0 { + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.Count)) + i-- + dAtA[i] = 0x18 + } + if len(m.IntToTestObjWithoutPoolMap) > 0 { + for k := range m.IntToTestObjWithoutPoolMap { + v := m.IntToTestObjWithoutPoolMap[k] + baseI := i + size, err := v.MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x12 + i = protohelpers.EncodeVarint(dAtA, i, uint64(k)) + i-- + dAtA[i] = 0x8 + i = protohelpers.EncodeVarint(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0x12 + } + } + if len(m.IntToMapReuseTest1Map) > 0 { + for k := range m.IntToMapReuseTest1Map { + v := m.IntToMapReuseTest1Map[k] + baseI := i + size, err := v.MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x12 + i = protohelpers.EncodeVarint(dAtA, i, uint64(k)) + i-- + dAtA[i] = 0x8 + i = protohelpers.EncodeVarint(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *MapReuseTest1) MarshalVTStrict() (dAtA []byte, err error) { + if m == nil { + return nil, nil + } + size := m.SizeVT() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBufferVTStrict(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MapReuseTest1) MarshalToVTStrict(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVTStrict(dAtA[:size]) +} + +func (m *MapReuseTest1) MarshalToSizedBufferVTStrict(dAtA []byte) (int, error) { + if m == nil { + return 0, nil + } + i := len(dAtA) + _ = i + var l int + _ = l + if m.unknownFields != nil { + i -= len(m.unknownFields) + copy(dAtA[i:], m.unknownFields) + } + if len(m.StringToEnumMap) > 0 { + for k := range m.StringToEnumMap { + v := m.StringToEnumMap[k] + baseI := i + i = protohelpers.EncodeVarint(dAtA, i, uint64(v)) + i-- + dAtA[i] = 0x10 + i -= len(k) + copy(dAtA[i:], k) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(k))) + i-- + dAtA[i] = 0xa + i = protohelpers.EncodeVarint(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0x12 + } + } + if len(m.IntToStringMap) > 0 { + for k := range m.IntToStringMap { + v := m.IntToStringMap[k] + baseI := i + i -= len(v) + copy(dAtA[i:], v) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(v))) + i-- + dAtA[i] = 0x12 + i = protohelpers.EncodeVarint(dAtA, i, uint64(k)) + i-- + dAtA[i] = 0x8 + i = protohelpers.EncodeVarint(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *TestObjWithoutPool) MarshalVTStrict() (dAtA []byte, err error) { + if m == nil { + return nil, nil + } + size := m.SizeVT() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBufferVTStrict(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *TestObjWithoutPool) MarshalToVTStrict(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVTStrict(dAtA[:size]) +} + +func (m *TestObjWithoutPool) MarshalToSizedBufferVTStrict(dAtA []byte) (int, error) { + if m == nil { + return 0, nil + } + i := len(dAtA) + _ = i + var l int + _ = l + if m.unknownFields != nil { + i -= len(m.unknownFields) + copy(dAtA[i:], m.unknownFields) + } + if m.Age != 0 { + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.Age)) + i-- + dAtA[i] = 0x10 + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MapReuseTest2) MarshalVTStrict() (dAtA []byte, err error) { + if m == nil { + return nil, nil + } + size := m.SizeVT() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBufferVTStrict(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MapReuseTest2) MarshalToVTStrict(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVTStrict(dAtA[:size]) +} + +func (m *MapReuseTest2) MarshalToSizedBufferVTStrict(dAtA []byte) (int, error) { + if m == nil { + return 0, nil + } + i := len(dAtA) + _ = i + var l int + _ = l + if m.unknownFields != nil { + i -= len(m.unknownFields) + copy(dAtA[i:], m.unknownFields) + } + if m.Count != 0 { + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.Count)) + i-- + dAtA[i] = 0x18 + } + if len(m.IntToTestObjWithoutPoolMap) > 0 { + for k := range m.IntToTestObjWithoutPoolMap { + v := m.IntToTestObjWithoutPoolMap[k] + baseI := i + size, err := v.MarshalToSizedBufferVTStrict(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x12 + i = protohelpers.EncodeVarint(dAtA, i, uint64(k)) + i-- + dAtA[i] = 0x8 + i = protohelpers.EncodeVarint(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0x12 + } + } + if len(m.IntToMapReuseTest1Map) > 0 { + for k := range m.IntToMapReuseTest1Map { + v := m.IntToMapReuseTest1Map[k] + baseI := i + size, err := v.MarshalToSizedBufferVTStrict(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x12 + i = protohelpers.EncodeVarint(dAtA, i, uint64(k)) + i-- + dAtA[i] = 0x8 + i = protohelpers.EncodeVarint(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +var vtprotoPool_MapReuseTest1 = sync.Pool{ + New: func() interface{} { + return &MapReuseTest1{} + }, +} + +func (m *MapReuseTest1) ResetVT() { + if m != nil { + clear(m.IntToStringMap) + f0 := m.IntToStringMap + clear(m.StringToEnumMap) + f1 := m.StringToEnumMap + m.Reset() + m.IntToStringMap = f0 + m.StringToEnumMap = f1 + } +} +func (m *MapReuseTest1) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_MapReuseTest1.Put(m) + } +} +func MapReuseTest1FromVTPool() *MapReuseTest1 { + return vtprotoPool_MapReuseTest1.Get().(*MapReuseTest1) +} + +var vtprotoPool_MapReuseTest2 = sync.Pool{ + New: func() interface{} { + return &MapReuseTest2{} + }, +} + +func (m *MapReuseTest2) ResetVT() { + if m != nil { + for _, v := range m.IntToMapReuseTest1Map { + v.ResetVT() + } + clear(m.IntToMapReuseTest1Map) + f0 := m.IntToMapReuseTest1Map + for _, v := range m.IntToTestObjWithoutPoolMap { + v.Reset() + } + clear(m.IntToTestObjWithoutPoolMap) + f1 := m.IntToTestObjWithoutPoolMap + m.Reset() + m.IntToMapReuseTest1Map = f0 + m.IntToTestObjWithoutPoolMap = f1 + } +} +func (m *MapReuseTest2) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_MapReuseTest2.Put(m) + } +} +func MapReuseTest2FromVTPool() *MapReuseTest2 { + return vtprotoPool_MapReuseTest2.Get().(*MapReuseTest2) +} +func (m *MapReuseTest1) SizeVT() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.IntToStringMap) > 0 { + for k, v := range m.IntToStringMap { + _ = k + _ = v + mapEntrySize := 1 + protohelpers.SizeOfVarint(uint64(k)) + 1 + len(v) + protohelpers.SizeOfVarint(uint64(len(v))) + n += mapEntrySize + 1 + protohelpers.SizeOfVarint(uint64(mapEntrySize)) + } + } + if len(m.StringToEnumMap) > 0 { + for k, v := range m.StringToEnumMap { + _ = k + _ = v + mapEntrySize := 1 + len(k) + protohelpers.SizeOfVarint(uint64(len(k))) + 1 + protohelpers.SizeOfVarint(uint64(v)) + n += mapEntrySize + 1 + protohelpers.SizeOfVarint(uint64(mapEntrySize)) + } + } + n += len(m.unknownFields) + return n +} + +func (m *TestObjWithoutPool) SizeVT() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Name) + if l > 0 { + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) + } + if m.Age != 0 { + n += 1 + protohelpers.SizeOfVarint(uint64(m.Age)) + } + n += len(m.unknownFields) + return n +} + +func (m *MapReuseTest2) SizeVT() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.IntToMapReuseTest1Map) > 0 { + for k, v := range m.IntToMapReuseTest1Map { + _ = k + _ = v + l = 0 + if v != nil { + l = v.SizeVT() + } + l += 1 + protohelpers.SizeOfVarint(uint64(l)) + mapEntrySize := 1 + protohelpers.SizeOfVarint(uint64(k)) + l + n += mapEntrySize + 1 + protohelpers.SizeOfVarint(uint64(mapEntrySize)) + } + } + if len(m.IntToTestObjWithoutPoolMap) > 0 { + for k, v := range m.IntToTestObjWithoutPoolMap { + _ = k + _ = v + l = 0 + if v != nil { + l = v.SizeVT() + } + l += 1 + protohelpers.SizeOfVarint(uint64(l)) + mapEntrySize := 1 + protohelpers.SizeOfVarint(uint64(k)) + l + n += mapEntrySize + 1 + protohelpers.SizeOfVarint(uint64(mapEntrySize)) + } + } + if m.Count != 0 { + n += 1 + protohelpers.SizeOfVarint(uint64(m.Count)) + } + n += len(m.unknownFields) + return n +} + +func (m *MapReuseTest1) UnmarshalVT(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MapReuseTest1: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MapReuseTest1: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field IntToStringMap", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.IntToStringMap == nil { + m.IntToStringMap = make(map[int32]string) + } + var mapkey int32 + var mapvalue string + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapkey |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + } else if fieldNum == 2 { + var stringLenmapvalue uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapvalue |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapvalue := int(stringLenmapvalue) + if intStringLenmapvalue < 0 { + return protohelpers.ErrInvalidLength + } + postStringIndexmapvalue := iNdEx + intStringLenmapvalue + if postStringIndexmapvalue < 0 { + return protohelpers.ErrInvalidLength + } + if postStringIndexmapvalue > l { + return io.ErrUnexpectedEOF + } + mapvalue = string(dAtA[iNdEx:postStringIndexmapvalue]) + iNdEx = postStringIndexmapvalue + } else { + iNdEx = entryPreIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > postIndex { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + m.IntToStringMap[mapkey] = mapvalue + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StringToEnumMap", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.StringToEnumMap == nil { + m.StringToEnumMap = make(map[string]MapReuseTest1_TEST) + } + var mapkey string + var mapvalue MapReuseTest1_TEST + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + var stringLenmapkey uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapkey |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapkey := int(stringLenmapkey) + if intStringLenmapkey < 0 { + return protohelpers.ErrInvalidLength + } + postStringIndexmapkey := iNdEx + intStringLenmapkey + if postStringIndexmapkey < 0 { + return protohelpers.ErrInvalidLength + } + if postStringIndexmapkey > l { + return io.ErrUnexpectedEOF + } + mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) + iNdEx = postStringIndexmapkey + } else if fieldNum == 2 { + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapvalue |= MapReuseTest1_TEST(b&0x7F) << shift + if b < 0x80 { + break + } + } + } else { + iNdEx = entryPreIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > postIndex { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + m.StringToEnumMap[mapkey] = mapvalue + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.unknownFields = append(m.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *TestObjWithoutPool) UnmarshalVT(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: TestObjWithoutPool: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TestObjWithoutPool: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Age", wireType) + } + m.Age = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Age |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.unknownFields = append(m.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MapReuseTest2) UnmarshalVT(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MapReuseTest2: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MapReuseTest2: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field IntToMapReuseTest1Map", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.IntToMapReuseTest1Map == nil { + m.IntToMapReuseTest1Map = make(map[int32]*MapReuseTest1) + } + var mapkey int32 + var mapvalue *MapReuseTest1 + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapkey |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + } else if fieldNum == 2 { + var mapmsglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapmsglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if mapmsglen < 0 { + return protohelpers.ErrInvalidLength + } + postmsgIndex := iNdEx + mapmsglen + if postmsgIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postmsgIndex > l { + return io.ErrUnexpectedEOF + } + mapvalue = &MapReuseTest1{} + if err := mapvalue.UnmarshalVT(dAtA[iNdEx:postmsgIndex]); err != nil { + return err + } + iNdEx = postmsgIndex + } else { + iNdEx = entryPreIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > postIndex { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + m.IntToMapReuseTest1Map[mapkey] = mapvalue + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field IntToTestObjWithoutPoolMap", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.IntToTestObjWithoutPoolMap == nil { + m.IntToTestObjWithoutPoolMap = make(map[int32]*TestObjWithoutPool) + } + var mapkey int32 + var mapvalue *TestObjWithoutPool + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapkey |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + } else if fieldNum == 2 { + var mapmsglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapmsglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if mapmsglen < 0 { + return protohelpers.ErrInvalidLength + } + postmsgIndex := iNdEx + mapmsglen + if postmsgIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postmsgIndex > l { + return io.ErrUnexpectedEOF + } + mapvalue = &TestObjWithoutPool{} + if err := mapvalue.UnmarshalVT(dAtA[iNdEx:postmsgIndex]); err != nil { + return err + } + iNdEx = postmsgIndex + } else { + iNdEx = entryPreIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > postIndex { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + m.IntToTestObjWithoutPoolMap[mapkey] = mapvalue + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Count", wireType) + } + m.Count = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Count |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.unknownFields = append(m.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MapReuseTest1) UnmarshalVTUnsafe(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MapReuseTest1: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MapReuseTest1: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field IntToStringMap", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.IntToStringMap == nil { + m.IntToStringMap = make(map[int32]string) + } + var mapkey int32 + var mapvalue string + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapkey |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + } else if fieldNum == 2 { + var stringLenmapvalue uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapvalue |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapvalue := int(stringLenmapvalue) + if intStringLenmapvalue < 0 { + return protohelpers.ErrInvalidLength + } + postStringIndexmapvalue := iNdEx + intStringLenmapvalue + if postStringIndexmapvalue < 0 { + return protohelpers.ErrInvalidLength + } + if postStringIndexmapvalue > l { + return io.ErrUnexpectedEOF + } + if intStringLenmapvalue == 0 { + mapvalue = "" + } else { + mapvalue = unsafe.String(&dAtA[iNdEx], intStringLenmapvalue) + } + iNdEx = postStringIndexmapvalue + } else { + iNdEx = entryPreIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > postIndex { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + m.IntToStringMap[mapkey] = mapvalue + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StringToEnumMap", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.StringToEnumMap == nil { + m.StringToEnumMap = make(map[string]MapReuseTest1_TEST) + } + var mapkey string + var mapvalue MapReuseTest1_TEST + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + var stringLenmapkey uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapkey |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapkey := int(stringLenmapkey) + if intStringLenmapkey < 0 { + return protohelpers.ErrInvalidLength + } + postStringIndexmapkey := iNdEx + intStringLenmapkey + if postStringIndexmapkey < 0 { + return protohelpers.ErrInvalidLength + } + if postStringIndexmapkey > l { + return io.ErrUnexpectedEOF + } + if intStringLenmapkey == 0 { + mapkey = "" + } else { + mapkey = unsafe.String(&dAtA[iNdEx], intStringLenmapkey) + } + iNdEx = postStringIndexmapkey + } else if fieldNum == 2 { + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapvalue |= MapReuseTest1_TEST(b&0x7F) << shift + if b < 0x80 { + break + } + } + } else { + iNdEx = entryPreIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > postIndex { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + m.StringToEnumMap[mapkey] = mapvalue + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.unknownFields = append(m.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *TestObjWithoutPool) UnmarshalVTUnsafe(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: TestObjWithoutPool: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TestObjWithoutPool: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var stringValue string + if intStringLen > 0 { + stringValue = unsafe.String(&dAtA[iNdEx], intStringLen) + } + m.Name = stringValue + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Age", wireType) + } + m.Age = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Age |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.unknownFields = append(m.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MapReuseTest2) UnmarshalVTUnsafe(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MapReuseTest2: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MapReuseTest2: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field IntToMapReuseTest1Map", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.IntToMapReuseTest1Map == nil { + m.IntToMapReuseTest1Map = make(map[int32]*MapReuseTest1) + } + var mapkey int32 + var mapvalue *MapReuseTest1 + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapkey |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + } else if fieldNum == 2 { + var mapmsglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapmsglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if mapmsglen < 0 { + return protohelpers.ErrInvalidLength + } + postmsgIndex := iNdEx + mapmsglen + if postmsgIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postmsgIndex > l { + return io.ErrUnexpectedEOF + } + mapvalue = &MapReuseTest1{} + if err := mapvalue.UnmarshalVTUnsafe(dAtA[iNdEx:postmsgIndex]); err != nil { + return err + } + iNdEx = postmsgIndex + } else { + iNdEx = entryPreIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > postIndex { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + m.IntToMapReuseTest1Map[mapkey] = mapvalue + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field IntToTestObjWithoutPoolMap", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.IntToTestObjWithoutPoolMap == nil { + m.IntToTestObjWithoutPoolMap = make(map[int32]*TestObjWithoutPool) + } + var mapkey int32 + var mapvalue *TestObjWithoutPool + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapkey |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + } else if fieldNum == 2 { + var mapmsglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapmsglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if mapmsglen < 0 { + return protohelpers.ErrInvalidLength + } + postmsgIndex := iNdEx + mapmsglen + if postmsgIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postmsgIndex > l { + return io.ErrUnexpectedEOF + } + mapvalue = &TestObjWithoutPool{} + if err := mapvalue.UnmarshalVTUnsafe(dAtA[iNdEx:postmsgIndex]); err != nil { + return err + } + iNdEx = postmsgIndex + } else { + iNdEx = entryPreIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > postIndex { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + m.IntToTestObjWithoutPoolMap[mapkey] = mapvalue + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Count", wireType) + } + m.Count = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Count |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.unknownFields = append(m.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +}