From ae379105ce450faf2b567a57ccce463f96552e68 Mon Sep 17 00:00:00 2001 From: codesoap Date: Tue, 8 Oct 2024 19:52:29 +0200 Subject: [PATCH] Test compilation with ignoreUnknownFields flag --- Makefile | 2 + testproto/ignore_unknown_fields/opt.pb.go | 149 +++++++++ testproto/ignore_unknown_fields/opt.proto | 9 + .../ignore_unknown_fields/opt_vtproto.pb.go | 307 ++++++++++++++++++ 4 files changed, 467 insertions(+) create mode 100644 testproto/ignore_unknown_fields/opt.pb.go create mode 100644 testproto/ignore_unknown_fields/opt.proto create mode 100644 testproto/ignore_unknown_fields/opt_vtproto.pb.go diff --git a/Makefile b/Makefile index 41c524d..3cc625a 100644 --- a/Makefile +++ b/Makefile @@ -56,6 +56,7 @@ gen-testproto: get-grpc-testproto gen-wkt-testproto install --go_out=. --plugin protoc-gen-go="${GOBIN}/protoc-gen-go" \ --go-vtproto_out=allow-empty=true:. --plugin protoc-gen-go-vtproto="${GOBIN}/protoc-gen-go-vtproto" \ -I$(PROTOBUF_ROOT)/src \ + testproto/ignore_unknown_fields/opt.proto \ testproto/empty/empty.proto \ testproto/pool/pool.proto \ testproto/pool/pool_with_slice_reuse.proto \ @@ -106,4 +107,5 @@ genall: gen-include gen-conformance gen-testproto gen-wkt test: install gen-conformance go test -short ./... go test -count=1 ./conformance/... + go test -count=1 ./testproto/ignore_unknown_fields/... GOGC="off" go test -count=1 ./testproto/pool/... diff --git a/testproto/ignore_unknown_fields/opt.pb.go b/testproto/ignore_unknown_fields/opt.pb.go new file mode 100644 index 0000000..1ac2516 --- /dev/null +++ b/testproto/ignore_unknown_fields/opt.pb.go @@ -0,0 +1,149 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc v3.21.12 +// source: ignore_unknown_fields/opt.proto + +package ignore_unknown_fields + +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 IgnoreUnknownFieldsExtension struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Foo string `protobuf:"bytes,1,opt,name=foo,proto3" json:"foo,omitempty"` +} + +func (x *IgnoreUnknownFieldsExtension) Reset() { + *x = IgnoreUnknownFieldsExtension{} + if protoimpl.UnsafeEnabled { + mi := &file_ignore_unknown_fields_opt_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *IgnoreUnknownFieldsExtension) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*IgnoreUnknownFieldsExtension) ProtoMessage() {} + +func (x *IgnoreUnknownFieldsExtension) ProtoReflect() protoreflect.Message { + mi := &file_ignore_unknown_fields_opt_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 IgnoreUnknownFieldsExtension.ProtoReflect.Descriptor instead. +func (*IgnoreUnknownFieldsExtension) Descriptor() ([]byte, []int) { + return file_ignore_unknown_fields_opt_proto_rawDescGZIP(), []int{0} +} + +func (x *IgnoreUnknownFieldsExtension) GetFoo() string { + if x != nil { + return x.Foo + } + return "" +} + +var File_ignore_unknown_fields_opt_proto protoreflect.FileDescriptor + +var file_ignore_unknown_fields_opt_proto_rawDesc = []byte{ + 0x0a, 0x1f, 0x69, 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x5f, 0x75, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, + 0x5f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x73, 0x2f, 0x6f, 0x70, 0x74, 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, 0x36, 0x0a, 0x1c, 0x49, 0x67, 0x6e, 0x6f, 0x72, 0x65, + 0x55, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x73, 0x45, 0x78, 0x74, + 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x66, 0x6f, 0x6f, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x3a, 0x04, 0xb0, 0xa6, 0x1f, 0x01, 0x42, 0x21, + 0x5a, 0x1f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x69, 0x67, 0x6e, 0x6f, + 0x72, 0x65, 0x5f, 0x75, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x5f, 0x66, 0x69, 0x65, 0x6c, 0x64, + 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_ignore_unknown_fields_opt_proto_rawDescOnce sync.Once + file_ignore_unknown_fields_opt_proto_rawDescData = file_ignore_unknown_fields_opt_proto_rawDesc +) + +func file_ignore_unknown_fields_opt_proto_rawDescGZIP() []byte { + file_ignore_unknown_fields_opt_proto_rawDescOnce.Do(func() { + file_ignore_unknown_fields_opt_proto_rawDescData = protoimpl.X.CompressGZIP(file_ignore_unknown_fields_opt_proto_rawDescData) + }) + return file_ignore_unknown_fields_opt_proto_rawDescData +} + +var file_ignore_unknown_fields_opt_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_ignore_unknown_fields_opt_proto_goTypes = []interface{}{ + (*IgnoreUnknownFieldsExtension)(nil), // 0: IgnoreUnknownFieldsExtension +} +var file_ignore_unknown_fields_opt_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 +} + +func init() { file_ignore_unknown_fields_opt_proto_init() } +func file_ignore_unknown_fields_opt_proto_init() { + if File_ignore_unknown_fields_opt_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_ignore_unknown_fields_opt_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*IgnoreUnknownFieldsExtension); 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_ignore_unknown_fields_opt_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_ignore_unknown_fields_opt_proto_goTypes, + DependencyIndexes: file_ignore_unknown_fields_opt_proto_depIdxs, + MessageInfos: file_ignore_unknown_fields_opt_proto_msgTypes, + }.Build() + File_ignore_unknown_fields_opt_proto = out.File + file_ignore_unknown_fields_opt_proto_rawDesc = nil + file_ignore_unknown_fields_opt_proto_goTypes = nil + file_ignore_unknown_fields_opt_proto_depIdxs = nil +} diff --git a/testproto/ignore_unknown_fields/opt.proto b/testproto/ignore_unknown_fields/opt.proto new file mode 100644 index 0000000..0e0146d --- /dev/null +++ b/testproto/ignore_unknown_fields/opt.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; +option go_package = "testproto/ignore_unknown_fields"; + +import "github.com/planetscale/vtprotobuf/vtproto/ext.proto"; + +message IgnoreUnknownFieldsExtension { + option (vtproto.ignore_unknown_fields) = true; + string foo = 1; +} diff --git a/testproto/ignore_unknown_fields/opt_vtproto.pb.go b/testproto/ignore_unknown_fields/opt_vtproto.pb.go new file mode 100644 index 0000000..3e24a50 --- /dev/null +++ b/testproto/ignore_unknown_fields/opt_vtproto.pb.go @@ -0,0 +1,307 @@ +// Code generated by protoc-gen-go-vtproto. DO NOT EDIT. +// protoc-gen-go-vtproto version: (devel) +// source: ignore_unknown_fields/opt.proto + +package ignore_unknown_fields + +import ( + fmt "fmt" + protohelpers "github.com/planetscale/vtprotobuf/protohelpers" + proto "google.golang.org/protobuf/proto" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + io "io" + 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 *IgnoreUnknownFieldsExtension) CloneVT() *IgnoreUnknownFieldsExtension { + if m == nil { + return (*IgnoreUnknownFieldsExtension)(nil) + } + r := new(IgnoreUnknownFieldsExtension) + r.Foo = m.Foo + return r +} + +func (m *IgnoreUnknownFieldsExtension) CloneMessageVT() proto.Message { + return m.CloneVT() +} + +func (this *IgnoreUnknownFieldsExtension) EqualVT(that *IgnoreUnknownFieldsExtension) bool { + if this == that { + return true + } else if this == nil || that == nil { + return false + } + if this.Foo != that.Foo { + return false + } + return true +} + +func (this *IgnoreUnknownFieldsExtension) EqualMessageVT(thatMsg proto.Message) bool { + that, ok := thatMsg.(*IgnoreUnknownFieldsExtension) + if !ok { + return false + } + return this.EqualVT(that) +} +func (m *IgnoreUnknownFieldsExtension) 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 *IgnoreUnknownFieldsExtension) MarshalToVT(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVT(dAtA[:size]) +} + +func (m *IgnoreUnknownFieldsExtension) MarshalToSizedBufferVT(dAtA []byte) (int, error) { + if m == nil { + return 0, nil + } + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Foo) > 0 { + i -= len(m.Foo) + copy(dAtA[i:], m.Foo) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Foo))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *IgnoreUnknownFieldsExtension) 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 *IgnoreUnknownFieldsExtension) MarshalToVTStrict(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVTStrict(dAtA[:size]) +} + +func (m *IgnoreUnknownFieldsExtension) MarshalToSizedBufferVTStrict(dAtA []byte) (int, error) { + if m == nil { + return 0, nil + } + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Foo) > 0 { + i -= len(m.Foo) + copy(dAtA[i:], m.Foo) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Foo))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *IgnoreUnknownFieldsExtension) SizeVT() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Foo) + if l > 0 { + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) + } + return n +} + +func (m *IgnoreUnknownFieldsExtension) 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: IgnoreUnknownFieldsExtension: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: IgnoreUnknownFieldsExtension: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Foo", 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.Foo = string(dAtA[iNdEx:postIndex]) + 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 + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *IgnoreUnknownFieldsExtension) 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: IgnoreUnknownFieldsExtension: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: IgnoreUnknownFieldsExtension: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Foo", 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.Foo = stringValue + 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 + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +}