diff --git a/.gitignore b/.gitignore index ef80c50..08fa25d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ bin _vendor +conformance/marshal.log diff --git a/Makefile b/Makefile index 3cc625a..3608555 100644 --- a/Makefile +++ b/Makefile @@ -64,6 +64,7 @@ gen-testproto: get-grpc-testproto gen-wkt-testproto install testproto/proto3opt/opt.proto \ testproto/proto2/scalars.proto \ testproto/unsafe/unsafe.proto \ + testproto/unique/unique.proto \ || exit 1; $(PROTOBUF_ROOT)/src/protoc \ --proto_path=testproto \ diff --git a/features/unmarshal/unmarshal.go b/features/unmarshal/unmarshal.go index 87f6ab6..c5540a5 100644 --- a/features/unmarshal/unmarshal.go +++ b/features/unmarshal/unmarshal.go @@ -157,9 +157,7 @@ func (p *unmarshal) declareMapField(varName string, nullable bool, field *protog } } -func (p *unmarshal) mapField(varName string, field *protogen.Field) { - unique := proto.GetExtension(field.Desc.Options(), vtproto.E_Options).(*vtproto.Opts).GetUnique() - +func (p *unmarshal) mapField(varName string, field *protogen.Field, unique bool) { switch field.Desc.Kind() { case protoreflect.DoubleKind: p.P(`var `, varName, `temp uint64`) @@ -509,6 +507,8 @@ func (p *unmarshal) fieldItem(field *protogen.Field, fieldname string, message * p.P(`m.`, fieldname, ` = &`, field.GoIdent, "{", field.GoName, `: v}`) p.P(`}`) } else if field.Desc.IsMap() { + unique := proto.GetExtension(field.Desc.Options(), vtproto.E_Options).(*vtproto.Opts).GetUnique() + goTyp, _ := p.FieldGoType(field) goTypK, _ := p.FieldGoType(field.Message.Fields[0]) goTypV, _ := p.FieldGoType(field.Message.Fields[1]) @@ -527,9 +527,9 @@ func (p *unmarshal) fieldItem(field *protogen.Field, fieldname string, message * p.P(`fieldNum := int32(wire >> 3)`) p.P(`if fieldNum == 1 {`) - p.mapField("mapkey", field.Message.Fields[0]) + p.mapField("mapkey", field.Message.Fields[0], unique) p.P(`} else if fieldNum == 2 {`) - p.mapField("mapvalue", field.Message.Fields[1]) + p.mapField("mapvalue", field.Message.Fields[1], unique) p.P(`} else {`) p.P(`iNdEx = entryPreIndex`) p.P(`skippy, err := `, p.Helper("Skip"), `(dAtA[iNdEx:])`) diff --git a/testproto/unique/unique.pb.go b/testproto/unique/unique.pb.go index cc1fb68..f9779f8 100644 --- a/testproto/unique/unique.pb.go +++ b/testproto/unique/unique.pb.go @@ -26,7 +26,9 @@ type UniqueFieldExtension struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Foo string `protobuf:"bytes,1,opt,name=foo,proto3" json:"foo,omitempty"` + Foo string `protobuf:"bytes,1,opt,name=foo,proto3" json:"foo,omitempty"` + Bar map[string]int64 `protobuf:"bytes,2,rep,name=bar,proto3" json:"bar,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` + Baz map[int64]string `protobuf:"bytes,3,rep,name=baz,proto3" json:"baz,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } func (x *UniqueFieldExtension) Reset() { @@ -68,6 +70,20 @@ func (x *UniqueFieldExtension) GetFoo() string { return "" } +func (x *UniqueFieldExtension) GetBar() map[string]int64 { + if x != nil { + return x.Bar + } + return nil +} + +func (x *UniqueFieldExtension) GetBaz() map[int64]string { + if x != nil { + return x.Baz + } + return nil +} + var File_unique_unique_proto protoreflect.FileDescriptor var file_unique_unique_proto_rawDesc = []byte{ @@ -75,12 +91,26 @@ var file_unique_unique_proto_rawDesc = []byte{ 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, 0x31, 0x0a, 0x14, 0x55, 0x6e, - 0x69, 0x71, 0x75, 0x65, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x45, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, - 0x6f, 0x6e, 0x12, 0x19, 0x0a, 0x03, 0x66, 0x6f, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, - 0x07, 0xfa, 0xa3, 0xe8, 0x03, 0x02, 0x08, 0x01, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x42, 0x12, 0x5a, - 0x10, 0x74, 0x65, 0x73, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x75, 0x6e, 0x69, 0x71, 0x75, - 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x2f, 0x65, 0x78, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x94, 0x02, 0x0a, 0x14, 0x55, + 0x6e, 0x69, 0x71, 0x75, 0x65, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x45, 0x78, 0x74, 0x65, 0x6e, 0x73, + 0x69, 0x6f, 0x6e, 0x12, 0x18, 0x0a, 0x03, 0x66, 0x6f, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x42, 0x06, 0xb2, 0xa9, 0x1f, 0x02, 0x08, 0x01, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x12, 0x38, 0x0a, + 0x03, 0x62, 0x61, 0x72, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x55, 0x6e, 0x69, + 0x71, 0x75, 0x65, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x45, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, + 0x6e, 0x2e, 0x42, 0x61, 0x72, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x42, 0x06, 0xb2, 0xa9, 0x1f, 0x02, + 0x08, 0x01, 0x52, 0x03, 0x62, 0x61, 0x72, 0x12, 0x38, 0x0a, 0x03, 0x62, 0x61, 0x7a, 0x18, 0x03, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x55, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x46, 0x69, 0x65, + 0x6c, 0x64, 0x45, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x2e, 0x42, 0x61, 0x7a, 0x45, + 0x6e, 0x74, 0x72, 0x79, 0x42, 0x06, 0xb2, 0xa9, 0x1f, 0x02, 0x08, 0x01, 0x52, 0x03, 0x62, 0x61, + 0x7a, 0x1a, 0x36, 0x0a, 0x08, 0x42, 0x61, 0x72, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, + 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, + 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x36, 0x0a, 0x08, 0x42, 0x61, 0x7a, + 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x03, 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, 0x42, 0x12, 0x5a, 0x10, 0x74, 0x65, 0x73, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x75, + 0x6e, 0x69, 0x71, 0x75, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -95,16 +125,20 @@ func file_unique_unique_proto_rawDescGZIP() []byte { return file_unique_unique_proto_rawDescData } -var file_unique_unique_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_unique_unique_proto_msgTypes = make([]protoimpl.MessageInfo, 3) var file_unique_unique_proto_goTypes = []interface{}{ (*UniqueFieldExtension)(nil), // 0: UniqueFieldExtension + nil, // 1: UniqueFieldExtension.BarEntry + nil, // 2: UniqueFieldExtension.BazEntry } var file_unique_unique_proto_depIdxs = []int32{ - 0, // [0:0] is the sub-list for method output_type - 0, // [0:0] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name + 1, // 0: UniqueFieldExtension.bar:type_name -> UniqueFieldExtension.BarEntry + 2, // 1: UniqueFieldExtension.baz:type_name -> UniqueFieldExtension.BazEntry + 2, // [2:2] is the sub-list for method output_type + 2, // [2:2] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name } func init() { file_unique_unique_proto_init() } @@ -132,7 +166,7 @@ func file_unique_unique_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_unique_unique_proto_rawDesc, NumEnums: 0, - NumMessages: 1, + NumMessages: 3, NumExtensions: 0, NumServices: 0, }, diff --git a/testproto/unique/unique.proto b/testproto/unique/unique.proto index 767023b..e95e56e 100644 --- a/testproto/unique/unique.proto +++ b/testproto/unique/unique.proto @@ -5,4 +5,6 @@ import "github.com/planetscale/vtprotobuf/vtproto/ext.proto"; message UniqueFieldExtension { string foo = 1 [(vtproto.options).unique = true]; + map bar = 2 [(vtproto.options).unique = true]; + map baz = 3 [(vtproto.options).unique = true]; } diff --git a/testproto/unique/unique_test.go b/testproto/unique/unique_test.go index bef4055..6ae7bda 100644 --- a/testproto/unique/unique_test.go +++ b/testproto/unique/unique_test.go @@ -1,6 +1,8 @@ package unique import ( + "maps" + "slices" "testing" "unsafe" @@ -10,6 +12,8 @@ import ( func TestUnmarshalSameMemory(t *testing.T) { m := &UniqueFieldExtension{ Foo: "bar", + Bar: map[string]int64{"key": 100}, + Baz: map[int64]string{100: "value"}, } b, err := m.MarshalVTStrict() @@ -21,5 +25,17 @@ func TestUnmarshalSameMemory(t *testing.T) { m3 := &UniqueFieldExtension{} require.NoError(t, m3.UnmarshalVT(b)) - require.Equal(t, unsafe.StringData(m2.Foo), unsafe.StringData(m3.Foo)) + require.Same(t, unsafe.StringData(m2.Foo), unsafe.StringData(m3.Foo), "string field") + + keys2 := slices.Collect(maps.Keys(m2.Bar)) + keys3 := slices.Collect(maps.Keys(m3.Bar)) + require.Len(t, keys2, 1) + require.Len(t, keys3, 1) + require.Same(t, unsafe.StringData(keys2[0]), unsafe.StringData(keys3[0]), "string key") + + values2 := slices.Collect(maps.Values(m2.Baz)) + values3 := slices.Collect(maps.Values(m3.Baz)) + require.Len(t, values2, 1) + require.Len(t, values2, 1) + require.Same(t, unsafe.StringData(values2[0]), unsafe.StringData(values3[0]), "string value") } diff --git a/testproto/unique/unique_vtproto.pb.go b/testproto/unique/unique_vtproto.pb.go index d232bc8..4a8de2f 100644 --- a/testproto/unique/unique_vtproto.pb.go +++ b/testproto/unique/unique_vtproto.pb.go @@ -27,6 +27,20 @@ func (m *UniqueFieldExtension) CloneVT() *UniqueFieldExtension { } r := new(UniqueFieldExtension) r.Foo = m.Foo + if rhs := m.Bar; rhs != nil { + tmpContainer := make(map[string]int64, len(rhs)) + for k, v := range rhs { + tmpContainer[k] = v + } + r.Bar = tmpContainer + } + if rhs := m.Baz; rhs != nil { + tmpContainer := make(map[int64]string, len(rhs)) + for k, v := range rhs { + tmpContainer[k] = v + } + r.Baz = tmpContainer + } if len(m.unknownFields) > 0 { r.unknownFields = make([]byte, len(m.unknownFields)) copy(r.unknownFields, m.unknownFields) @@ -47,6 +61,30 @@ func (this *UniqueFieldExtension) EqualVT(that *UniqueFieldExtension) bool { if this.Foo != that.Foo { return false } + if len(this.Bar) != len(that.Bar) { + return false + } + for i, vx := range this.Bar { + vy, ok := that.Bar[i] + if !ok { + return false + } + if vx != vy { + return false + } + } + if len(this.Baz) != len(that.Baz) { + return false + } + for i, vx := range this.Baz { + vy, ok := that.Baz[i] + if !ok { + return false + } + if vx != vy { + return false + } + } return string(this.unknownFields) == string(that.unknownFields) } @@ -87,6 +125,40 @@ func (m *UniqueFieldExtension) MarshalToSizedBufferVT(dAtA []byte) (int, error) i -= len(m.unknownFields) copy(dAtA[i:], m.unknownFields) } + if len(m.Baz) > 0 { + for k := range m.Baz { + v := m.Baz[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] = 0x1a + } + } + if len(m.Bar) > 0 { + for k := range m.Bar { + v := m.Bar[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.Foo) > 0 { i -= len(m.Foo) copy(dAtA[i:], m.Foo) @@ -127,6 +199,40 @@ func (m *UniqueFieldExtension) MarshalToSizedBufferVTStrict(dAtA []byte) (int, e i -= len(m.unknownFields) copy(dAtA[i:], m.unknownFields) } + if len(m.Baz) > 0 { + for k := range m.Baz { + v := m.Baz[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] = 0x1a + } + } + if len(m.Bar) > 0 { + for k := range m.Bar { + v := m.Bar[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.Foo) > 0 { i -= len(m.Foo) copy(dAtA[i:], m.Foo) @@ -147,6 +253,22 @@ func (m *UniqueFieldExtension) SizeVT() (n int) { if l > 0 { n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } + if len(m.Bar) > 0 { + for k, v := range m.Bar { + _ = k + _ = v + mapEntrySize := 1 + len(k) + protohelpers.SizeOfVarint(uint64(len(k))) + 1 + protohelpers.SizeOfVarint(uint64(v)) + n += mapEntrySize + 1 + protohelpers.SizeOfVarint(uint64(mapEntrySize)) + } + } + if len(m.Baz) > 0 { + for k, v := range m.Baz { + _ = k + _ = v + mapEntrySize := 1 + protohelpers.SizeOfVarint(uint64(k)) + 1 + len(v) + protohelpers.SizeOfVarint(uint64(len(v))) + n += mapEntrySize + 1 + protohelpers.SizeOfVarint(uint64(mapEntrySize)) + } + } n += len(m.unknownFields) return n } @@ -216,6 +338,240 @@ func (m *UniqueFieldExtension) UnmarshalVT(dAtA []byte) error { } m.Foo = stringValue iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Bar", 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.Bar == nil { + m.Bar = make(map[string]int64) + } + var mapkey string + var mapvalue int64 + 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 = unique.Make[string](unsafe.String(&dAtA[iNdEx], intStringLenmapkey)).Value() + } + 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 |= int64(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.Bar[mapkey] = mapvalue + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Baz", 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.Baz == nil { + m.Baz = make(map[int64]string) + } + var mapkey int64 + 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 |= int64(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 = unique.Make[string](unsafe.String(&dAtA[iNdEx], intStringLenmapvalue)).Value() + } + 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.Baz[mapkey] = mapvalue + iNdEx = postIndex default: iNdEx = preIndex skippy, err := protohelpers.Skip(dAtA[iNdEx:]) @@ -303,6 +659,240 @@ func (m *UniqueFieldExtension) UnmarshalVTUnsafe(dAtA []byte) error { } m.Foo = stringValue iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Bar", 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.Bar == nil { + m.Bar = make(map[string]int64) + } + var mapkey string + var mapvalue int64 + 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 |= int64(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.Bar[mapkey] = mapvalue + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Baz", 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.Baz == nil { + m.Baz = make(map[int64]string) + } + var mapkey int64 + 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 |= int64(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.Baz[mapkey] = mapvalue + iNdEx = postIndex default: iNdEx = preIndex skippy, err := protohelpers.Skip(dAtA[iNdEx:])