diff --git a/README.md b/README.md index 96adb7be..1030c056 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,20 @@ The following features can be generated: - `func (p *YourProto) CloneMessageVT() proto.Message`: this function behaves like the above `p.CloneVT()`, but provides a uniform signature in order to be accessible via type assertions even if the type is not known at compile time. This allows implementing a generic `func CloneVT(proto.Message)` without reflection. If the receiver `p` is `nil`, a typed `nil` pointer of the message type will be returned inside a `proto.Message` interface. +### Field Options + +- `unique` is a field option available on strings. If it is set to `true` then all all strings are interned using [unique.Make](https://pkg.go.dev/unique#Make). Go 1.23+ is needed. `unmarshal_unsafe` takes precendence over `unique`. Example usage: + +``` +import "github.com/planetscale/vtprotobuf/vtproto/ext.proto"; + +message Label { + string name = 1 [(vtproto.options).unique = true]; + string value = 2 [(vtproto.options).unique = true]; +} +``` + + ## Usage 1. Install `protoc-gen-go-vtproto`: diff --git a/features/unmarshal/unmarshal.go b/features/unmarshal/unmarshal.go index 79e929b0..0f7bce02 100644 --- a/features/unmarshal/unmarshal.go +++ b/features/unmarshal/unmarshal.go @@ -12,9 +12,11 @@ import ( "google.golang.org/protobuf/compiler/protogen" "google.golang.org/protobuf/encoding/protowire" + "google.golang.org/protobuf/proto" "google.golang.org/protobuf/reflect/protoreflect" "github.com/planetscale/vtprotobuf/generator" + "github.com/planetscale/vtprotobuf/vtproto" ) func init() { @@ -156,6 +158,8 @@ 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() + switch field.Desc.Kind() { case protoreflect.DoubleKind: p.P(`var `, varName, `temp uint64`) @@ -193,13 +197,20 @@ func (p *unmarshal) mapField(varName string, field *protogen.Field) { p.P(`if postStringIndex`, varName, ` > l {`) p.P(`return `, p.Ident("io", `ErrUnexpectedEOF`)) p.P(`}`) - if p.unsafe { + switch { + case p.unsafe: p.P(`if intStringLen`, varName, ` == 0 {`) p.P(varName, ` = ""`) p.P(`} else {`) p.P(varName, ` = `, p.Ident("unsafe", `String`), `(&dAtA[iNdEx], intStringLen`, varName, `)`) p.P(`}`) - } else { + case unique: + p.P(`if intStringLen`, varName, ` == 0 {`) + p.P(varName, ` = ""`) + p.P(`} else {`) + p.P(varName, ` = `, p.Ident("unique", `Make`), `[string](`, p.Ident("unsafe", `String`), `(&dAtA[iNdEx], intStringLen`, varName, `)).Value()`) + p.P(`}`) + default: p.P(varName, ` = `, "string", `(dAtA[iNdEx:postStringIndex`, varName, `])`) } p.P(`iNdEx = postStringIndex`, varName) @@ -409,6 +420,8 @@ func (p *unmarshal) fieldItem(field *protogen.Field, fieldname string, message * p.P(`m.`, fieldname, ` = &b`) } case protoreflect.StringKind: + unique := proto.GetExtension(field.Desc.Options(), vtproto.E_Options).(*vtproto.Opts).GetUnique() + p.P(`var stringLen uint64`) p.decodeVarint("stringLen", "uint64") p.P(`intStringLen := int(stringLen)`) @@ -423,12 +436,19 @@ func (p *unmarshal) fieldItem(field *protogen.Field, fieldname string, message * p.P(`return `, p.Ident("io", `ErrUnexpectedEOF`)) p.P(`}`) str := "string(dAtA[iNdEx:postIndex])" - if p.unsafe { + switch { + case p.unsafe: str = "stringValue" p.P(`var stringValue string`) p.P(`if intStringLen > 0 {`) p.P(`stringValue = `, p.Ident("unsafe", `String`), `(&dAtA[iNdEx], intStringLen)`) p.P(`}`) + case unique: + str = "stringValue" + p.P(`var stringValue string`) + p.P(`if intStringLen > 0 {`) + p.P(`stringValue = `, p.Ident("unique", `Make`), `[string](`, p.Ident("unsafe", `String`), `(&dAtA[iNdEx], intStringLen)).Value()`) + p.P(`}`) } if oneof { p.P(`m.`, fieldname, ` = &`, field.GoIdent, `{`, field.GoName, ": ", str, `}`) diff --git a/include/github.com/planetscale/vtprotobuf/vtproto/ext.proto b/include/github.com/planetscale/vtprotobuf/vtproto/ext.proto index 99099c5a..6c1c628a 100644 --- a/include/github.com/planetscale/vtprotobuf/vtproto/ext.proto +++ b/include/github.com/planetscale/vtprotobuf/vtproto/ext.proto @@ -9,4 +9,14 @@ option go_package = "github.com/planetscale/vtprotobuf/vtproto"; extend google.protobuf.MessageOptions { optional bool mempool = 64101; +} + +extend google.protobuf.FieldOptions { + optional Opts options = 64150; +} + +// These options should be used during schema definition, +// applying them to some of the fields in protobuf +message Opts { + optional bool unique = 1; } \ No newline at end of file diff --git a/testproto/unique/unique.pb.go b/testproto/unique/unique.pb.go new file mode 100644 index 00000000..cc1fb68f --- /dev/null +++ b/testproto/unique/unique.pb.go @@ -0,0 +1,147 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc v3.21.12 +// source: unique/unique.proto + +package unique + +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 UniqueFieldExtension struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Foo string `protobuf:"bytes,1,opt,name=foo,proto3" json:"foo,omitempty"` +} + +func (x *UniqueFieldExtension) Reset() { + *x = UniqueFieldExtension{} + if protoimpl.UnsafeEnabled { + mi := &file_unique_unique_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UniqueFieldExtension) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UniqueFieldExtension) ProtoMessage() {} + +func (x *UniqueFieldExtension) ProtoReflect() protoreflect.Message { + mi := &file_unique_unique_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 UniqueFieldExtension.ProtoReflect.Descriptor instead. +func (*UniqueFieldExtension) Descriptor() ([]byte, []int) { + return file_unique_unique_proto_rawDescGZIP(), []int{0} +} + +func (x *UniqueFieldExtension) GetFoo() string { + if x != nil { + return x.Foo + } + return "" +} + +var File_unique_unique_proto protoreflect.FileDescriptor + +var file_unique_unique_proto_rawDesc = []byte{ + 0x0a, 0x13, 0x75, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x2f, 0x75, 0x6e, 0x69, 0x71, 0x75, 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, 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, +} + +var ( + file_unique_unique_proto_rawDescOnce sync.Once + file_unique_unique_proto_rawDescData = file_unique_unique_proto_rawDesc +) + +func file_unique_unique_proto_rawDescGZIP() []byte { + file_unique_unique_proto_rawDescOnce.Do(func() { + file_unique_unique_proto_rawDescData = protoimpl.X.CompressGZIP(file_unique_unique_proto_rawDescData) + }) + return file_unique_unique_proto_rawDescData +} + +var file_unique_unique_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_unique_unique_proto_goTypes = []interface{}{ + (*UniqueFieldExtension)(nil), // 0: UniqueFieldExtension +} +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 +} + +func init() { file_unique_unique_proto_init() } +func file_unique_unique_proto_init() { + if File_unique_unique_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_unique_unique_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UniqueFieldExtension); 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_unique_unique_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_unique_unique_proto_goTypes, + DependencyIndexes: file_unique_unique_proto_depIdxs, + MessageInfos: file_unique_unique_proto_msgTypes, + }.Build() + File_unique_unique_proto = out.File + file_unique_unique_proto_rawDesc = nil + file_unique_unique_proto_goTypes = nil + file_unique_unique_proto_depIdxs = nil +} diff --git a/testproto/unique/unique.proto b/testproto/unique/unique.proto new file mode 100644 index 00000000..767023b2 --- /dev/null +++ b/testproto/unique/unique.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; +option go_package = "testproto/unique"; + +import "github.com/planetscale/vtprotobuf/vtproto/ext.proto"; + +message UniqueFieldExtension { + string foo = 1 [(vtproto.options).unique = true]; +} diff --git a/testproto/unique/unique_test.go b/testproto/unique/unique_test.go new file mode 100644 index 00000000..bef40554 --- /dev/null +++ b/testproto/unique/unique_test.go @@ -0,0 +1,25 @@ +package unique + +import ( + "testing" + "unsafe" + + "github.com/stretchr/testify/require" +) + +func TestUnmarshalSameMemory(t *testing.T) { + m := &UniqueFieldExtension{ + Foo: "bar", + } + + b, err := m.MarshalVTStrict() + require.NoError(t, err) + + m2 := &UniqueFieldExtension{} + require.NoError(t, m2.UnmarshalVT(b)) + + m3 := &UniqueFieldExtension{} + require.NoError(t, m3.UnmarshalVT(b)) + + require.Equal(t, unsafe.StringData(m2.Foo), unsafe.StringData(m3.Foo)) +} diff --git a/testproto/unique/unique_vtproto.pb.go b/testproto/unique/unique_vtproto.pb.go new file mode 100644 index 00000000..d232bc83 --- /dev/null +++ b/testproto/unique/unique_vtproto.pb.go @@ -0,0 +1,327 @@ +// Code generated by protoc-gen-go-vtproto. DO NOT EDIT. +// protoc-gen-go-vtproto version: (devel) +// source: unique/unique.proto + +package unique + +import ( + fmt "fmt" + protohelpers "github.com/planetscale/vtprotobuf/protohelpers" + proto "google.golang.org/protobuf/proto" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + io "io" + unique "unique" + 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 *UniqueFieldExtension) CloneVT() *UniqueFieldExtension { + if m == nil { + return (*UniqueFieldExtension)(nil) + } + r := new(UniqueFieldExtension) + r.Foo = m.Foo + if len(m.unknownFields) > 0 { + r.unknownFields = make([]byte, len(m.unknownFields)) + copy(r.unknownFields, m.unknownFields) + } + return r +} + +func (m *UniqueFieldExtension) CloneMessageVT() proto.Message { + return m.CloneVT() +} + +func (this *UniqueFieldExtension) EqualVT(that *UniqueFieldExtension) bool { + if this == that { + return true + } else if this == nil || that == nil { + return false + } + if this.Foo != that.Foo { + return false + } + return string(this.unknownFields) == string(that.unknownFields) +} + +func (this *UniqueFieldExtension) EqualMessageVT(thatMsg proto.Message) bool { + that, ok := thatMsg.(*UniqueFieldExtension) + if !ok { + return false + } + return this.EqualVT(that) +} +func (m *UniqueFieldExtension) 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 *UniqueFieldExtension) MarshalToVT(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVT(dAtA[:size]) +} + +func (m *UniqueFieldExtension) 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.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 *UniqueFieldExtension) 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 *UniqueFieldExtension) MarshalToVTStrict(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVTStrict(dAtA[:size]) +} + +func (m *UniqueFieldExtension) 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.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 *UniqueFieldExtension) 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)) + } + n += len(m.unknownFields) + return n +} + +func (m *UniqueFieldExtension) 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: UniqueFieldExtension: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: UniqueFieldExtension: 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 = unique.Make[string](unsafe.String(&dAtA[iNdEx], intStringLen)).Value() + } + 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 + } + m.unknownFields = append(m.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *UniqueFieldExtension) 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: UniqueFieldExtension: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: UniqueFieldExtension: 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 + } + m.unknownFields = append(m.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} diff --git a/vtproto/ext.pb.go b/vtproto/ext.pb.go index 98c14a66..816fee1a 100644 --- a/vtproto/ext.pb.go +++ b/vtproto/ext.pb.go @@ -11,6 +11,7 @@ import ( protoimpl "google.golang.org/protobuf/runtime/protoimpl" descriptorpb "google.golang.org/protobuf/types/descriptorpb" reflect "reflect" + sync "sync" ) const ( @@ -20,6 +21,55 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) +// These options should be used during schema definition, +// applying them to some of the fields in protobuf +type Opts struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Unique *bool `protobuf:"varint,1,opt,name=unique" json:"unique,omitempty"` +} + +func (x *Opts) Reset() { + *x = Opts{} + if protoimpl.UnsafeEnabled { + mi := &file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Opts) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Opts) ProtoMessage() {} + +func (x *Opts) ProtoReflect() protoreflect.Message { + mi := &file_github_com_planetscale_vtprotobuf_vtproto_ext_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 Opts.ProtoReflect.Descriptor instead. +func (*Opts) Descriptor() ([]byte, []int) { + return file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_rawDescGZIP(), []int{0} +} + +func (x *Opts) GetUnique() bool { + if x != nil && x.Unique != nil { + return *x.Unique + } + return false +} + var file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_extTypes = []protoimpl.ExtensionInfo{ { ExtendedType: (*descriptorpb.MessageOptions)(nil), @@ -29,6 +79,14 @@ var file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_extTypes = []protoi Tag: "varint,64101,opt,name=mempool", Filename: "github.com/planetscale/vtprotobuf/vtproto/ext.proto", }, + { + ExtendedType: (*descriptorpb.FieldOptions)(nil), + ExtensionType: (*Opts)(nil), + Field: 64150, + Name: "vtproto.options", + Tag: "bytes,64150,opt,name=options", + Filename: "github.com/planetscale/vtprotobuf/vtproto/ext.proto", + }, } // Extension fields to descriptorpb.MessageOptions. @@ -37,6 +95,12 @@ var ( E_Mempool = &file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_extTypes[0] ) +// Extension fields to descriptorpb.FieldOptions. +var ( + // optional vtproto.Opts options = 64150; + E_Options = &file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_extTypes[1] +) + var File_github_com_planetscale_vtprotobuf_vtproto_ext_proto protoreflect.FileDescriptor var file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_rawDesc = []byte{ @@ -46,26 +110,50 @@ var file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_rawDesc = []byte{ 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x76, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x20, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x22, 0x1e, 0x0a, 0x04, 0x4f, 0x70, 0x74, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x6e, 0x69, 0x71, + 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x75, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x3a, 0x3b, 0x0a, 0x07, 0x6d, 0x65, 0x6d, 0x70, 0x6f, 0x6f, 0x6c, 0x12, 0x1f, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xe5, 0xf4, 0x03, - 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x6d, 0x65, 0x6d, 0x70, 0x6f, 0x6f, 0x6c, 0x42, 0x49, 0x0a, - 0x13, 0x63, 0x6f, 0x6d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x62, 0x75, 0x66, 0x42, 0x07, 0x56, 0x54, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x5a, 0x29, 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, + 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x6d, 0x65, 0x6d, 0x70, 0x6f, 0x6f, 0x6c, 0x3a, 0x48, 0x0a, + 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, + 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46, 0x69, 0x65, 0x6c, 0x64, + 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x96, 0xf5, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x0d, 0x2e, 0x76, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4f, 0x70, 0x74, 0x73, 0x52, 0x07, + 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x42, 0x49, 0x0a, 0x13, 0x63, 0x6f, 0x6d, 0x2e, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x42, 0x07, + 0x56, 0x54, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x5a, 0x29, 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, } +var ( + file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_rawDescOnce sync.Once + file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_rawDescData = file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_rawDesc +) + +func file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_rawDescGZIP() []byte { + file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_rawDescOnce.Do(func() { + file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_rawDescData = protoimpl.X.CompressGZIP(file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_rawDescData) + }) + return file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_rawDescData +} + +var file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_msgTypes = make([]protoimpl.MessageInfo, 1) var file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_goTypes = []interface{}{ - (*descriptorpb.MessageOptions)(nil), // 0: google.protobuf.MessageOptions + (*Opts)(nil), // 0: vtproto.Opts + (*descriptorpb.MessageOptions)(nil), // 1: google.protobuf.MessageOptions + (*descriptorpb.FieldOptions)(nil), // 2: google.protobuf.FieldOptions } var file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_depIdxs = []int32{ - 0, // 0: vtproto.mempool:extendee -> google.protobuf.MessageOptions - 1, // [1:1] is the sub-list for method output_type - 1, // [1:1] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 0, // [0:1] is the sub-list for extension extendee + 1, // 0: vtproto.mempool:extendee -> google.protobuf.MessageOptions + 2, // 1: vtproto.options:extendee -> google.protobuf.FieldOptions + 0, // 2: vtproto.options:type_name -> vtproto.Opts + 3, // [3:3] is the sub-list for method output_type + 3, // [3:3] is the sub-list for method input_type + 2, // [2:3] is the sub-list for extension type_name + 0, // [0:2] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name } @@ -74,18 +162,33 @@ func file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_init() { if File_github_com_planetscale_vtprotobuf_vtproto_ext_proto != nil { return } + if !protoimpl.UnsafeEnabled { + file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Opts); 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_github_com_planetscale_vtprotobuf_vtproto_ext_proto_rawDesc, NumEnums: 0, - NumMessages: 0, - NumExtensions: 1, + NumMessages: 1, + NumExtensions: 2, NumServices: 0, }, GoTypes: file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_goTypes, DependencyIndexes: file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_depIdxs, + MessageInfos: file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_msgTypes, ExtensionInfos: file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_extTypes, }.Build() File_github_com_planetscale_vtprotobuf_vtproto_ext_proto = out.File