From 25bea0d2117c833afb9fc550858ce7dbe939857f Mon Sep 17 00:00:00 2001 From: Frojdi Dymylja Date: Tue, 28 Sep 2021 16:43:01 +0200 Subject: [PATCH 1/2] add: interface as service spike --- Makefile | 2 +- anyinterface/testpb/iface/iface.proto | 18 + anyinterface/testpb/iface/iface.pulsar.go | 133 +++ anyinterface/testpb/ifaceimpl/ifaceimpl.proto | 17 + .../testpb/ifaceimpl/ifaceimpl.pulsar.go | 462 +++++++++++ cmd/protoc-gen-go-pulsar/main.go | 1 + cosmos.pb.go | 134 ---- cosmos.proto | 14 +- cosmos.pulsar.go | 758 ++++++++++++++++++ features/interfaceservice/feature.go | 39 + features/interfaceservice/generator.go | 102 +++ scripts/fastreflect.sh | 2 +- third_party/proto/google/protobuf/empty.proto | 52 ++ .../proto/google/protobuf/wrappers.proto | 123 +++ 14 files changed, 1720 insertions(+), 137 deletions(-) create mode 100644 anyinterface/testpb/iface/iface.proto create mode 100644 anyinterface/testpb/iface/iface.pulsar.go create mode 100644 anyinterface/testpb/ifaceimpl/ifaceimpl.proto create mode 100644 anyinterface/testpb/ifaceimpl/ifaceimpl.pulsar.go delete mode 100644 cosmos.pb.go create mode 100644 cosmos.pulsar.go create mode 100644 features/interfaceservice/feature.go create mode 100644 features/interfaceservice/generator.go create mode 100644 third_party/proto/google/protobuf/empty.proto create mode 100644 third_party/proto/google/protobuf/wrappers.proto diff --git a/Makefile b/Makefile index 2daa550..48c876e 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -DIRECTORIES_TO_BUILD := "./testpb" +DIRECTORIES_TO_BUILD := "./testpb . ./anyinterface" pulsar: docker build -t dev:proto-build -f Dockerfile . diff --git a/anyinterface/testpb/iface/iface.proto b/anyinterface/testpb/iface/iface.proto new file mode 100644 index 0000000..370fbdc --- /dev/null +++ b/anyinterface/testpb/iface/iface.proto @@ -0,0 +1,18 @@ +syntax="proto3"; + +import "cosmos.proto"; + +package anyinterface.testpb.iface; + +option go_package = "github.com/cosmos/cosmos-proto/anyinterface/testpb/iface"; + +import "google/protobuf/empty.proto"; +import "google/protobuf/wrappers.proto"; + +service Msg { + option (cosmos_proto.interface_service) = {}; + // GetSigners gets the signers + rpc GetSigners(google.protobuf.Empty) returns (google.protobuf.StringValue) {}; + + rpc ValidateBasic(google.protobuf.Empty) returns (google.protobuf.BytesValue) {}; +} diff --git a/anyinterface/testpb/iface/iface.pulsar.go b/anyinterface/testpb/iface/iface.pulsar.go new file mode 100644 index 0000000..1cc55dc --- /dev/null +++ b/anyinterface/testpb/iface/iface.pulsar.go @@ -0,0 +1,133 @@ +package iface + +import ( + reflect "reflect" + + _ "github.com/cosmos/cosmos-proto" + proto "google.golang.org/protobuf/proto" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + anypb "google.golang.org/protobuf/types/known/anypb" + emptypb "google.golang.org/protobuf/types/known/emptypb" + wrapperspb "google.golang.org/protobuf/types/known/wrapperspb" +) + +type Msg interface { + proto.Message + // GetSigners gets the signers + + GetSigners(*emptypb.Empty) (*wrapperspb.StringValue, error) + ValidateBasic(*emptypb.Empty) (*wrapperspb.BytesValue, error) +} + +var _ Msg = (*MsgAny)(nil) + +type ProtoWithInterface struct { + Interface *MsgAny +} + +func NewMsgAny(concrete Msg, packer interface{}) (*MsgAny, error) { + panic("impl") +} + +type MsgAny struct { + any *anypb.Any + iface Msg +} + +func (x *MsgAny) ProtoReflect() protoreflect.Message { + // mocks any behaviour + panic("gencode") +} + +// GetSigners gets the signers + +func (x *MsgAny) GetSigners(in *emptypb.Empty) (*wrapperspb.StringValue, error) { + return x.iface.GetSigners(in) +} + +func (x *MsgAny) ValidateBasic(in *emptypb.Empty) (*wrapperspb.BytesValue, error) { + return x.iface.ValidateBasic(in) +} + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.0 +// protoc v3.15.7 +// source: anyinterface/testpb/iface/iface.proto + +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) +) + +var File_anyinterface_testpb_iface_iface_proto protoreflect.FileDescriptor + +var file_anyinterface_testpb_iface_iface_proto_rawDesc = []byte{ + 0x0a, 0x25, 0x61, 0x6e, 0x79, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x2f, 0x74, + 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, 0x69, 0x66, 0x61, 0x63, 0x65, 0x2f, 0x69, 0x66, 0x61, 0x63, + 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x19, 0x61, 0x6e, 0x79, 0x69, 0x6e, 0x74, 0x65, + 0x72, 0x66, 0x61, 0x63, 0x65, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x69, 0x66, 0x61, + 0x63, 0x65, 0x1a, 0x0c, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, + 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x77, + 0x72, 0x61, 0x70, 0x70, 0x65, 0x72, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x32, 0x99, 0x01, + 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x12, 0x44, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x53, 0x69, 0x67, 0x6e, + 0x65, 0x72, 0x73, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1c, 0x2e, 0x67, 0x6f, + 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x00, 0x12, 0x46, 0x0a, 0x0d, 0x56, + 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x42, 0x61, 0x73, 0x69, 0x63, 0x12, 0x16, 0x2e, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, + 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1b, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x42, 0x79, 0x74, 0x65, 0x73, 0x56, 0x61, 0x6c, 0x75, + 0x65, 0x22, 0x00, 0x1a, 0x04, 0xca, 0xb4, 0x2d, 0x00, 0x42, 0x3a, 0x5a, 0x38, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, + 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x61, 0x6e, 0x79, 0x69, + 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, + 0x69, 0x66, 0x61, 0x63, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var file_anyinterface_testpb_iface_iface_proto_goTypes = []interface{}{ + (*emptypb.Empty)(nil), // 0: google.protobuf.Empty + (*wrapperspb.StringValue)(nil), // 1: google.protobuf.StringValue + (*wrapperspb.BytesValue)(nil), // 2: google.protobuf.BytesValue +} +var file_anyinterface_testpb_iface_iface_proto_depIdxs = []int32{ + 0, // 0: anyinterface.testpb.iface.Msg.GetSigners:input_type -> google.protobuf.Empty + 0, // 1: anyinterface.testpb.iface.Msg.ValidateBasic:input_type -> google.protobuf.Empty + 1, // 2: anyinterface.testpb.iface.Msg.GetSigners:output_type -> google.protobuf.StringValue + 2, // 3: anyinterface.testpb.iface.Msg.ValidateBasic:output_type -> google.protobuf.BytesValue + 2, // [2:4] is the sub-list for method output_type + 0, // [0:2] 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_anyinterface_testpb_iface_iface_proto_init() } +func file_anyinterface_testpb_iface_iface_proto_init() { + if File_anyinterface_testpb_iface_iface_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_anyinterface_testpb_iface_iface_proto_rawDesc, + NumEnums: 0, + NumMessages: 0, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_anyinterface_testpb_iface_iface_proto_goTypes, + DependencyIndexes: file_anyinterface_testpb_iface_iface_proto_depIdxs, + }.Build() + File_anyinterface_testpb_iface_iface_proto = out.File + file_anyinterface_testpb_iface_iface_proto_rawDesc = nil + file_anyinterface_testpb_iface_iface_proto_goTypes = nil + file_anyinterface_testpb_iface_iface_proto_depIdxs = nil +} diff --git a/anyinterface/testpb/ifaceimpl/ifaceimpl.proto b/anyinterface/testpb/ifaceimpl/ifaceimpl.proto new file mode 100644 index 0000000..f04a7f4 --- /dev/null +++ b/anyinterface/testpb/ifaceimpl/ifaceimpl.proto @@ -0,0 +1,17 @@ +syntax="proto3"; + +package anyinterface.testpb.ifaceimpl; + +import "cosmos.proto"; +import "anyinterface/testpb/iface/iface.proto"; + +option go_package = "github.com/cosmos/cosmos-proto/anyinterface/testpb/ifaceimpl"; + +message MsgSend { + option (cosmos_proto.implements_interface) = { + fullname: "anyinterface.testpb.iface.Msg", + }; + string from_address = 1; + string to_address = 2; + string amount = 3; +} \ No newline at end of file diff --git a/anyinterface/testpb/ifaceimpl/ifaceimpl.pulsar.go b/anyinterface/testpb/ifaceimpl/ifaceimpl.pulsar.go new file mode 100644 index 0000000..287cb64 --- /dev/null +++ b/anyinterface/testpb/ifaceimpl/ifaceimpl.pulsar.go @@ -0,0 +1,462 @@ +package ifaceimpl + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-proto/anyinterface/testpb/iface" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoiface "google.golang.org/protobuf/runtime/protoiface" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +var ( + md_MsgSend protoreflect.MessageDescriptor + fd_MsgSend_from_address protoreflect.FieldDescriptor + fd_MsgSend_to_address protoreflect.FieldDescriptor + fd_MsgSend_amount protoreflect.FieldDescriptor +) + +func init() { + file_anyinterface_testpb_ifaceimpl_ifaceimpl_proto_init() + md_MsgSend = File_anyinterface_testpb_ifaceimpl_ifaceimpl_proto.Messages().ByName("MsgSend") + fd_MsgSend_from_address = md_MsgSend.Fields().ByName("from_address") + fd_MsgSend_to_address = md_MsgSend.Fields().ByName("to_address") + fd_MsgSend_amount = md_MsgSend.Fields().ByName("amount") +} + +var _ protoreflect.Message = (*fastReflection_MsgSend)(nil) + +type fastReflection_MsgSend MsgSend + +func (x *MsgSend) ProtoReflect() protoreflect.Message { + return (*fastReflection_MsgSend)(x) +} + +func (x *MsgSend) slowProtoReflect() protoreflect.Message { + mi := &file_anyinterface_testpb_ifaceimpl_ifaceimpl_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) +} + +var _fastReflection_MsgSend_messageType fastReflection_MsgSend_messageType +var _ protoreflect.MessageType = fastReflection_MsgSend_messageType{} + +type fastReflection_MsgSend_messageType struct{} + +func (x fastReflection_MsgSend_messageType) Zero() protoreflect.Message { + return (*fastReflection_MsgSend)(nil) +} +func (x fastReflection_MsgSend_messageType) New() protoreflect.Message { + return new(fastReflection_MsgSend) +} +func (x fastReflection_MsgSend_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_MsgSend +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_MsgSend) Descriptor() protoreflect.MessageDescriptor { + return md_MsgSend +} + +// Type returns the message type, which encapsulates both Go and protobuf +// type information. If the Go type information is not needed, +// it is recommended that the message descriptor be used instead. +func (x *fastReflection_MsgSend) Type() protoreflect.MessageType { + return _fastReflection_MsgSend_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_MsgSend) New() protoreflect.Message { + return new(fastReflection_MsgSend) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_MsgSend) Interface() protoreflect.ProtoMessage { + return (*MsgSend)(x) +} + +// Range iterates over every populated field in an undefined order, +// calling f for each field descriptor and value encountered. +// Range returns immediately if f returns false. +// While iterating, mutating operations may only be performed +// on the current field descriptor. +func (x *fastReflection_MsgSend) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.FromAddress != "" { + value := protoreflect.ValueOfString(x.FromAddress) + if !f(fd_MsgSend_from_address, value) { + return + } + } + if x.ToAddress != "" { + value := protoreflect.ValueOfString(x.ToAddress) + if !f(fd_MsgSend_to_address, value) { + return + } + } + if x.Amount != "" { + value := protoreflect.ValueOfString(x.Amount) + if !f(fd_MsgSend_amount, value) { + return + } + } +} + +// Has reports whether a field is populated. +// +// Some fields have the property of nullability where it is possible to +// distinguish between the default value of a field and whether the field +// was explicitly populated with the default value. Singular message fields, +// member fields of a oneof, and proto2 scalar fields are nullable. Such +// fields are populated only if explicitly set. +// +// In other cases (aside from the nullable cases above), +// a proto3 scalar field is populated if it contains a non-zero value, and +// a repeated field is populated if it is non-empty. +func (x *fastReflection_MsgSend) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "anyinterface.testpb.ifaceimpl.MsgSend.from_address": + return x.FromAddress != "" + case "anyinterface.testpb.ifaceimpl.MsgSend.to_address": + return x.ToAddress != "" + case "anyinterface.testpb.ifaceimpl.MsgSend.amount": + return x.Amount != "" + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: anyinterface.testpb.ifaceimpl.MsgSend")) + } + panic(fmt.Errorf("message anyinterface.testpb.ifaceimpl.MsgSend does not contain field %s", fd.FullName())) + } +} + +// Clear clears the field such that a subsequent Has call reports false. +// +// Clearing an extension field clears both the extension type and value +// associated with the given field number. +// +// Clear is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgSend) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "anyinterface.testpb.ifaceimpl.MsgSend.from_address": + x.FromAddress = "" + case "anyinterface.testpb.ifaceimpl.MsgSend.to_address": + x.ToAddress = "" + case "anyinterface.testpb.ifaceimpl.MsgSend.amount": + x.Amount = "" + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: anyinterface.testpb.ifaceimpl.MsgSend")) + } + panic(fmt.Errorf("message anyinterface.testpb.ifaceimpl.MsgSend does not contain field %s", fd.FullName())) + } +} + +// Get retrieves the value for a field. +// +// For unpopulated scalars, it returns the default value, where +// the default value of a bytes scalar is guaranteed to be a copy. +// For unpopulated composite types, it returns an empty, read-only view +// of the value; to obtain a mutable reference, use Mutable. +func (x *fastReflection_MsgSend) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "anyinterface.testpb.ifaceimpl.MsgSend.from_address": + value := x.FromAddress + return protoreflect.ValueOfString(value) + case "anyinterface.testpb.ifaceimpl.MsgSend.to_address": + value := x.ToAddress + return protoreflect.ValueOfString(value) + case "anyinterface.testpb.ifaceimpl.MsgSend.amount": + value := x.Amount + return protoreflect.ValueOfString(value) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: anyinterface.testpb.ifaceimpl.MsgSend")) + } + panic(fmt.Errorf("message anyinterface.testpb.ifaceimpl.MsgSend does not contain field %s", descriptor.FullName())) + } +} + +// Set stores the value for a field. +// +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType. +// When setting a composite type, it is unspecified whether the stored value +// aliases the source's memory in any way. If the composite value is an +// empty, read-only value, then it panics. +// +// Set is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgSend) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "anyinterface.testpb.ifaceimpl.MsgSend.from_address": + x.FromAddress = value.String() + case "anyinterface.testpb.ifaceimpl.MsgSend.to_address": + x.ToAddress = value.String() + case "anyinterface.testpb.ifaceimpl.MsgSend.amount": + x.Amount = value.String() + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: anyinterface.testpb.ifaceimpl.MsgSend")) + } + panic(fmt.Errorf("message anyinterface.testpb.ifaceimpl.MsgSend does not contain field %s", fd.FullName())) + } +} + +// Mutable returns a mutable reference to a composite type. +// +// If the field is unpopulated, it may allocate a composite value. +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType +// if not already stored. +// It panics if the field does not contain a composite type. +// +// Mutable is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgSend) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "anyinterface.testpb.ifaceimpl.MsgSend.from_address": + panic(fmt.Errorf("field from_address of message anyinterface.testpb.ifaceimpl.MsgSend is not mutable")) + case "anyinterface.testpb.ifaceimpl.MsgSend.to_address": + panic(fmt.Errorf("field to_address of message anyinterface.testpb.ifaceimpl.MsgSend is not mutable")) + case "anyinterface.testpb.ifaceimpl.MsgSend.amount": + panic(fmt.Errorf("field amount of message anyinterface.testpb.ifaceimpl.MsgSend is not mutable")) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: anyinterface.testpb.ifaceimpl.MsgSend")) + } + panic(fmt.Errorf("message anyinterface.testpb.ifaceimpl.MsgSend does not contain field %s", fd.FullName())) + } +} + +// NewField returns a new value that is assignable to the field +// for the given descriptor. For scalars, this returns the default value. +// For lists, maps, and messages, this returns a new, empty, mutable value. +func (x *fastReflection_MsgSend) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "anyinterface.testpb.ifaceimpl.MsgSend.from_address": + return protoreflect.ValueOfString("") + case "anyinterface.testpb.ifaceimpl.MsgSend.to_address": + return protoreflect.ValueOfString("") + case "anyinterface.testpb.ifaceimpl.MsgSend.amount": + return protoreflect.ValueOfString("") + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: anyinterface.testpb.ifaceimpl.MsgSend")) + } + panic(fmt.Errorf("message anyinterface.testpb.ifaceimpl.MsgSend does not contain field %s", fd.FullName())) + } +} + +// WhichOneof reports which field within the oneof is populated, +// returning nil if none are populated. +// It panics if the oneof descriptor does not belong to this message. +func (x *fastReflection_MsgSend) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in anyinterface.testpb.ifaceimpl.MsgSend", d.FullName())) + } + panic("unreachable") +} + +// GetUnknown retrieves the entire list of unknown fields. +// The caller may only mutate the contents of the RawFields +// if the mutated bytes are stored back into the message with SetUnknown. +func (x *fastReflection_MsgSend) GetUnknown() protoreflect.RawFields { + return x.unknownFields +} + +// SetUnknown stores an entire list of unknown fields. +// The raw fields must be syntactically valid according to the wire format. +// An implementation may panic if this is not the case. +// Once stored, the caller must not mutate the content of the RawFields. +// An empty RawFields may be passed to clear the fields. +// +// SetUnknown is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgSend) SetUnknown(fields protoreflect.RawFields) { + x.unknownFields = fields +} + +// IsValid reports whether the message is valid. +// +// An invalid message is an empty, read-only value. +// +// An invalid message often corresponds to a nil pointer of the concrete +// message type, but the details are implementation dependent. +// Validity is not part of the protobuf data model, and may not +// be preserved in marshaling or other operations. +func (x *fastReflection_MsgSend) IsValid() bool { + return x != nil +} + +// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. +// This method may return nil. +// +// The returned methods type is identical to +// "google.golang.org/protobuf/runtime/protoiface".Methods. +// Consult the protoiface package documentation for details. +func (x *fastReflection_MsgSend) ProtoMethods() *protoiface.Methods { + return nil +} + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.0 +// protoc v3.15.7 +// source: anyinterface/testpb/ifaceimpl/ifaceimpl.proto + +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 MsgSend struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + FromAddress string `protobuf:"bytes,1,opt,name=from_address,json=fromAddress,proto3" json:"from_address,omitempty"` + ToAddress string `protobuf:"bytes,2,opt,name=to_address,json=toAddress,proto3" json:"to_address,omitempty"` + Amount string `protobuf:"bytes,3,opt,name=amount,proto3" json:"amount,omitempty"` +} + +func (x *MsgSend) Reset() { + *x = MsgSend{} + if protoimpl.UnsafeEnabled { + mi := &file_anyinterface_testpb_ifaceimpl_ifaceimpl_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MsgSend) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MsgSend) ProtoMessage() {} + +// Deprecated: Use MsgSend.ProtoReflect.Descriptor instead. +func (*MsgSend) Descriptor() ([]byte, []int) { + return file_anyinterface_testpb_ifaceimpl_ifaceimpl_proto_rawDescGZIP(), []int{0} +} + +func (x *MsgSend) GetFromAddress() string { + if x != nil { + return x.FromAddress + } + return "" +} + +func (x *MsgSend) GetToAddress() string { + if x != nil { + return x.ToAddress + } + return "" +} + +func (x *MsgSend) GetAmount() string { + if x != nil { + return x.Amount + } + return "" +} + +var File_anyinterface_testpb_ifaceimpl_ifaceimpl_proto protoreflect.FileDescriptor + +var file_anyinterface_testpb_ifaceimpl_ifaceimpl_proto_rawDesc = []byte{ + 0x0a, 0x2d, 0x61, 0x6e, 0x79, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x2f, 0x74, + 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, 0x69, 0x66, 0x61, 0x63, 0x65, 0x69, 0x6d, 0x70, 0x6c, 0x2f, + 0x69, 0x66, 0x61, 0x63, 0x65, 0x69, 0x6d, 0x70, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, + 0x1d, 0x61, 0x6e, 0x79, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x2e, 0x74, 0x65, + 0x73, 0x74, 0x70, 0x62, 0x2e, 0x69, 0x66, 0x61, 0x63, 0x65, 0x69, 0x6d, 0x70, 0x6c, 0x1a, 0x0c, + 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x25, 0x61, 0x6e, + 0x79, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, + 0x62, 0x2f, 0x69, 0x66, 0x61, 0x63, 0x65, 0x2f, 0x69, 0x66, 0x61, 0x63, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x22, 0x88, 0x01, 0x0a, 0x07, 0x4d, 0x73, 0x67, 0x53, 0x65, 0x6e, 0x64, 0x12, + 0x21, 0x0a, 0x0c, 0x66, 0x72, 0x6f, 0x6d, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x66, 0x72, 0x6f, 0x6d, 0x41, 0x64, 0x64, 0x72, 0x65, + 0x73, 0x73, 0x12, 0x1d, 0x0a, 0x0a, 0x74, 0x6f, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74, 0x6f, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, + 0x73, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x3a, 0x23, 0xca, 0xb4, 0x2d, 0x1f, 0x0a, + 0x1d, 0x61, 0x6e, 0x79, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x2e, 0x74, 0x65, + 0x73, 0x74, 0x70, 0x62, 0x2e, 0x69, 0x66, 0x61, 0x63, 0x65, 0x2e, 0x4d, 0x73, 0x67, 0x42, 0x3e, + 0x5a, 0x3c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, + 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x2f, 0x61, 0x6e, 0x79, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x2f, 0x74, 0x65, + 0x73, 0x74, 0x70, 0x62, 0x2f, 0x69, 0x66, 0x61, 0x63, 0x65, 0x69, 0x6d, 0x70, 0x6c, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_anyinterface_testpb_ifaceimpl_ifaceimpl_proto_rawDescOnce sync.Once + file_anyinterface_testpb_ifaceimpl_ifaceimpl_proto_rawDescData = file_anyinterface_testpb_ifaceimpl_ifaceimpl_proto_rawDesc +) + +func file_anyinterface_testpb_ifaceimpl_ifaceimpl_proto_rawDescGZIP() []byte { + file_anyinterface_testpb_ifaceimpl_ifaceimpl_proto_rawDescOnce.Do(func() { + file_anyinterface_testpb_ifaceimpl_ifaceimpl_proto_rawDescData = protoimpl.X.CompressGZIP(file_anyinterface_testpb_ifaceimpl_ifaceimpl_proto_rawDescData) + }) + return file_anyinterface_testpb_ifaceimpl_ifaceimpl_proto_rawDescData +} + +var file_anyinterface_testpb_ifaceimpl_ifaceimpl_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_anyinterface_testpb_ifaceimpl_ifaceimpl_proto_goTypes = []interface{}{ + (*MsgSend)(nil), // 0: anyinterface.testpb.ifaceimpl.MsgSend +} +var file_anyinterface_testpb_ifaceimpl_ifaceimpl_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_anyinterface_testpb_ifaceimpl_ifaceimpl_proto_init() } +func file_anyinterface_testpb_ifaceimpl_ifaceimpl_proto_init() { + if File_anyinterface_testpb_ifaceimpl_ifaceimpl_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_anyinterface_testpb_ifaceimpl_ifaceimpl_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MsgSend); 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_anyinterface_testpb_ifaceimpl_ifaceimpl_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_anyinterface_testpb_ifaceimpl_ifaceimpl_proto_goTypes, + DependencyIndexes: file_anyinterface_testpb_ifaceimpl_ifaceimpl_proto_depIdxs, + MessageInfos: file_anyinterface_testpb_ifaceimpl_ifaceimpl_proto_msgTypes, + }.Build() + File_anyinterface_testpb_ifaceimpl_ifaceimpl_proto = out.File + file_anyinterface_testpb_ifaceimpl_ifaceimpl_proto_rawDesc = nil + file_anyinterface_testpb_ifaceimpl_ifaceimpl_proto_goTypes = nil + file_anyinterface_testpb_ifaceimpl_ifaceimpl_proto_depIdxs = nil +} diff --git a/cmd/protoc-gen-go-pulsar/main.go b/cmd/protoc-gen-go-pulsar/main.go index d5d0ee2..00e44f0 100644 --- a/cmd/protoc-gen-go-pulsar/main.go +++ b/cmd/protoc-gen-go-pulsar/main.go @@ -7,6 +7,7 @@ import ( _ "github.com/cosmos/cosmos-proto/features/fastreflection" _ "github.com/cosmos/cosmos-proto/features/grpc" + _ "github.com/cosmos/cosmos-proto/features/interfaceservice" _ "github.com/cosmos/cosmos-proto/features/marshal" _ "github.com/cosmos/cosmos-proto/features/pool" _ "github.com/cosmos/cosmos-proto/features/protoc" diff --git a/cosmos.pb.go b/cosmos.pb.go deleted file mode 100644 index 8a0e8c8..0000000 --- a/cosmos.pb.go +++ /dev/null @@ -1,134 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.27.1 -// protoc v3.15.7 -// source: cosmos.proto - -package cosmos_proto - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - descriptorpb "google.golang.org/protobuf/types/descriptorpb" - reflect "reflect" -) - -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) -) - -var file_cosmos_proto_extTypes = []protoimpl.ExtensionInfo{ - { - ExtendedType: (*descriptorpb.MessageOptions)(nil), - ExtensionType: (*string)(nil), - Field: 93001, - Name: "cosmos_proto.implements_interface", - Tag: "bytes,93001,opt,name=implements_interface", - Filename: "cosmos.proto", - }, - { - ExtendedType: (*descriptorpb.FieldOptions)(nil), - ExtensionType: (*string)(nil), - Field: 93001, - Name: "cosmos_proto.accepts_interface", - Tag: "bytes,93001,opt,name=accepts_interface", - Filename: "cosmos.proto", - }, - { - ExtendedType: (*descriptorpb.FieldOptions)(nil), - ExtensionType: (*string)(nil), - Field: 93002, - Name: "cosmos_proto.scalar", - Tag: "bytes,93002,opt,name=scalar", - Filename: "cosmos.proto", - }, -} - -// Extension fields to descriptorpb.MessageOptions. -var ( - // implements_interface is used to annotate interface implementations - // - // optional string implements_interface = 93001; - E_ImplementsInterface = &file_cosmos_proto_extTypes[0] -) - -// Extension fields to descriptorpb.FieldOptions. -var ( - // accepts_interface is used to annote fields that accept interfaces - // - // optional string accepts_interface = 93001; - E_AcceptsInterface = &file_cosmos_proto_extTypes[1] - // scalar is used to define scalar types - // - // optional string scalar = 93002; - E_Scalar = &file_cosmos_proto_extTypes[2] -) - -var File_cosmos_proto protoreflect.FileDescriptor - -var file_cosmos_proto_rawDesc = []byte{ - 0x0a, 0x0c, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0c, - 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5f, 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, 0x3a, 0x54, - 0x0a, 0x14, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x5f, 0x69, 0x6e, 0x74, - 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 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, 0xc9, 0xd6, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x13, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x49, 0x6e, 0x74, 0x65, 0x72, - 0x66, 0x61, 0x63, 0x65, 0x3a, 0x4c, 0x0a, 0x11, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x73, 0x5f, - 0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 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, 0xc9, 0xd6, 0x05, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x10, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x73, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, - 0x63, 0x65, 0x3a, 0x37, 0x0a, 0x06, 0x73, 0x63, 0x61, 0x6c, 0x61, 0x72, 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, 0xca, 0xd6, 0x05, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x63, 0x61, 0x6c, 0x61, 0x72, 0x42, 0x20, 0x5a, 0x1e, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, - 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var file_cosmos_proto_goTypes = []interface{}{ - (*descriptorpb.MessageOptions)(nil), // 0: google.protobuf.MessageOptions - (*descriptorpb.FieldOptions)(nil), // 1: google.protobuf.FieldOptions -} -var file_cosmos_proto_depIdxs = []int32{ - 0, // 0: cosmos_proto.implements_interface:extendee -> google.protobuf.MessageOptions - 1, // 1: cosmos_proto.accepts_interface:extendee -> google.protobuf.FieldOptions - 1, // 2: cosmos_proto.scalar:extendee -> google.protobuf.FieldOptions - 3, // [3:3] is the sub-list for method output_type - 3, // [3:3] is the sub-list for method input_type - 3, // [3:3] is the sub-list for extension type_name - 0, // [0:3] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_cosmos_proto_init() } -func file_cosmos_proto_init() { - if File_cosmos_proto != nil { - return - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_cosmos_proto_rawDesc, - NumEnums: 0, - NumMessages: 0, - NumExtensions: 3, - NumServices: 0, - }, - GoTypes: file_cosmos_proto_goTypes, - DependencyIndexes: file_cosmos_proto_depIdxs, - ExtensionInfos: file_cosmos_proto_extTypes, - }.Build() - File_cosmos_proto = out.File - file_cosmos_proto_rawDesc = nil - file_cosmos_proto_goTypes = nil - file_cosmos_proto_depIdxs = nil -} diff --git a/cosmos.proto b/cosmos.proto index 682d98a..801242a 100644 --- a/cosmos.proto +++ b/cosmos.proto @@ -7,7 +7,11 @@ option go_package = "github.com/cosmos/cosmos-proto"; extend google.protobuf.MessageOptions { // implements_interface is used to annotate interface implementations - string implements_interface = 93001; + ImplementsInterface implements_interface = 93001; +} + +extend google.protobuf.ServiceOptions { + InterfaceService interface_service = 93001; } extend google.protobuf.FieldOptions { @@ -16,3 +20,11 @@ extend google.protobuf.FieldOptions { // scalar is used to define scalar types string scalar = 93002; } + +message InterfaceService { + +} + +message ImplementsInterface { + string fullname = 1; +} \ No newline at end of file diff --git a/cosmos.pulsar.go b/cosmos.pulsar.go new file mode 100644 index 0000000..45c6128 --- /dev/null +++ b/cosmos.pulsar.go @@ -0,0 +1,758 @@ +package cosmos_proto + +import ( + fmt "fmt" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoiface "google.golang.org/protobuf/runtime/protoiface" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + descriptorpb "google.golang.org/protobuf/types/descriptorpb" + reflect "reflect" + sync "sync" +) + +var ( + md_InterfaceService protoreflect.MessageDescriptor +) + +func init() { + file_cosmos_proto_init() + md_InterfaceService = File_cosmos_proto.Messages().ByName("InterfaceService") +} + +var _ protoreflect.Message = (*fastReflection_InterfaceService)(nil) + +type fastReflection_InterfaceService InterfaceService + +func (x *InterfaceService) ProtoReflect() protoreflect.Message { + return (*fastReflection_InterfaceService)(x) +} + +func (x *InterfaceService) slowProtoReflect() protoreflect.Message { + mi := &file_cosmos_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) +} + +var _fastReflection_InterfaceService_messageType fastReflection_InterfaceService_messageType +var _ protoreflect.MessageType = fastReflection_InterfaceService_messageType{} + +type fastReflection_InterfaceService_messageType struct{} + +func (x fastReflection_InterfaceService_messageType) Zero() protoreflect.Message { + return (*fastReflection_InterfaceService)(nil) +} +func (x fastReflection_InterfaceService_messageType) New() protoreflect.Message { + return new(fastReflection_InterfaceService) +} +func (x fastReflection_InterfaceService_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_InterfaceService +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_InterfaceService) Descriptor() protoreflect.MessageDescriptor { + return md_InterfaceService +} + +// Type returns the message type, which encapsulates both Go and protobuf +// type information. If the Go type information is not needed, +// it is recommended that the message descriptor be used instead. +func (x *fastReflection_InterfaceService) Type() protoreflect.MessageType { + return _fastReflection_InterfaceService_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_InterfaceService) New() protoreflect.Message { + return new(fastReflection_InterfaceService) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_InterfaceService) Interface() protoreflect.ProtoMessage { + return (*InterfaceService)(x) +} + +// Range iterates over every populated field in an undefined order, +// calling f for each field descriptor and value encountered. +// Range returns immediately if f returns false. +// While iterating, mutating operations may only be performed +// on the current field descriptor. +func (x *fastReflection_InterfaceService) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { +} + +// Has reports whether a field is populated. +// +// Some fields have the property of nullability where it is possible to +// distinguish between the default value of a field and whether the field +// was explicitly populated with the default value. Singular message fields, +// member fields of a oneof, and proto2 scalar fields are nullable. Such +// fields are populated only if explicitly set. +// +// In other cases (aside from the nullable cases above), +// a proto3 scalar field is populated if it contains a non-zero value, and +// a repeated field is populated if it is non-empty. +func (x *fastReflection_InterfaceService) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos_proto.InterfaceService")) + } + panic(fmt.Errorf("message cosmos_proto.InterfaceService does not contain field %s", fd.FullName())) + } +} + +// Clear clears the field such that a subsequent Has call reports false. +// +// Clearing an extension field clears both the extension type and value +// associated with the given field number. +// +// Clear is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_InterfaceService) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos_proto.InterfaceService")) + } + panic(fmt.Errorf("message cosmos_proto.InterfaceService does not contain field %s", fd.FullName())) + } +} + +// Get retrieves the value for a field. +// +// For unpopulated scalars, it returns the default value, where +// the default value of a bytes scalar is guaranteed to be a copy. +// For unpopulated composite types, it returns an empty, read-only view +// of the value; to obtain a mutable reference, use Mutable. +func (x *fastReflection_InterfaceService) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos_proto.InterfaceService")) + } + panic(fmt.Errorf("message cosmos_proto.InterfaceService does not contain field %s", descriptor.FullName())) + } +} + +// Set stores the value for a field. +// +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType. +// When setting a composite type, it is unspecified whether the stored value +// aliases the source's memory in any way. If the composite value is an +// empty, read-only value, then it panics. +// +// Set is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_InterfaceService) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos_proto.InterfaceService")) + } + panic(fmt.Errorf("message cosmos_proto.InterfaceService does not contain field %s", fd.FullName())) + } +} + +// Mutable returns a mutable reference to a composite type. +// +// If the field is unpopulated, it may allocate a composite value. +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType +// if not already stored. +// It panics if the field does not contain a composite type. +// +// Mutable is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_InterfaceService) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos_proto.InterfaceService")) + } + panic(fmt.Errorf("message cosmos_proto.InterfaceService does not contain field %s", fd.FullName())) + } +} + +// NewField returns a new value that is assignable to the field +// for the given descriptor. For scalars, this returns the default value. +// For lists, maps, and messages, this returns a new, empty, mutable value. +func (x *fastReflection_InterfaceService) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos_proto.InterfaceService")) + } + panic(fmt.Errorf("message cosmos_proto.InterfaceService does not contain field %s", fd.FullName())) + } +} + +// WhichOneof reports which field within the oneof is populated, +// returning nil if none are populated. +// It panics if the oneof descriptor does not belong to this message. +func (x *fastReflection_InterfaceService) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in cosmos_proto.InterfaceService", d.FullName())) + } + panic("unreachable") +} + +// GetUnknown retrieves the entire list of unknown fields. +// The caller may only mutate the contents of the RawFields +// if the mutated bytes are stored back into the message with SetUnknown. +func (x *fastReflection_InterfaceService) GetUnknown() protoreflect.RawFields { + return x.unknownFields +} + +// SetUnknown stores an entire list of unknown fields. +// The raw fields must be syntactically valid according to the wire format. +// An implementation may panic if this is not the case. +// Once stored, the caller must not mutate the content of the RawFields. +// An empty RawFields may be passed to clear the fields. +// +// SetUnknown is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_InterfaceService) SetUnknown(fields protoreflect.RawFields) { + x.unknownFields = fields +} + +// IsValid reports whether the message is valid. +// +// An invalid message is an empty, read-only value. +// +// An invalid message often corresponds to a nil pointer of the concrete +// message type, but the details are implementation dependent. +// Validity is not part of the protobuf data model, and may not +// be preserved in marshaling or other operations. +func (x *fastReflection_InterfaceService) IsValid() bool { + return x != nil +} + +// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. +// This method may return nil. +// +// The returned methods type is identical to +// "google.golang.org/protobuf/runtime/protoiface".Methods. +// Consult the protoiface package documentation for details. +func (x *fastReflection_InterfaceService) ProtoMethods() *protoiface.Methods { + return nil +} + +var ( + md_ImplementsInterface protoreflect.MessageDescriptor + fd_ImplementsInterface_fullname protoreflect.FieldDescriptor +) + +func init() { + file_cosmos_proto_init() + md_ImplementsInterface = File_cosmos_proto.Messages().ByName("ImplementsInterface") + fd_ImplementsInterface_fullname = md_ImplementsInterface.Fields().ByName("fullname") +} + +var _ protoreflect.Message = (*fastReflection_ImplementsInterface)(nil) + +type fastReflection_ImplementsInterface ImplementsInterface + +func (x *ImplementsInterface) ProtoReflect() protoreflect.Message { + return (*fastReflection_ImplementsInterface)(x) +} + +func (x *ImplementsInterface) slowProtoReflect() protoreflect.Message { + mi := &file_cosmos_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) +} + +var _fastReflection_ImplementsInterface_messageType fastReflection_ImplementsInterface_messageType +var _ protoreflect.MessageType = fastReflection_ImplementsInterface_messageType{} + +type fastReflection_ImplementsInterface_messageType struct{} + +func (x fastReflection_ImplementsInterface_messageType) Zero() protoreflect.Message { + return (*fastReflection_ImplementsInterface)(nil) +} +func (x fastReflection_ImplementsInterface_messageType) New() protoreflect.Message { + return new(fastReflection_ImplementsInterface) +} +func (x fastReflection_ImplementsInterface_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_ImplementsInterface +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_ImplementsInterface) Descriptor() protoreflect.MessageDescriptor { + return md_ImplementsInterface +} + +// Type returns the message type, which encapsulates both Go and protobuf +// type information. If the Go type information is not needed, +// it is recommended that the message descriptor be used instead. +func (x *fastReflection_ImplementsInterface) Type() protoreflect.MessageType { + return _fastReflection_ImplementsInterface_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_ImplementsInterface) New() protoreflect.Message { + return new(fastReflection_ImplementsInterface) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_ImplementsInterface) Interface() protoreflect.ProtoMessage { + return (*ImplementsInterface)(x) +} + +// Range iterates over every populated field in an undefined order, +// calling f for each field descriptor and value encountered. +// Range returns immediately if f returns false. +// While iterating, mutating operations may only be performed +// on the current field descriptor. +func (x *fastReflection_ImplementsInterface) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.Fullname != "" { + value := protoreflect.ValueOfString(x.Fullname) + if !f(fd_ImplementsInterface_fullname, value) { + return + } + } +} + +// Has reports whether a field is populated. +// +// Some fields have the property of nullability where it is possible to +// distinguish between the default value of a field and whether the field +// was explicitly populated with the default value. Singular message fields, +// member fields of a oneof, and proto2 scalar fields are nullable. Such +// fields are populated only if explicitly set. +// +// In other cases (aside from the nullable cases above), +// a proto3 scalar field is populated if it contains a non-zero value, and +// a repeated field is populated if it is non-empty. +func (x *fastReflection_ImplementsInterface) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "cosmos_proto.ImplementsInterface.fullname": + return x.Fullname != "" + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos_proto.ImplementsInterface")) + } + panic(fmt.Errorf("message cosmos_proto.ImplementsInterface does not contain field %s", fd.FullName())) + } +} + +// Clear clears the field such that a subsequent Has call reports false. +// +// Clearing an extension field clears both the extension type and value +// associated with the given field number. +// +// Clear is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_ImplementsInterface) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "cosmos_proto.ImplementsInterface.fullname": + x.Fullname = "" + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos_proto.ImplementsInterface")) + } + panic(fmt.Errorf("message cosmos_proto.ImplementsInterface does not contain field %s", fd.FullName())) + } +} + +// Get retrieves the value for a field. +// +// For unpopulated scalars, it returns the default value, where +// the default value of a bytes scalar is guaranteed to be a copy. +// For unpopulated composite types, it returns an empty, read-only view +// of the value; to obtain a mutable reference, use Mutable. +func (x *fastReflection_ImplementsInterface) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "cosmos_proto.ImplementsInterface.fullname": + value := x.Fullname + return protoreflect.ValueOfString(value) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos_proto.ImplementsInterface")) + } + panic(fmt.Errorf("message cosmos_proto.ImplementsInterface does not contain field %s", descriptor.FullName())) + } +} + +// Set stores the value for a field. +// +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType. +// When setting a composite type, it is unspecified whether the stored value +// aliases the source's memory in any way. If the composite value is an +// empty, read-only value, then it panics. +// +// Set is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_ImplementsInterface) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "cosmos_proto.ImplementsInterface.fullname": + x.Fullname = value.String() + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos_proto.ImplementsInterface")) + } + panic(fmt.Errorf("message cosmos_proto.ImplementsInterface does not contain field %s", fd.FullName())) + } +} + +// Mutable returns a mutable reference to a composite type. +// +// If the field is unpopulated, it may allocate a composite value. +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType +// if not already stored. +// It panics if the field does not contain a composite type. +// +// Mutable is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_ImplementsInterface) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "cosmos_proto.ImplementsInterface.fullname": + panic(fmt.Errorf("field fullname of message cosmos_proto.ImplementsInterface is not mutable")) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos_proto.ImplementsInterface")) + } + panic(fmt.Errorf("message cosmos_proto.ImplementsInterface does not contain field %s", fd.FullName())) + } +} + +// NewField returns a new value that is assignable to the field +// for the given descriptor. For scalars, this returns the default value. +// For lists, maps, and messages, this returns a new, empty, mutable value. +func (x *fastReflection_ImplementsInterface) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "cosmos_proto.ImplementsInterface.fullname": + return protoreflect.ValueOfString("") + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos_proto.ImplementsInterface")) + } + panic(fmt.Errorf("message cosmos_proto.ImplementsInterface does not contain field %s", fd.FullName())) + } +} + +// WhichOneof reports which field within the oneof is populated, +// returning nil if none are populated. +// It panics if the oneof descriptor does not belong to this message. +func (x *fastReflection_ImplementsInterface) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in cosmos_proto.ImplementsInterface", d.FullName())) + } + panic("unreachable") +} + +// GetUnknown retrieves the entire list of unknown fields. +// The caller may only mutate the contents of the RawFields +// if the mutated bytes are stored back into the message with SetUnknown. +func (x *fastReflection_ImplementsInterface) GetUnknown() protoreflect.RawFields { + return x.unknownFields +} + +// SetUnknown stores an entire list of unknown fields. +// The raw fields must be syntactically valid according to the wire format. +// An implementation may panic if this is not the case. +// Once stored, the caller must not mutate the content of the RawFields. +// An empty RawFields may be passed to clear the fields. +// +// SetUnknown is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_ImplementsInterface) SetUnknown(fields protoreflect.RawFields) { + x.unknownFields = fields +} + +// IsValid reports whether the message is valid. +// +// An invalid message is an empty, read-only value. +// +// An invalid message often corresponds to a nil pointer of the concrete +// message type, but the details are implementation dependent. +// Validity is not part of the protobuf data model, and may not +// be preserved in marshaling or other operations. +func (x *fastReflection_ImplementsInterface) IsValid() bool { + return x != nil +} + +// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. +// This method may return nil. +// +// The returned methods type is identical to +// "google.golang.org/protobuf/runtime/protoiface".Methods. +// Consult the protoiface package documentation for details. +func (x *fastReflection_ImplementsInterface) ProtoMethods() *protoiface.Methods { + return nil +} + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.0 +// protoc v3.15.7 +// source: cosmos.proto + +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 InterfaceService struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *InterfaceService) Reset() { + *x = InterfaceService{} + if protoimpl.UnsafeEnabled { + mi := &file_cosmos_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *InterfaceService) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*InterfaceService) ProtoMessage() {} + +// Deprecated: Use InterfaceService.ProtoReflect.Descriptor instead. +func (*InterfaceService) Descriptor() ([]byte, []int) { + return file_cosmos_proto_rawDescGZIP(), []int{0} +} + +type ImplementsInterface struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Fullname string `protobuf:"bytes,1,opt,name=fullname,proto3" json:"fullname,omitempty"` +} + +func (x *ImplementsInterface) Reset() { + *x = ImplementsInterface{} + if protoimpl.UnsafeEnabled { + mi := &file_cosmos_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ImplementsInterface) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ImplementsInterface) ProtoMessage() {} + +// Deprecated: Use ImplementsInterface.ProtoReflect.Descriptor instead. +func (*ImplementsInterface) Descriptor() ([]byte, []int) { + return file_cosmos_proto_rawDescGZIP(), []int{1} +} + +func (x *ImplementsInterface) GetFullname() string { + if x != nil { + return x.Fullname + } + return "" +} + +var file_cosmos_proto_extTypes = []protoimpl.ExtensionInfo{ + { + ExtendedType: (*descriptorpb.MessageOptions)(nil), + ExtensionType: (*ImplementsInterface)(nil), + Field: 93001, + Name: "cosmos_proto.implements_interface", + Tag: "bytes,93001,opt,name=implements_interface", + Filename: "cosmos.proto", + }, + { + ExtendedType: (*descriptorpb.ServiceOptions)(nil), + ExtensionType: (*InterfaceService)(nil), + Field: 93001, + Name: "cosmos_proto.interface_service", + Tag: "bytes,93001,opt,name=interface_service", + Filename: "cosmos.proto", + }, + { + ExtendedType: (*descriptorpb.FieldOptions)(nil), + ExtensionType: (*string)(nil), + Field: 93001, + Name: "cosmos_proto.accepts_interface", + Tag: "bytes,93001,opt,name=accepts_interface", + Filename: "cosmos.proto", + }, + { + ExtendedType: (*descriptorpb.FieldOptions)(nil), + ExtensionType: (*string)(nil), + Field: 93002, + Name: "cosmos_proto.scalar", + Tag: "bytes,93002,opt,name=scalar", + Filename: "cosmos.proto", + }, +} + +// Extension fields to descriptorpb.MessageOptions. +var ( + // implements_interface is used to annotate interface implementations + // + // optional cosmos_proto.ImplementsInterface implements_interface = 93001; + E_ImplementsInterface = &file_cosmos_proto_extTypes[0] +) + +// Extension fields to descriptorpb.ServiceOptions. +var ( + // optional cosmos_proto.InterfaceService interface_service = 93001; + E_InterfaceService = &file_cosmos_proto_extTypes[1] +) + +// Extension fields to descriptorpb.FieldOptions. +var ( + // accepts_interface is used to annote fields that accept interfaces + // + // optional string accepts_interface = 93001; + E_AcceptsInterface = &file_cosmos_proto_extTypes[2] + // scalar is used to define scalar types + // + // optional string scalar = 93002; + E_Scalar = &file_cosmos_proto_extTypes[3] +) + +var File_cosmos_proto protoreflect.FileDescriptor + +var file_cosmos_proto_rawDesc = []byte{ + 0x0a, 0x0c, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0c, + 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5f, 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, 0x12, + 0x0a, 0x10, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x22, 0x31, 0x0a, 0x13, 0x49, 0x6d, 0x70, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x73, + 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x75, 0x6c, + 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, 0x75, 0x6c, + 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x3a, 0x77, 0x0a, 0x14, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x6d, 0x65, + 0x6e, 0x74, 0x73, 0x5f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 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, 0xc9, + 0xd6, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5f, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x49, 0x6d, 0x70, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x73, + 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x52, 0x13, 0x69, 0x6d, 0x70, 0x6c, 0x65, + 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x3a, 0x6e, + 0x0a, 0x11, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x5f, 0x73, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x12, 0x1f, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x4f, 0x70, 0x74, + 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xc9, 0xd6, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x63, + 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x49, 0x6e, 0x74, 0x65, + 0x72, 0x66, 0x61, 0x63, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x10, 0x69, 0x6e, + 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x3a, 0x4c, + 0x0a, 0x11, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x73, 0x5f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, + 0x61, 0x63, 0x65, 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, 0xc9, 0xd6, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x61, 0x63, 0x63, 0x65, + 0x70, 0x74, 0x73, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x3a, 0x37, 0x0a, 0x06, + 0x73, 0x63, 0x61, 0x6c, 0x61, 0x72, 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, 0xca, 0xd6, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, + 0x63, 0x61, 0x6c, 0x61, 0x72, 0x42, 0x20, 0x5a, 0x1e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, + 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x2d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_cosmos_proto_rawDescOnce sync.Once + file_cosmos_proto_rawDescData = file_cosmos_proto_rawDesc +) + +func file_cosmos_proto_rawDescGZIP() []byte { + file_cosmos_proto_rawDescOnce.Do(func() { + file_cosmos_proto_rawDescData = protoimpl.X.CompressGZIP(file_cosmos_proto_rawDescData) + }) + return file_cosmos_proto_rawDescData +} + +var file_cosmos_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_cosmos_proto_goTypes = []interface{}{ + (*InterfaceService)(nil), // 0: cosmos_proto.InterfaceService + (*ImplementsInterface)(nil), // 1: cosmos_proto.ImplementsInterface + (*descriptorpb.MessageOptions)(nil), // 2: google.protobuf.MessageOptions + (*descriptorpb.ServiceOptions)(nil), // 3: google.protobuf.ServiceOptions + (*descriptorpb.FieldOptions)(nil), // 4: google.protobuf.FieldOptions +} +var file_cosmos_proto_depIdxs = []int32{ + 2, // 0: cosmos_proto.implements_interface:extendee -> google.protobuf.MessageOptions + 3, // 1: cosmos_proto.interface_service:extendee -> google.protobuf.ServiceOptions + 4, // 2: cosmos_proto.accepts_interface:extendee -> google.protobuf.FieldOptions + 4, // 3: cosmos_proto.scalar:extendee -> google.protobuf.FieldOptions + 1, // 4: cosmos_proto.implements_interface:type_name -> cosmos_proto.ImplementsInterface + 0, // 5: cosmos_proto.interface_service:type_name -> cosmos_proto.InterfaceService + 6, // [6:6] is the sub-list for method output_type + 6, // [6:6] is the sub-list for method input_type + 4, // [4:6] is the sub-list for extension type_name + 0, // [0:4] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_cosmos_proto_init() } +func file_cosmos_proto_init() { + if File_cosmos_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_cosmos_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*InterfaceService); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_cosmos_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ImplementsInterface); 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_cosmos_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 4, + NumServices: 0, + }, + GoTypes: file_cosmos_proto_goTypes, + DependencyIndexes: file_cosmos_proto_depIdxs, + MessageInfos: file_cosmos_proto_msgTypes, + ExtensionInfos: file_cosmos_proto_extTypes, + }.Build() + File_cosmos_proto = out.File + file_cosmos_proto_rawDesc = nil + file_cosmos_proto_goTypes = nil + file_cosmos_proto_depIdxs = nil +} diff --git a/features/interfaceservice/feature.go b/features/interfaceservice/feature.go new file mode 100644 index 0000000..a2e0290 --- /dev/null +++ b/features/interfaceservice/feature.go @@ -0,0 +1,39 @@ +package interfaceservice + +import ( + cosmos_proto "github.com/cosmos/cosmos-proto" + "github.com/cosmos/cosmos-proto/generator" + "google.golang.org/protobuf/compiler/protogen" + "google.golang.org/protobuf/proto" +) + +func init() { + generator.RegisterFeature("interfaceservice", func(gen *generator.GeneratedFile, plugin *protogen.Plugin) generator.FeatureGenerator { + return &interfaceService{GeneratedFile: gen} + }) +} + +type interfaceService struct { + *generator.GeneratedFile +} + +func (i interfaceService) GenerateFile(file *protogen.File, plugin *protogen.Plugin) bool { + for _, svc := range file.Services { + options := svc.Desc.Options() + xt := proto.GetExtension(options, cosmos_proto.E_InterfaceService).(*cosmos_proto.InterfaceService) + if xt == nil { + continue + } + err := (&gen{file: file, plugin: plugin, svc: svc, desc: xt, GeneratedFile: i.GeneratedFile}).generate() + if err != nil { + plugin.Error(err) + panic(err) // TODO: do we need to panic? + } + } + + return true +} + +func (i interfaceService) GenerateHelpers() { + +} diff --git a/features/interfaceservice/generator.go b/features/interfaceservice/generator.go new file mode 100644 index 0000000..b456b94 --- /dev/null +++ b/features/interfaceservice/generator.go @@ -0,0 +1,102 @@ +package interfaceservice + +import ( + "fmt" + + cosmos_proto "github.com/cosmos/cosmos-proto" + "github.com/cosmos/cosmos-proto/generator" + "google.golang.org/protobuf/compiler/protogen" +) + +const ( + protoImportPath = protogen.GoImportPath("google.golang.org/protobuf/proto") + anyImportPath = protogen.GoImportPath("google.golang.org/protobuf/types/known/anypb") +) + +type gen struct { + *generator.GeneratedFile + svc *protogen.Service + file *protogen.File + plugin *protogen.Plugin + desc *cosmos_proto.InterfaceService +} + +func (g *gen) generate() error { + if err := g.genInterface(); err != nil { + return err + } + + if err := g.genAnyInterface(); err != nil { + return err + } + + return nil +} + +func (g *gen) genInterface() error { + // generate the interface + g.Import(protoImportPath) + g.P("type ", interfaceServiceName(g.svc), " interface {") + g.P(protoImportPath.Ident("Message")) + // gen interface methods + for _, method := range g.svc.Methods { + if g.svc.Desc.ParentFile() != method.Input.Desc.ParentFile() { + g.Import(method.Input.GoIdent.GoImportPath) + } + if g.svc.Desc.ParentFile() != method.Output.Desc.ParentFile() { + g.Import(method.Output.GoIdent.GoImportPath) + } + // TODO: comments in a proper way + if len(method.Comments.Leading) != 0 { + g.P(method.Comments.Leading.String()) + } + + g.P(method.GoName, "(*", g.QualifiedGoIdent(method.Input.GoIdent), ") (*", g.QualifiedGoIdent(method.Output.GoIdent), ", error)") + } + g.P("}") + + g.P() + return nil +} + +func (g *gen) genAnyInterface() error { + name := anyInterfaceName(g.svc) + + // interface assertion + g.P("var _ ", interfaceServiceName(g.svc), " = (*", name, ")(nil)") + // type creation + g.P("type ", name, " struct {") + g.P("any *", anyImportPath.Ident("Any")) + g.P("iface ", g.svc.GoName) + g.P("}") + g.P() + // type implementation + for _, method := range g.svc.Methods { + if g.svc.Desc.ParentFile() != method.Input.Desc.ParentFile() { + g.Import(method.Input.GoIdent.GoImportPath) + } + if g.svc.Desc.ParentFile() != method.Output.Desc.ParentFile() { + g.Import(method.Output.GoIdent.GoImportPath) + } + // TODO: comments in a proper way + if len(method.Comments.Leading) != 0 { + g.P(method.Comments.Leading.String()) + } + + g.P("func (x *", name, ")", method.GoName, "(in *", g.QualifiedGoIdent(method.Input.GoIdent), ") (*", g.QualifiedGoIdent(method.Output.GoIdent), ", error) {") + g.P("return x.iface.", method.GoName, "(in)") + g.P("}") + g.P() + } + g.P() + // type constructor + return nil +} + +func interfaceServiceName(svc *protogen.Service) string { + return svc.GoName +} + +func anyInterfaceName(svc *protogen.Service) string { + return fmt.Sprintf("%sAny", svc.GoName) +} diff --git a/scripts/fastreflect.sh b/scripts/fastreflect.sh index c259381..0b40aea 100755 --- a/scripts/fastreflect.sh +++ b/scripts/fastreflect.sh @@ -7,7 +7,7 @@ build() { proto_files=$(find "$1" -name "*.proto") for file in $proto_files; do echo "building proto file $file" - protoc -I=. -I=./third_party/proto --plugin /usr/bin/protoc-gen-go-pulsar --go-pulsar_out=. --go-pulsar_opt=features=fast+protoc "$file" + protoc -I=. -I=./third_party/proto --plugin /usr/bin/protoc-gen-go-pulsar --go-pulsar_out=. --go-pulsar_opt=features=fast+protoc+interfaceservice "$file" done } diff --git a/third_party/proto/google/protobuf/empty.proto b/third_party/proto/google/protobuf/empty.proto new file mode 100644 index 0000000..87e7411 --- /dev/null +++ b/third_party/proto/google/protobuf/empty.proto @@ -0,0 +1,52 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option go_package = "google.golang.org/protobuf/types/known/emptypb"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "EmptyProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; +option cc_enable_arenas = true; + +// A generic empty message that you can re-use to avoid defining duplicated +// empty messages in your APIs. A typical example is to use it as the request +// or the response type of an API method. For instance: +// +// service Foo { +// rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); +// } +// +// The JSON representation for `Empty` is empty JSON object `{}`. +message Empty {} \ No newline at end of file diff --git a/third_party/proto/google/protobuf/wrappers.proto b/third_party/proto/google/protobuf/wrappers.proto new file mode 100644 index 0000000..c571f09 --- /dev/null +++ b/third_party/proto/google/protobuf/wrappers.proto @@ -0,0 +1,123 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Wrappers for primitive (non-message) types. These types are useful +// for embedding primitives in the `google.protobuf.Any` type and for places +// where we need to distinguish between the absence of a primitive +// typed field and its default value. +// +// These wrappers have no meaningful use within repeated fields as they lack +// the ability to detect presence on individual elements. +// These wrappers have no meaningful use within a map or a oneof since +// individual entries of a map or fields of a oneof can already detect presence. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option cc_enable_arenas = true; +option go_package = "google.golang.org/protobuf/types/known/wrapperspb"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "WrappersProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; + +// Wrapper message for `double`. +// +// The JSON representation for `DoubleValue` is JSON number. +message DoubleValue { + // The double value. + double value = 1; +} + +// Wrapper message for `float`. +// +// The JSON representation for `FloatValue` is JSON number. +message FloatValue { + // The float value. + float value = 1; +} + +// Wrapper message for `int64`. +// +// The JSON representation for `Int64Value` is JSON string. +message Int64Value { + // The int64 value. + int64 value = 1; +} + +// Wrapper message for `uint64`. +// +// The JSON representation for `UInt64Value` is JSON string. +message UInt64Value { + // The uint64 value. + uint64 value = 1; +} + +// Wrapper message for `int32`. +// +// The JSON representation for `Int32Value` is JSON number. +message Int32Value { + // The int32 value. + int32 value = 1; +} + +// Wrapper message for `uint32`. +// +// The JSON representation for `UInt32Value` is JSON number. +message UInt32Value { + // The uint32 value. + uint32 value = 1; +} + +// Wrapper message for `bool`. +// +// The JSON representation for `BoolValue` is JSON `true` and `false`. +message BoolValue { + // The bool value. + bool value = 1; +} + +// Wrapper message for `string`. +// +// The JSON representation for `StringValue` is JSON string. +message StringValue { + // The string value. + string value = 1; +} + +// Wrapper message for `bytes`. +// +// The JSON representation for `BytesValue` is JSON string. +message BytesValue { + // The bytes value. + bytes value = 1; +} \ No newline at end of file From d655ef71091dc93e240d06dff0bd4fd0ef288e1d Mon Sep 17 00:00:00 2001 From: Frojdi Dymylja Date: Fri, 1 Oct 2021 11:07:41 +0200 Subject: [PATCH 2/2] add: interface accepter code --- anyinterface/testpb/iface/iface.pulsar.go | 16 +- .../testpb/ifaceaccepter/ifaceaccepter.proto | 13 + .../ifaceaccepter/ifaceaccepter.pulsar.go | 410 ++++++++++++++++++ features/interfaceservice/generator.go | 10 +- features/protoc/main.go | 53 ++- internal/strs/strings.go | 183 ++++++++ third_party/proto/google/protobuf/any.proto | 158 +++++++ 7 files changed, 812 insertions(+), 31 deletions(-) create mode 100644 anyinterface/testpb/ifaceaccepter/ifaceaccepter.proto create mode 100644 anyinterface/testpb/ifaceaccepter/ifaceaccepter.pulsar.go create mode 100644 internal/strs/strings.go create mode 100644 third_party/proto/google/protobuf/any.proto diff --git a/anyinterface/testpb/iface/iface.pulsar.go b/anyinterface/testpb/iface/iface.pulsar.go index 1cc55dc..f701b23 100644 --- a/anyinterface/testpb/iface/iface.pulsar.go +++ b/anyinterface/testpb/iface/iface.pulsar.go @@ -1,8 +1,6 @@ package iface import ( - reflect "reflect" - _ "github.com/cosmos/cosmos-proto" proto "google.golang.org/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" @@ -10,6 +8,7 @@ import ( anypb "google.golang.org/protobuf/types/known/anypb" emptypb "google.golang.org/protobuf/types/known/emptypb" wrapperspb "google.golang.org/protobuf/types/known/wrapperspb" + reflect "reflect" ) type Msg interface { @@ -22,24 +21,11 @@ type Msg interface { var _ Msg = (*MsgAny)(nil) -type ProtoWithInterface struct { - Interface *MsgAny -} - -func NewMsgAny(concrete Msg, packer interface{}) (*MsgAny, error) { - panic("impl") -} - type MsgAny struct { any *anypb.Any iface Msg } -func (x *MsgAny) ProtoReflect() protoreflect.Message { - // mocks any behaviour - panic("gencode") -} - // GetSigners gets the signers func (x *MsgAny) GetSigners(in *emptypb.Empty) (*wrapperspb.StringValue, error) { diff --git a/anyinterface/testpb/ifaceaccepter/ifaceaccepter.proto b/anyinterface/testpb/ifaceaccepter/ifaceaccepter.proto new file mode 100644 index 0000000..93796e7 --- /dev/null +++ b/anyinterface/testpb/ifaceaccepter/ifaceaccepter.proto @@ -0,0 +1,13 @@ +syntax="proto3"; + +package anyinterface.testpb.ifaceaccepter; + +import "cosmos.proto"; +import "anyinterface/testpb/iface/iface.proto"; +import "google/protobuf/any.proto"; + +option go_package = "github.com/cosmos/cosmos-proto/anyinterface/testpb/ifaceaccepter"; + +message Tx { + google.protobuf.Any Msg = 1 [(cosmos_proto.accepts_interface) = "anyinterface.testpb.iface.Msg"]; +} \ No newline at end of file diff --git a/anyinterface/testpb/ifaceaccepter/ifaceaccepter.pulsar.go b/anyinterface/testpb/ifaceaccepter/ifaceaccepter.pulsar.go new file mode 100644 index 0000000..8840651 --- /dev/null +++ b/anyinterface/testpb/ifaceaccepter/ifaceaccepter.pulsar.go @@ -0,0 +1,410 @@ +package ifaceaccepter + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + iface "github.com/cosmos/cosmos-proto/anyinterface/testpb/iface" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoiface "google.golang.org/protobuf/runtime/protoiface" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + anypb "google.golang.org/protobuf/types/known/anypb" + reflect "reflect" + sync "sync" +) + +var ( + md_Tx protoreflect.MessageDescriptor + fd_Tx_Msg protoreflect.FieldDescriptor +) + +func init() { + file_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto_init() + md_Tx = File_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto.Messages().ByName("Tx") + fd_Tx_Msg = md_Tx.Fields().ByName("Msg") +} + +var _ protoreflect.Message = (*fastReflection_Tx)(nil) + +type fastReflection_Tx Tx + +func (x *Tx) ProtoReflect() protoreflect.Message { + return (*fastReflection_Tx)(x) +} + +func (x *Tx) slowProtoReflect() protoreflect.Message { + mi := &file_anyinterface_testpb_ifaceaccepter_ifaceaccepter_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) +} + +var _fastReflection_Tx_messageType fastReflection_Tx_messageType +var _ protoreflect.MessageType = fastReflection_Tx_messageType{} + +type fastReflection_Tx_messageType struct{} + +func (x fastReflection_Tx_messageType) Zero() protoreflect.Message { + return (*fastReflection_Tx)(nil) +} +func (x fastReflection_Tx_messageType) New() protoreflect.Message { + return new(fastReflection_Tx) +} +func (x fastReflection_Tx_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_Tx +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_Tx) Descriptor() protoreflect.MessageDescriptor { + return md_Tx +} + +// Type returns the message type, which encapsulates both Go and protobuf +// type information. If the Go type information is not needed, +// it is recommended that the message descriptor be used instead. +func (x *fastReflection_Tx) Type() protoreflect.MessageType { + return _fastReflection_Tx_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_Tx) New() protoreflect.Message { + return new(fastReflection_Tx) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_Tx) Interface() protoreflect.ProtoMessage { + return (*Tx)(x) +} + +// Range iterates over every populated field in an undefined order, +// calling f for each field descriptor and value encountered. +// Range returns immediately if f returns false. +// While iterating, mutating operations may only be performed +// on the current field descriptor. +func (x *fastReflection_Tx) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.Msg != nil { + value := protoreflect.ValueOfMessage(x.Msg.ProtoReflect()) + if !f(fd_Tx_Msg, value) { + return + } + } +} + +// Has reports whether a field is populated. +// +// Some fields have the property of nullability where it is possible to +// distinguish between the default value of a field and whether the field +// was explicitly populated with the default value. Singular message fields, +// member fields of a oneof, and proto2 scalar fields are nullable. Such +// fields are populated only if explicitly set. +// +// In other cases (aside from the nullable cases above), +// a proto3 scalar field is populated if it contains a non-zero value, and +// a repeated field is populated if it is non-empty. +func (x *fastReflection_Tx) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "anyinterface.testpb.ifaceaccepter.Tx.Msg": + return x.Msg != nil + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: anyinterface.testpb.ifaceaccepter.Tx")) + } + panic(fmt.Errorf("message anyinterface.testpb.ifaceaccepter.Tx does not contain field %s", fd.FullName())) + } +} + +// Clear clears the field such that a subsequent Has call reports false. +// +// Clearing an extension field clears both the extension type and value +// associated with the given field number. +// +// Clear is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_Tx) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "anyinterface.testpb.ifaceaccepter.Tx.Msg": + x.Msg = nil + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: anyinterface.testpb.ifaceaccepter.Tx")) + } + panic(fmt.Errorf("message anyinterface.testpb.ifaceaccepter.Tx does not contain field %s", fd.FullName())) + } +} + +// Get retrieves the value for a field. +// +// For unpopulated scalars, it returns the default value, where +// the default value of a bytes scalar is guaranteed to be a copy. +// For unpopulated composite types, it returns an empty, read-only view +// of the value; to obtain a mutable reference, use Mutable. +func (x *fastReflection_Tx) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "anyinterface.testpb.ifaceaccepter.Tx.Msg": + value := x.Msg + return protoreflect.ValueOfMessage(value.ProtoReflect()) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: anyinterface.testpb.ifaceaccepter.Tx")) + } + panic(fmt.Errorf("message anyinterface.testpb.ifaceaccepter.Tx does not contain field %s", descriptor.FullName())) + } +} + +// Set stores the value for a field. +// +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType. +// When setting a composite type, it is unspecified whether the stored value +// aliases the source's memory in any way. If the composite value is an +// empty, read-only value, then it panics. +// +// Set is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_Tx) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "anyinterface.testpb.ifaceaccepter.Tx.Msg": + x.Msg = value.Message().Interface().(*anypb.Any) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: anyinterface.testpb.ifaceaccepter.Tx")) + } + panic(fmt.Errorf("message anyinterface.testpb.ifaceaccepter.Tx does not contain field %s", fd.FullName())) + } +} + +// Mutable returns a mutable reference to a composite type. +// +// If the field is unpopulated, it may allocate a composite value. +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType +// if not already stored. +// It panics if the field does not contain a composite type. +// +// Mutable is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_Tx) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "anyinterface.testpb.ifaceaccepter.Tx.Msg": + if x.Msg == nil { + x.Msg = new(anypb.Any) + } + return protoreflect.ValueOfMessage(x.Msg.ProtoReflect()) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: anyinterface.testpb.ifaceaccepter.Tx")) + } + panic(fmt.Errorf("message anyinterface.testpb.ifaceaccepter.Tx does not contain field %s", fd.FullName())) + } +} + +// NewField returns a new value that is assignable to the field +// for the given descriptor. For scalars, this returns the default value. +// For lists, maps, and messages, this returns a new, empty, mutable value. +func (x *fastReflection_Tx) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "anyinterface.testpb.ifaceaccepter.Tx.Msg": + m := new(anypb.Any) + return protoreflect.ValueOfMessage(m.ProtoReflect()) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: anyinterface.testpb.ifaceaccepter.Tx")) + } + panic(fmt.Errorf("message anyinterface.testpb.ifaceaccepter.Tx does not contain field %s", fd.FullName())) + } +} + +// WhichOneof reports which field within the oneof is populated, +// returning nil if none are populated. +// It panics if the oneof descriptor does not belong to this message. +func (x *fastReflection_Tx) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in anyinterface.testpb.ifaceaccepter.Tx", d.FullName())) + } + panic("unreachable") +} + +// GetUnknown retrieves the entire list of unknown fields. +// The caller may only mutate the contents of the RawFields +// if the mutated bytes are stored back into the message with SetUnknown. +func (x *fastReflection_Tx) GetUnknown() protoreflect.RawFields { + return x.unknownFields +} + +// SetUnknown stores an entire list of unknown fields. +// The raw fields must be syntactically valid according to the wire format. +// An implementation may panic if this is not the case. +// Once stored, the caller must not mutate the content of the RawFields. +// An empty RawFields may be passed to clear the fields. +// +// SetUnknown is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_Tx) SetUnknown(fields protoreflect.RawFields) { + x.unknownFields = fields +} + +// IsValid reports whether the message is valid. +// +// An invalid message is an empty, read-only value. +// +// An invalid message often corresponds to a nil pointer of the concrete +// message type, but the details are implementation dependent. +// Validity is not part of the protobuf data model, and may not +// be preserved in marshaling or other operations. +func (x *fastReflection_Tx) IsValid() bool { + return x != nil +} + +// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. +// This method may return nil. +// +// The returned methods type is identical to +// "google.golang.org/protobuf/runtime/protoiface".Methods. +// Consult the protoiface package documentation for details. +func (x *fastReflection_Tx) ProtoMethods() *protoiface.Methods { + return nil +} + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.0 +// protoc v3.15.7 +// source: anyinterface/testpb/ifaceaccepter/ifaceaccepter.proto + +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 Tx struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Msg *iface.MsgAny `protobuf:"bytes,1,opt,name=Msg,proto3" json:"Msg,omitempty"` +} + +func (x *Tx) Reset() { + *x = Tx{} + if protoimpl.UnsafeEnabled { + mi := &file_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Tx) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Tx) ProtoMessage() {} + +// Deprecated: Use Tx.ProtoReflect.Descriptor instead. +func (*Tx) Descriptor() ([]byte, []int) { + return file_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto_rawDescGZIP(), []int{0} +} + +func (x *Tx) GetMsg() iface.MsgAny { + if x != nil { + return *x.Msg + } + return nil +} + +var File_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto protoreflect.FileDescriptor + +var file_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto_rawDesc = []byte{ + 0x0a, 0x35, 0x61, 0x6e, 0x79, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x2f, 0x74, + 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, 0x69, 0x66, 0x61, 0x63, 0x65, 0x61, 0x63, 0x63, 0x65, 0x70, + 0x74, 0x65, 0x72, 0x2f, 0x69, 0x66, 0x61, 0x63, 0x65, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, + 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x21, 0x61, 0x6e, 0x79, 0x69, 0x6e, 0x74, 0x65, + 0x72, 0x66, 0x61, 0x63, 0x65, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x69, 0x66, 0x61, + 0x63, 0x65, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x72, 0x1a, 0x0c, 0x63, 0x6f, 0x73, 0x6d, + 0x6f, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x25, 0x61, 0x6e, 0x79, 0x69, 0x6e, 0x74, + 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, 0x69, 0x66, + 0x61, 0x63, 0x65, 0x2f, 0x69, 0x66, 0x61, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, + 0x19, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, + 0x2f, 0x61, 0x6e, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x4f, 0x0a, 0x02, 0x54, 0x78, + 0x12, 0x49, 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, + 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, + 0x41, 0x6e, 0x79, 0x42, 0x21, 0xca, 0xb4, 0x2d, 0x1d, 0x61, 0x6e, 0x79, 0x69, 0x6e, 0x74, 0x65, + 0x72, 0x66, 0x61, 0x63, 0x65, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x69, 0x66, 0x61, + 0x63, 0x65, 0x2e, 0x4d, 0x73, 0x67, 0x52, 0x03, 0x4d, 0x73, 0x67, 0x42, 0x42, 0x5a, 0x40, 0x67, + 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, + 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x61, 0x6e, + 0x79, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, + 0x62, 0x2f, 0x69, 0x66, 0x61, 0x63, 0x65, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x72, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto_rawDescOnce sync.Once + file_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto_rawDescData = file_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto_rawDesc +) + +func file_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto_rawDescGZIP() []byte { + file_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto_rawDescOnce.Do(func() { + file_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto_rawDescData = protoimpl.X.CompressGZIP(file_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto_rawDescData) + }) + return file_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto_rawDescData +} + +var file_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto_goTypes = []interface{}{ + (*Tx)(nil), // 0: anyinterface.testpb.ifaceaccepter.Tx + (*anypb.Any)(nil), // 1: google.protobuf.Any +} +var file_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto_depIdxs = []int32{ + 1, // 0: anyinterface.testpb.ifaceaccepter.Tx.Msg:type_name -> google.protobuf.Any + 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 + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto_init() } +func file_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto_init() { + if File_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Tx); 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_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto_goTypes, + DependencyIndexes: file_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto_depIdxs, + MessageInfos: file_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto_msgTypes, + }.Build() + File_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto = out.File + file_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto_rawDesc = nil + file_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto_goTypes = nil + file_anyinterface_testpb_ifaceaccepter_ifaceaccepter_proto_depIdxs = nil +} diff --git a/features/interfaceservice/generator.go b/features/interfaceservice/generator.go index b456b94..37a27bb 100644 --- a/features/interfaceservice/generator.go +++ b/features/interfaceservice/generator.go @@ -1,11 +1,11 @@ package interfaceservice import ( - "fmt" - cosmos_proto "github.com/cosmos/cosmos-proto" "github.com/cosmos/cosmos-proto/generator" + "github.com/cosmos/cosmos-proto/internal/strs" "google.golang.org/protobuf/compiler/protogen" + "google.golang.org/protobuf/reflect/protoreflect" ) const ( @@ -60,7 +60,7 @@ func (g *gen) genInterface() error { } func (g *gen) genAnyInterface() error { - name := anyInterfaceName(g.svc) + name := AnyInterfaceType(g.svc.Desc) // interface assertion g.P("var _ ", interfaceServiceName(g.svc), " = (*", name, ")(nil)") @@ -97,6 +97,6 @@ func interfaceServiceName(svc *protogen.Service) string { return svc.GoName } -func anyInterfaceName(svc *protogen.Service) string { - return fmt.Sprintf("%sAny", svc.GoName) +func AnyInterfaceType(desc protoreflect.ServiceDescriptor) string { + return strs.GoCamelCase(string(desc.Name()) + "Any") } diff --git a/features/protoc/main.go b/features/protoc/main.go index e67d00e..81df759 100644 --- a/features/protoc/main.go +++ b/features/protoc/main.go @@ -7,19 +7,24 @@ package protoc import ( "fmt" - "github.com/cosmos/cosmos-proto/features/protoc/genid" - "github.com/cosmos/cosmos-proto/generator" "go/ast" "go/parser" "go/token" - "google.golang.org/protobuf/encoding/protowire" - "google.golang.org/protobuf/proto" "math" "strconv" "strings" "unicode" "unicode/utf8" + cosmos_proto "github.com/cosmos/cosmos-proto" + "github.com/cosmos/cosmos-proto/features/interfaceservice" + "github.com/cosmos/cosmos-proto/features/protoc/genid" + "github.com/cosmos/cosmos-proto/generator" + "google.golang.org/protobuf/encoding/protowire" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protodesc" + "google.golang.org/protobuf/types/known/anypb" + pref "google.golang.org/protobuf/reflect/protoreflect" "github.com/cosmos/cosmos-proto/features/protoc/version" @@ -176,7 +181,6 @@ func genFileDescriptor(gen *protogen.Plugin, g *generator.GeneratedFile, f *file } } - func genReflectFileDescriptor(gen *protogen.Plugin, g *generator.GeneratedFile, f *fileInfo) { g.P("var ", f.GoDescriptorIdent, " ", protoreflectPackage.Ident("FileDescriptor")) g.P() @@ -1713,8 +1717,38 @@ func fieldGoType(g *generator.GeneratedFile, f *fileInfo, field *protogen.Field) goType = "[]byte" pointer = false // rely on nullability of slices for presence case protoreflect.MessageKind, protoreflect.GroupKind: - goType = "*" + g.QualifiedGoIdent(field.Message.GoIdent) - pointer = false // pointer captured as part of the type + // we check if the field has accepts_interface options + interfaceName := protoreflect.FullName(proto.GetExtension(field.Desc.Options(), cosmos_proto.E_AcceptsInterface).(string)) + switch interfaceName { + // normal proto case + case "": + goType = "*" + g.QualifiedGoIdent(field.Message.GoIdent) + pointer = false // pointer captured as part of the type + // any as interface + default: + if field.Desc.Message().FullName() != (&anypb.Any{}).ProtoReflect().Descriptor().FullName() { + panic(fmt.Errorf("interface fields must be represented as google.Protobuf.Any: %s, %s", field.Desc.FullName(), field.Desc.Message().FullName())) + } + + // check imports for the interface name + var interfaceSvcDesc protoreflect.ServiceDescriptor + for i := 0; i < f.Desc.Imports().Len(); i++ { + fd := f.Desc.Imports().Get(i) + if interfaceSvcDesc = fd.Services().ByName(interfaceName.Name()); interfaceSvcDesc != nil { + break + } + } + + if interfaceSvcDesc == nil { + panic(fmt.Errorf("interface service descriptor %s was not found or was not imported", interfaceName)) + } + ifacePkg := protogen.GoImportPath(*(protodesc.ToFileDescriptorProto(interfaceSvcDesc.ParentFile()).Options.GoPackage)) + g.Import(ifacePkg) + goType = g.QualifiedGoIdent(protogen.GoIdent{ + GoName: interfaceservice.AnyInterfaceType(interfaceSvcDesc), + GoImportPath: ifacePkg, + }) + } } switch { case field.Desc.IsList(): @@ -2137,7 +2171,6 @@ type goImportPath interface { Ident(string) protogen.GoIdent } - type enumInfo struct { *protogen.Enum @@ -2145,7 +2178,6 @@ type enumInfo struct { genRawDescMethod bool } - func newEnumInfo(f *fileInfo, enum *protogen.Enum) *enumInfo { e := &enumInfo{Enum: enum} e.genJSONMethod = true @@ -2194,7 +2226,6 @@ func newMessageInfo(f *fileInfo, message *protogen.Message) *messageInfo { return m } - type extensionInfo struct { *protogen.Extension } @@ -2291,4 +2322,4 @@ func newFileInfo(file *protogen.File) *fileInfo { } return f -} \ No newline at end of file +} diff --git a/internal/strs/strings.go b/internal/strs/strings.go new file mode 100644 index 0000000..17dee66 --- /dev/null +++ b/internal/strs/strings.go @@ -0,0 +1,183 @@ +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package strs provides string manipulation functionality specific to protobuf. +package strs + +import ( + "go/token" + "strings" + "unicode" + "unicode/utf8" +) + +// GoCamelCase camel-cases a protobuf name for use as a Go identifier. +// +// If there is an interior underscore followed by a lower case letter, +// drop the underscore and convert the letter to upper case. +func GoCamelCase(s string) string { + // Invariant: if the next letter is lower case, it must be converted + // to upper case. + // That is, we process a word at a time, where words are marked by _ or + // upper case letter. Digits are treated as words. + var b []byte + for i := 0; i < len(s); i++ { + c := s[i] + switch { + case c == '.' && i+1 < len(s) && isASCIILower(s[i+1]): + // Skip over '.' in ".{{lowercase}}". + case c == '.': + b = append(b, '_') // convert '.' to '_' + case c == '_' && (i == 0 || s[i-1] == '.'): + // Convert initial '_' to ensure we start with a capital letter. + // Do the same for '_' after '.' to match historic behavior. + b = append(b, 'X') // convert '_' to 'X' + case c == '_' && i+1 < len(s) && isASCIILower(s[i+1]): + // Skip over '_' in "_{{lowercase}}". + case isASCIIDigit(c): + b = append(b, c) + default: + // Assume we have a letter now - if not, it's a bogus identifier. + // The next word is a sequence of characters that must start upper case. + if isASCIILower(c) { + c -= 'a' - 'A' // convert lowercase to uppercase + } + b = append(b, c) + + // Accept lower case sequence that follows. + for ; i+1 < len(s) && isASCIILower(s[i+1]); i++ { + b = append(b, s[i+1]) + } + } + } + return string(b) +} + +// GoSanitized converts a string to a valid Go identifier. +func GoSanitized(s string) string { + // Sanitize the input to the set of valid characters, + // which must be '_' or be in the Unicode L or N categories. + s = strings.Map(func(r rune) rune { + if unicode.IsLetter(r) || unicode.IsDigit(r) { + return r + } + return '_' + }, s) + + // Prepend '_' in the event of a Go keyword conflict or if + // the identifier is invalid (does not start in the Unicode L category). + r, _ := utf8.DecodeRuneInString(s) + if token.Lookup(s).IsKeyword() || !unicode.IsLetter(r) { + return "_" + s + } + return s +} + +// JSONCamelCase converts a snake_case identifier to a camelCase identifier, +// according to the protobuf JSON specification. +func JSONCamelCase(s string) string { + var b []byte + var wasUnderscore bool + for i := 0; i < len(s); i++ { // proto identifiers are always ASCII + c := s[i] + if c != '_' { + if wasUnderscore && isASCIILower(c) { + c -= 'a' - 'A' // convert to uppercase + } + b = append(b, c) + } + wasUnderscore = c == '_' + } + return string(b) +} + +// JSONSnakeCase converts a camelCase identifier to a snake_case identifier, +// according to the protobuf JSON specification. +func JSONSnakeCase(s string) string { + var b []byte + for i := 0; i < len(s); i++ { // proto identifiers are always ASCII + c := s[i] + if isASCIIUpper(c) { + b = append(b, '_') + c += 'a' - 'A' // convert to lowercase + } + b = append(b, c) + } + return string(b) +} + +// MapEntryName derives the name of the map entry message given the field name. +// See protoc v3.8.0: src/google/protobuf/descriptor.cc:254-276,6057 +func MapEntryName(s string) string { + var b []byte + upperNext := true + for _, c := range s { + switch { + case c == '_': + upperNext = true + case upperNext: + b = append(b, byte(unicode.ToUpper(c))) + upperNext = false + default: + b = append(b, byte(c)) + } + } + b = append(b, "Entry"...) + return string(b) +} + +// EnumValueName derives the camel-cased enum value name. +// See protoc v3.8.0: src/google/protobuf/descriptor.cc:297-313 +func EnumValueName(s string) string { + var b []byte + upperNext := true + for _, c := range s { + switch { + case c == '_': + upperNext = true + case upperNext: + b = append(b, byte(unicode.ToUpper(c))) + upperNext = false + default: + b = append(b, byte(unicode.ToLower(c))) + upperNext = false + } + } + return string(b) +} + +// TrimEnumPrefix trims the enum name prefix from an enum value name, +// where the prefix is all lowercase without underscores. +// See protoc v3.8.0: src/google/protobuf/descriptor.cc:330-375 +func TrimEnumPrefix(s, prefix string) string { + s0 := s // original input + for len(s) > 0 && len(prefix) > 0 { + if s[0] == '_' { + s = s[1:] + continue + } + if unicode.ToLower(rune(s[0])) != rune(prefix[0]) { + return s0 // no prefix match + } + s, prefix = s[1:], prefix[1:] + } + if len(prefix) > 0 { + return s0 // no prefix match + } + s = strings.TrimLeft(s, "_") + if len(s) == 0 { + return s0 // avoid returning empty string + } + return s +} + +func isASCIILower(c byte) bool { + return 'a' <= c && c <= 'z' +} +func isASCIIUpper(c byte) bool { + return 'A' <= c && c <= 'Z' +} +func isASCIIDigit(c byte) bool { + return '0' <= c && c <= '9' +} diff --git a/third_party/proto/google/protobuf/any.proto b/third_party/proto/google/protobuf/any.proto new file mode 100644 index 0000000..1c6a465 --- /dev/null +++ b/third_party/proto/google/protobuf/any.proto @@ -0,0 +1,158 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option go_package = "google.golang.org/protobuf/types/known/anypb"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "AnyProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; + +// `Any` contains an arbitrary serialized protocol buffer message along with a +// URL that describes the type of the serialized message. +// +// Protobuf library provides support to pack/unpack Any values in the form +// of utility functions or additional generated methods of the Any type. +// +// Example 1: Pack and unpack a message in C++. +// +// Foo foo = ...; +// Any any; +// any.PackFrom(foo); +// ... +// if (any.UnpackTo(&foo)) { +// ... +// } +// +// Example 2: Pack and unpack a message in Java. +// +// Foo foo = ...; +// Any any = Any.pack(foo); +// ... +// if (any.is(Foo.class)) { +// foo = any.unpack(Foo.class); +// } +// +// Example 3: Pack and unpack a message in Python. +// +// foo = Foo(...) +// any = Any() +// any.Pack(foo) +// ... +// if any.Is(Foo.DESCRIPTOR): +// any.Unpack(foo) +// ... +// +// Example 4: Pack and unpack a message in Go +// +// foo := &pb.Foo{...} +// any, err := anypb.New(foo) +// if err != nil { +// ... +// } +// ... +// foo := &pb.Foo{} +// if err := any.UnmarshalTo(foo); err != nil { +// ... +// } +// +// The pack methods provided by protobuf library will by default use +// 'type.googleapis.com/full.type.name' as the type URL and the unpack +// methods only use the fully qualified type name after the last '/' +// in the type URL, for example "foo.bar.com/x/y.z" will yield type +// name "y.z". +// +// +// JSON +// ==== +// The JSON representation of an `Any` value uses the regular +// representation of the deserialized, embedded message, with an +// additional field `@type` which contains the type URL. Example: +// +// package google.profile; +// message Person { +// string first_name = 1; +// string last_name = 2; +// } +// +// { +// "@type": "type.googleapis.com/google.profile.Person", +// "firstName": , +// "lastName": +// } +// +// If the embedded message type is well-known and has a custom JSON +// representation, that representation will be embedded adding a field +// `value` which holds the custom JSON in addition to the `@type` +// field. Example (for message [google.protobuf.Duration][]): +// +// { +// "@type": "type.googleapis.com/google.protobuf.Duration", +// "value": "1.212s" +// } +// +message Any { + // A URL/resource name that uniquely identifies the type of the serialized + // protocol buffer message. This string must contain at least + // one "/" character. The last segment of the URL's path must represent + // the fully qualified name of the type (as in + // `path/google.protobuf.Duration`). The name should be in a canonical form + // (e.g., leading "." is not accepted). + // + // In practice, teams usually precompile into the binary all types that they + // expect it to use in the context of Any. However, for URLs which use the + // scheme `http`, `https`, or no scheme, one can optionally set up a type + // server that maps type URLs to message definitions as follows: + // + // * If no scheme is provided, `https` is assumed. + // * An HTTP GET on the URL must yield a [google.protobuf.Type][] + // value in binary format, or produce an error. + // * Applications are allowed to cache lookup results based on the + // URL, or have them precompiled into a binary to avoid any + // lookup. Therefore, binary compatibility needs to be preserved + // on changes to types. (Use versioned type names to manage + // breaking changes.) + // + // Note: this functionality is not currently available in the official + // protobuf release, and it is not used for type URLs beginning with + // type.googleapis.com. + // + // Schemes other than `http`, `https` (or the empty scheme) might be + // used with implementation specific semantics. + // + string type_url = 1; + + // Must be a valid serialized protocol buffer of the above specified type. + bytes value = 2; +} \ No newline at end of file