From 2f763c9721baf6d37b4dc7ac9983075f07afa1ba Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Wed, 8 Dec 2021 14:08:14 -0800 Subject: [PATCH] chore!: move to internal --- Makefile | 2 +- cmd/protoc-gen-go-pulsar/main.go | 13 +- codec/drpc/drpc_codec.go | 27 -- codec/grpc/grpc_codec.go | 33 -- features/grpc/grpc.go | 422 ------------------ features/grpc/grpc_plugin.go | 34 -- features/pool/pool.go | 96 ---- .../features}/fastreflection/clear.go | 4 +- .../features}/fastreflection/copied/README.md | 0 .../fastreflection/copied/file_info.go | 0 .../features}/fastreflection/copied/naming.go | 0 .../features}/fastreflection/descriptors.go | 10 +- .../features}/fastreflection/fast_plugin.go | 10 +- .../features}/fastreflection/get.go | 4 +- .../features}/fastreflection/has.go | 4 +- .../features}/fastreflection/list.go | 10 +- .../features}/fastreflection/map.go | 4 +- .../features}/fastreflection/mutable.go | 4 +- .../features}/fastreflection/new_field.go | 4 +- .../features}/fastreflection/proto_marshal.go | 8 +- .../features}/fastreflection/proto_message.go | 12 +- .../features}/fastreflection/proto_size.go | 12 +- .../fastreflection/proto_unmarshal.go | 34 +- .../features}/fastreflection/range.go | 4 +- .../features}/fastreflection/set.go | 4 +- .../features}/fastreflection/type.go | 4 +- .../features}/fastreflection/which_oneof.go | 4 +- .../features}/protoc/feature.go | 10 +- .../features}/protoc/genid/any_gen.go | 0 .../features}/protoc/genid/api_gen.go | 0 .../features}/protoc/genid/descriptor_gen.go | 0 .../features}/protoc/genid/doc.go | 0 .../features}/protoc/genid/duration_gen.go | 0 .../features}/protoc/genid/empty_gen.go | 0 .../features}/protoc/genid/field_mask_gen.go | 0 .../features}/protoc/genid/goname.go | 0 .../features}/protoc/genid/map_entry.go | 0 .../protoc/genid/source_context_gen.go | 0 .../features}/protoc/genid/struct_gen.go | 0 .../features}/protoc/genid/timestamp_gen.go | 0 .../features}/protoc/genid/type_gen.go | 0 .../features}/protoc/genid/wrappers.go | 0 .../features}/protoc/genid/wrappers_gen.go | 0 .../features}/protoc/main.go | 122 ++--- .../features}/protoc/version/version.go | 0 {generator => internal/generator}/features.go | 0 .../generator}/generatedfile.go | 24 - .../generator}/generator.go | 0 {generator => internal/generator}/helpers.go | 0 {testpb => internal/testpb}/1.proto | 5 +- {testpb => internal/testpb}/1.pulsar.go | 314 +++++-------- {testpb => internal/testpb}/clear_test.go | 0 {testpb => internal/testpb}/codec_test.go | 0 {testpb => internal/testpb}/get_test.go | 0 {testpb => internal/testpb}/has_test.go | 0 .../testpb}/list_bench_test.go | 0 {testpb => internal/testpb}/list_test.go | 0 {testpb => internal/testpb}/map_bench_test.go | 0 {testpb => internal/testpb}/map_test.go | 0 {testpb => internal/testpb}/mutable_test.go | 0 {testpb => internal/testpb}/new_field_test.go | 0 .../testpb}/proto_message_bench_test.go | 0 .../testpb}/proto_methods_test.go | 0 {testpb => internal/testpb}/range_test.go | 0 {testpb => internal/testpb}/set_test.go | 0 .../testpb}/type_bench_test.go | 0 {testpb => internal/testpb}/type_test.go | 0 .../testpb}/whichoneof_test.go | 0 internal/testprotos/test3/test.pulsar.go | 2 +- .../testprotos/test3/test_import.pulsar.go | 2 +- pulsarproto/ext.pb.go | 95 ---- scripts/fastreflect.sh | 2 +- 72 files changed, 242 insertions(+), 1097 deletions(-) delete mode 100644 codec/drpc/drpc_codec.go delete mode 100644 codec/grpc/grpc_codec.go delete mode 100644 features/grpc/grpc.go delete mode 100644 features/grpc/grpc_plugin.go delete mode 100644 features/pool/pool.go rename {features => internal/features}/fastreflection/clear.go (95%) rename {features => internal/features}/fastreflection/copied/README.md (100%) rename {features => internal/features}/fastreflection/copied/file_info.go (100%) rename {features => internal/features}/fastreflection/copied/naming.go (100%) rename {features => internal/features}/fastreflection/descriptors.go (84%) rename {features => internal/features}/fastreflection/fast_plugin.go (71%) rename {features => internal/features}/fastreflection/get.go (98%) rename {features => internal/features}/fastreflection/has.go (97%) rename {features => internal/features}/fastreflection/list.go (96%) rename {features => internal/features}/fastreflection/map.go (98%) rename {features => internal/features}/fastreflection/mutable.go (98%) rename {features => internal/features}/fastreflection/new_field.go (96%) rename {features => internal/features}/fastreflection/proto_marshal.go (98%) rename {features => internal/features}/fastreflection/proto_message.go (95%) rename {features => internal/features}/fastreflection/proto_size.go (96%) rename {features => internal/features}/fastreflection/proto_unmarshal.go (95%) rename {features => internal/features}/fastreflection/range.go (98%) rename {features => internal/features}/fastreflection/set.go (98%) rename {features => internal/features}/fastreflection/type.go (93%) rename {features => internal/features}/fastreflection/which_oneof.go (94%) rename {features => internal/features}/protoc/feature.go (57%) rename {features => internal/features}/protoc/genid/any_gen.go (100%) rename {features => internal/features}/protoc/genid/api_gen.go (100%) rename {features => internal/features}/protoc/genid/descriptor_gen.go (100%) rename {features => internal/features}/protoc/genid/doc.go (100%) rename {features => internal/features}/protoc/genid/duration_gen.go (100%) rename {features => internal/features}/protoc/genid/empty_gen.go (100%) rename {features => internal/features}/protoc/genid/field_mask_gen.go (100%) rename {features => internal/features}/protoc/genid/goname.go (100%) rename {features => internal/features}/protoc/genid/map_entry.go (100%) rename {features => internal/features}/protoc/genid/source_context_gen.go (100%) rename {features => internal/features}/protoc/genid/struct_gen.go (100%) rename {features => internal/features}/protoc/genid/timestamp_gen.go (100%) rename {features => internal/features}/protoc/genid/type_gen.go (100%) rename {features => internal/features}/protoc/genid/wrappers.go (100%) rename {features => internal/features}/protoc/genid/wrappers_gen.go (100%) rename {features => internal/features}/protoc/main.go (95%) rename {features => internal/features}/protoc/version/version.go (100%) rename {generator => internal/generator}/features.go (100%) rename {generator => internal/generator}/generatedfile.go (77%) rename {generator => internal/generator}/generator.go (100%) rename {generator => internal/generator}/helpers.go (100%) rename {testpb => internal/testpb}/1.proto (80%) rename {testpb => internal/testpb}/1.pulsar.go (88%) rename {testpb => internal/testpb}/clear_test.go (100%) rename {testpb => internal/testpb}/codec_test.go (100%) rename {testpb => internal/testpb}/get_test.go (100%) rename {testpb => internal/testpb}/has_test.go (100%) rename {testpb => internal/testpb}/list_bench_test.go (100%) rename {testpb => internal/testpb}/list_test.go (100%) rename {testpb => internal/testpb}/map_bench_test.go (100%) rename {testpb => internal/testpb}/map_test.go (100%) rename {testpb => internal/testpb}/mutable_test.go (100%) rename {testpb => internal/testpb}/new_field_test.go (100%) rename {testpb => internal/testpb}/proto_message_bench_test.go (100%) rename {testpb => internal/testpb}/proto_methods_test.go (100%) rename {testpb => internal/testpb}/range_test.go (100%) rename {testpb => internal/testpb}/set_test.go (100%) rename {testpb => internal/testpb}/type_bench_test.go (100%) rename {testpb => internal/testpb}/type_test.go (100%) rename {testpb => internal/testpb}/whichoneof_test.go (100%) delete mode 100644 pulsarproto/ext.pb.go diff --git a/Makefile b/Makefile index 412c356..335a5a4 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -DIRECTORIES_TO_BUILD := "./testpb ./internal/testprotos/test3" +DIRECTORIES_TO_BUILD := "./internal/testpb ./internal/testprotos/test3" pulsar: docker build -t dev:proto-build -f Dockerfile . diff --git a/cmd/protoc-gen-go-pulsar/main.go b/cmd/protoc-gen-go-pulsar/main.go index a57634c..fbb1b62 100644 --- a/cmd/protoc-gen-go-pulsar/main.go +++ b/cmd/protoc-gen-go-pulsar/main.go @@ -3,14 +3,11 @@ package main import ( "flag" "fmt" + generator2 "github.com/cosmos/cosmos-proto/internal/generator" "strings" - _ "github.com/cosmos/cosmos-proto/features/fastreflection" - _ "github.com/cosmos/cosmos-proto/features/grpc" - _ "github.com/cosmos/cosmos-proto/features/pool" - _ "github.com/cosmos/cosmos-proto/features/protoc" - "github.com/cosmos/cosmos-proto/generator" - + _ "github.com/cosmos/cosmos-proto/internal/features/fastreflection" + _ "github.com/cosmos/cosmos-proto/internal/features/protoc" "google.golang.org/protobuf/compiler/protogen" "google.golang.org/protobuf/types/pluginpb" ) @@ -51,8 +48,8 @@ func main() { var SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL) func generateAllFiles(plugin *protogen.Plugin, featureNames []string, poolable ObjectSet) error { - ext := &generator.Extensions{Poolable: poolable} - gen, err := generator.NewGenerator(plugin.Files, featureNames, ext) + ext := &generator2.Extensions{Poolable: poolable} + gen, err := generator2.NewGenerator(plugin.Files, featureNames, ext) if err != nil { return err } diff --git a/codec/drpc/drpc_codec.go b/codec/drpc/drpc_codec.go deleted file mode 100644 index d525250..0000000 --- a/codec/drpc/drpc_codec.go +++ /dev/null @@ -1,27 +0,0 @@ -package drpc - -import ( - "google.golang.org/protobuf/encoding/protojson" - "google.golang.org/protobuf/proto" -) - -type vtprotoMessage interface { - Marshal() ([]byte, error) - Unmarshal([]byte) error -} - -func Marshal(msg interface{}) ([]byte, error) { - return msg.(vtprotoMessage).Marshal() -} - -func Unmarshal(buf []byte, msg interface{}) error { - return msg.(vtprotoMessage).Unmarshal(buf) -} - -func JSONMarshal(msg interface{}) ([]byte, error) { - return protojson.Marshal(msg.(proto.Message)) -} - -func JSONUnmarshal(buf []byte, msg interface{}) error { - return protojson.Unmarshal(buf, msg.(proto.Message)) -} diff --git a/codec/grpc/grpc_codec.go b/codec/grpc/grpc_codec.go deleted file mode 100644 index 2203e55..0000000 --- a/codec/grpc/grpc_codec.go +++ /dev/null @@ -1,33 +0,0 @@ -package grpc - -import "fmt" - -// Name is the name registered for the proto compressor. -const Name = "proto" - -type Codec struct{} - -type vtprotoMessage interface { - Marshal() ([]byte, error) - Unmarshal([]byte) error -} - -func (Codec) Marshal(v interface{}) ([]byte, error) { - vt, ok := v.(vtprotoMessage) - if !ok { - return nil, fmt.Errorf("failed to marshal, message is %T (missing vtprotobuf helpers)", v) - } - return vt.Marshal() -} - -func (Codec) Unmarshal(data []byte, v interface{}) error { - vt, ok := v.(vtprotoMessage) - if !ok { - return fmt.Errorf("failed to unmarshal, message is %T (missing vtprotobuf helpers)", v) - } - return vt.Unmarshal(data) -} - -func (Codec) Name() string { - return Name -} diff --git a/features/grpc/grpc.go b/features/grpc/grpc.go deleted file mode 100644 index d7143cf..0000000 --- a/features/grpc/grpc.go +++ /dev/null @@ -1,422 +0,0 @@ -/* - * - * Copyright 2020 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package grpc - -import ( - "fmt" - "strconv" - "strings" - - "github.com/cosmos/cosmos-proto/generator" - - "google.golang.org/protobuf/compiler/protogen" - "google.golang.org/protobuf/types/descriptorpb" -) - -const ( - contextPackage = protogen.GoImportPath("context") - grpcPackage = protogen.GoImportPath("google.golang.org/grpc") - codesPackage = protogen.GoImportPath("google.golang.org/grpc/codes") - statusPackage = protogen.GoImportPath("google.golang.org/grpc/status") -) - -// generateFileContent generates the gRPC service definitions, excluding the package statement. -func generateFileContent(gen *protogen.Plugin, file *protogen.File, g *generator.GeneratedFile) { - if len(file.Services) == 0 { - return - } - - g.P("// This is a compile-time assertion to ensure that this generated file") - g.P("// is compatible with the grpc package it is being compiled against.") - g.P("// Requires gRPC-Go v1.32.0 or later.") - g.P("const _ = ", grpcPackage.Ident("SupportPackageIsVersion7")) // When changing, update version number above. - g.P() - for _, service := range file.Services { - genService(gen, file, g, service) - } -} - -func genService(gen *protogen.Plugin, file *protogen.File, g *generator.GeneratedFile, service *protogen.Service) { - clientName := service.GoName + "Client" - - g.P("// ", clientName, " is the client API for ", service.GoName, " service.") - g.P("//") - g.P("// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.") - - // Client interface. - if service.Desc.Options().(*descriptorpb.ServiceOptions).GetDeprecated() { - g.P("//") - g.P(deprecationComment) - } - g.Annotate(clientName, service.Location) - g.P("type ", clientName, " interface {") - for _, method := range service.Methods { - g.Annotate(clientName+"."+method.GoName, method.Location) - if method.Desc.Options().(*descriptorpb.MethodOptions).GetDeprecated() { - g.P(deprecationComment) - } - g.P(method.Comments.Leading, - clientSignature(g, method)) - } - g.P("}") - g.P() - - // Client structure. - g.P("type ", unexport(clientName), " struct {") - g.P("cc ", grpcPackage.Ident("ClientConnInterface")) - g.P("}") - g.P() - - // NewClient factory. - if service.Desc.Options().(*descriptorpb.ServiceOptions).GetDeprecated() { - g.P(deprecationComment) - } - g.P("func New", clientName, " (cc ", grpcPackage.Ident("ClientConnInterface"), ") ", clientName, " {") - g.P("return &", unexport(clientName), "{cc}") - g.P("}") - g.P() - - var methodIndex, streamIndex int - // Client method implementations. - for _, method := range service.Methods { - if !method.Desc.IsStreamingServer() && !method.Desc.IsStreamingClient() { - // Unary RPC method - genClientMethod(gen, file, g, method, methodIndex) - methodIndex++ - } else { - // Streaming RPC method - genClientMethod(gen, file, g, method, streamIndex) - streamIndex++ - } - } - - mustOrShould := "must" - if !*requireUnimplemented { - mustOrShould = "should" - } - - // Server interface. - serverType := service.GoName + "Server" - g.P("// ", serverType, " is the server API for ", service.GoName, " service.") - g.P("// All implementations ", mustOrShould, " embed Unimplemented", serverType) - g.P("// for forward compatibility") - if service.Desc.Options().(*descriptorpb.ServiceOptions).GetDeprecated() { - g.P("//") - g.P(deprecationComment) - } - g.Annotate(serverType, service.Location) - g.P("type ", serverType, " interface {") - for _, method := range service.Methods { - g.Annotate(serverType+"."+method.GoName, method.Location) - if method.Desc.Options().(*descriptorpb.MethodOptions).GetDeprecated() { - g.P(deprecationComment) - } - g.P(method.Comments.Leading, - serverSignature(g, method)) - } - if *requireUnimplemented { - g.P("mustEmbedUnimplemented", serverType, "()") - } - g.P("}") - g.P() - - // Server Unimplemented struct for forward compatibility. - g.P("// Unimplemented", serverType, " ", mustOrShould, " be embedded to have forward compatible implementations.") - g.P("type Unimplemented", serverType, " struct {") - g.P("}") - g.P() - for _, method := range service.Methods { - nilArg := "" - if !method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() { - nilArg = "nil," - } - g.P("func (Unimplemented", serverType, ") ", serverSignature(g, method), "{") - g.P("return ", nilArg, statusPackage.Ident("Errorf"), "(", codesPackage.Ident("Unimplemented"), `, "method `, method.GoName, ` not implemented")`) - g.P("}") - } - if *requireUnimplemented { - g.P("func (Unimplemented", serverType, ") mustEmbedUnimplemented", serverType, "() {}") - } - g.P() - - // Unsafe Server interface to opt-out of forward compatibility. - g.P("// Unsafe", serverType, " may be embedded to opt out of forward compatibility for this service.") - g.P("// Use of this interface is not recommended, as added methods to ", serverType, " will") - g.P("// result in compilation errors.") - g.P("type Unsafe", serverType, " interface {") - g.P("mustEmbedUnimplemented", serverType, "()") - g.P("}") - - // Server registration. - if service.Desc.Options().(*descriptorpb.ServiceOptions).GetDeprecated() { - g.P(deprecationComment) - } - serviceDescVar := service.GoName + "_ServiceDesc" - g.P("func Register", service.GoName, "Server(s ", grpcPackage.Ident("ServiceRegistrar"), ", srv ", serverType, ") {") - g.P("s.RegisterService(&", serviceDescVar, `, srv)`) - g.P("}") - g.P() - - // Server handler implementations. - var handlerNames []string - for _, method := range service.Methods { - hname := genServerMethod(gen, file, g, method) - handlerNames = append(handlerNames, hname) - } - - // Service descriptor. - g.P("// ", serviceDescVar, " is the ", grpcPackage.Ident("ServiceDesc"), " for ", service.GoName, " service.") - g.P("// It's only intended for direct use with ", grpcPackage.Ident("RegisterService"), ",") - g.P("// and not to be introspected or modified (even as a copy)") - g.P("var ", serviceDescVar, " = ", grpcPackage.Ident("ServiceDesc"), " {") - g.P("ServiceName: ", strconv.Quote(string(service.Desc.FullName())), ",") - g.P("HandlerType: (*", serverType, ")(nil),") - g.P("Methods: []", grpcPackage.Ident("MethodDesc"), "{") - for i, method := range service.Methods { - if method.Desc.IsStreamingClient() || method.Desc.IsStreamingServer() { - continue - } - g.P("{") - g.P("MethodName: ", strconv.Quote(string(method.Desc.Name())), ",") - g.P("Handler: ", handlerNames[i], ",") - g.P("},") - } - g.P("},") - g.P("Streams: []", grpcPackage.Ident("StreamDesc"), "{") - for i, method := range service.Methods { - if !method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() { - continue - } - g.P("{") - g.P("StreamName: ", strconv.Quote(string(method.Desc.Name())), ",") - g.P("Handler: ", handlerNames[i], ",") - if method.Desc.IsStreamingServer() { - g.P("ServerStreams: true,") - } - if method.Desc.IsStreamingClient() { - g.P("ClientStreams: true,") - } - g.P("},") - } - g.P("},") - g.P("Metadata: \"", file.Desc.Path(), "\",") - g.P("}") - g.P() -} - -func clientSignature(g *generator.GeneratedFile, method *protogen.Method) string { - s := method.GoName + "(ctx " + g.QualifiedGoIdent(contextPackage.Ident("Context")) - if !method.Desc.IsStreamingClient() { - s += ", in *" + g.QualifiedGoIdent(method.Input.GoIdent) - } - s += ", opts ..." + g.QualifiedGoIdent(grpcPackage.Ident("CallOption")) + ") (" - if !method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() { - s += "*" + g.QualifiedGoIdent(method.Output.GoIdent) - } else { - s += method.Parent.GoName + "_" + method.GoName + "Client" - } - s += ", error)" - return s -} - -func genClientMethod(gen *protogen.Plugin, file *protogen.File, g *generator.GeneratedFile, method *protogen.Method, index int) { - service := method.Parent - sname := fmt.Sprintf("/%s/%s", service.Desc.FullName(), method.Desc.Name()) - - if method.Desc.Options().(*descriptorpb.MethodOptions).GetDeprecated() { - g.P(deprecationComment) - } - g.P("func (c *", unexport(service.GoName), "Client) ", clientSignature(g, method), "{") - if !method.Desc.IsStreamingServer() && !method.Desc.IsStreamingClient() { - // g.P("out := new(", method.Output.GoIdent, ")") - g.Alloc("out", method.Output) - g.P(`err := c.cc.Invoke(ctx, "`, sname, `", in, out, opts...)`) - g.P("if err != nil { return nil, err }") - g.P("return out, nil") - g.P("}") - g.P() - return - } - streamType := unexport(service.GoName) + method.GoName + "Client" - serviceDescVar := service.GoName + "_ServiceDesc" - g.P("stream, err := c.cc.NewStream(ctx, &", serviceDescVar, ".Streams[", index, `], "`, sname, `", opts...)`) - g.P("if err != nil { return nil, err }") - g.P("x := &", streamType, "{stream}") - if !method.Desc.IsStreamingClient() { - g.P("if err := x.ClientStream.SendMsg(in); err != nil { return nil, err }") - g.P("if err := x.ClientStream.CloseSend(); err != nil { return nil, err }") - } - g.P("return x, nil") - g.P("}") - g.P() - - genSend := method.Desc.IsStreamingClient() - genRecv := method.Desc.IsStreamingServer() - genCloseAndRecv := !method.Desc.IsStreamingServer() - - // Stream auxiliary types and methods. - g.P("type ", service.GoName, "_", method.GoName, "Client interface {") - if genSend { - g.P("Send(*", method.Input.GoIdent, ") error") - } - if genRecv { - g.P("Recv() (*", method.Output.GoIdent, ", error)") - } - if genCloseAndRecv { - g.P("CloseAndRecv() (*", method.Output.GoIdent, ", error)") - } - g.P(grpcPackage.Ident("ClientStream")) - g.P("}") - g.P() - - g.P("type ", streamType, " struct {") - g.P(grpcPackage.Ident("ClientStream")) - g.P("}") - g.P() - - if genSend { - g.P("func (x *", streamType, ") Send(m *", method.Input.GoIdent, ") error {") - g.P("return x.ClientStream.SendMsg(m)") - g.P("}") - g.P() - } - if genRecv { - g.P("func (x *", streamType, ") Recv() (*", method.Output.GoIdent, ", error) {") - // g.P("m := new(", method.Output.GoIdent, ")") - g.Alloc("m", method.Output) - g.P("if err := x.ClientStream.RecvMsg(m); err != nil { return nil, err }") - g.P("return m, nil") - g.P("}") - g.P() - } - if genCloseAndRecv { - g.P("func (x *", streamType, ") CloseAndRecv() (*", method.Output.GoIdent, ", error) {") - g.P("if err := x.ClientStream.CloseSend(); err != nil { return nil, err }") - // g.P("m := new(", method.Output.GoIdent, ")") - g.Alloc("m", method.Output) - g.P("if err := x.ClientStream.RecvMsg(m); err != nil { return nil, err }") - g.P("return m, nil") - g.P("}") - g.P() - } -} - -func serverSignature(g *generator.GeneratedFile, method *protogen.Method) string { - var reqArgs []string - ret := "error" - if !method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() { - reqArgs = append(reqArgs, g.QualifiedGoIdent(contextPackage.Ident("Context"))) - ret = "(*" + g.QualifiedGoIdent(method.Output.GoIdent) + ", error)" - } - if !method.Desc.IsStreamingClient() { - reqArgs = append(reqArgs, "*"+g.QualifiedGoIdent(method.Input.GoIdent)) - } - if method.Desc.IsStreamingClient() || method.Desc.IsStreamingServer() { - reqArgs = append(reqArgs, method.Parent.GoName+"_"+method.GoName+"Server") - } - return method.GoName + "(" + strings.Join(reqArgs, ", ") + ") " + ret -} - -func genServerMethod(gen *protogen.Plugin, file *protogen.File, g *generator.GeneratedFile, method *protogen.Method) string { - service := method.Parent - hname := fmt.Sprintf("_%s_%s_Handler", service.GoName, method.GoName) - - if !method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() { - g.P("func ", hname, "(srv interface{}, ctx ", contextPackage.Ident("Context"), ", dec func(interface{}) error, interceptor ", grpcPackage.Ident("UnaryServerInterceptor"), ") (interface{}, error) {") - // g.P("in := new(", method.Input.GoIdent, ")") - g.Alloc("in", method.Input) - g.P("if err := dec(in); err != nil { return nil, err }") - g.P("if interceptor == nil { return srv.(", service.GoName, "Server).", method.GoName, "(ctx, in) }") - g.P("info := &", grpcPackage.Ident("UnaryServerInfo"), "{") - g.P("Server: srv,") - g.P("FullMethod: ", strconv.Quote(fmt.Sprintf("/%s/%s", service.Desc.FullName(), method.Desc.Name())), ",") - g.P("}") - g.P("handler := func(ctx ", contextPackage.Ident("Context"), ", req interface{}) (interface{}, error) {") - g.P("return srv.(", service.GoName, "Server).", method.GoName, "(ctx, req.(*", method.Input.GoIdent, "))") - g.P("}") - g.P("return interceptor(ctx, in, info, handler)") - g.P("}") - g.P() - return hname - } - streamType := unexport(service.GoName) + method.GoName + "Server" - g.P("func ", hname, "(srv interface{}, stream ", grpcPackage.Ident("ServerStream"), ") error {") - if !method.Desc.IsStreamingClient() { - // g.P("m := new(", method.Input.GoIdent, ")") - g.Alloc("m", method.Input) - g.P("if err := stream.RecvMsg(m); err != nil { return err }") - g.P("return srv.(", service.GoName, "Server).", method.GoName, "(m, &", streamType, "{stream})") - } else { - g.P("return srv.(", service.GoName, "Server).", method.GoName, "(&", streamType, "{stream})") - } - g.P("}") - g.P() - - genSend := method.Desc.IsStreamingServer() - genSendAndClose := !method.Desc.IsStreamingServer() - genRecv := method.Desc.IsStreamingClient() - - // Stream auxiliary types and methods. - g.P("type ", service.GoName, "_", method.GoName, "Server interface {") - if genSend { - g.P("Send(*", method.Output.GoIdent, ") error") - } - if genSendAndClose { - g.P("SendAndClose(*", method.Output.GoIdent, ") error") - } - if genRecv { - g.P("Recv() (*", method.Input.GoIdent, ", error)") - } - g.P(grpcPackage.Ident("ServerStream")) - g.P("}") - g.P() - - g.P("type ", streamType, " struct {") - g.P(grpcPackage.Ident("ServerStream")) - g.P("}") - g.P() - - if genSend { - g.P("func (x *", streamType, ") Send(m *", method.Output.GoIdent, ") error {") - g.P("return x.ServerStream.SendMsg(m)") - g.P("}") - g.P() - } - if genSendAndClose { - g.P("func (x *", streamType, ") SendAndClose(m *", method.Output.GoIdent, ") error {") - g.P("return x.ServerStream.SendMsg(m)") - g.P("}") - g.P() - } - if genRecv { - g.P("func (x *", streamType, ") Recv() (*", method.Input.GoIdent, ", error) {") - // g.P("m := new(", method.Input.GoIdent, ")") - g.Alloc("m", method.Input) - g.P("if err := x.ServerStream.RecvMsg(m); err != nil { return nil, err }") - g.P("return m, nil") - g.P("}") - g.P() - } - - return hname -} - -const deprecationComment = "// Deprecated: Do not use." - -func unexport(s string) string { return strings.ToLower(s[:1]) + s[1:] } diff --git a/features/grpc/grpc_plugin.go b/features/grpc/grpc_plugin.go deleted file mode 100644 index e6f2773..0000000 --- a/features/grpc/grpc_plugin.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2021 PlanetScale Inc. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package grpc - -import ( - "github.com/cosmos/cosmos-proto/generator" - "google.golang.org/protobuf/compiler/protogen" -) - -var requireUnimplementedAlways = true -var requireUnimplemented = &requireUnimplementedAlways - -func init() { - generator.RegisterFeature("grpc", func(gen *generator.GeneratedFile, _ *protogen.Plugin) generator.FeatureGenerator { - return &grpc{gen} - }) -} - -type grpc struct { - *generator.GeneratedFile -} - -func (g *grpc) GenerateFile(file *protogen.File, _ *protogen.Plugin) bool { - if len(file.Services) == 0 { - return false - } - - generateFileContent(nil, file, g.GeneratedFile) - return true -} - -func (g *grpc) GenerateHelpers() {} diff --git a/features/pool/pool.go b/features/pool/pool.go deleted file mode 100644 index 1eddec0..0000000 --- a/features/pool/pool.go +++ /dev/null @@ -1,96 +0,0 @@ -package pool - -import ( - "fmt" - - "github.com/cosmos/cosmos-proto/generator" - "google.golang.org/protobuf/compiler/protogen" - "google.golang.org/protobuf/reflect/protoreflect" -) - -func init() { - generator.RegisterFeature("pool", func(gen *generator.GeneratedFile, plugin *protogen.Plugin) generator.FeatureGenerator { - return &pool{GeneratedFile: gen} - }) -} - -type pool struct { - *generator.GeneratedFile - once bool -} - -var _ generator.FeatureGenerator = (*pool)(nil) - -func (p *pool) GenerateHelpers() {} - -func (p *pool) GenerateFile(file *protogen.File, plugin *protogen.Plugin) bool { - for _, message := range file.Messages { - p.message(message) - } - return p.once -} - -func (p *pool) message(message *protogen.Message) { - for _, nested := range message.Messages { - p.message(nested) - } - - if message.Desc.IsMapEntry() || !p.ShouldPool(message) { - return - } - - p.once = true - ccTypeName := message.GoIdent - - p.P(`var vtprotoPool_`, ccTypeName, ` = `, p.Ident("sync", "Pool"), `{`) - p.P(`New: func() interface{} {`) - p.P(`return &`, message.GoIdent, `{}`) - p.P(`},`) - p.P(`}`) - - p.P(`func (x *`, ccTypeName, `) ResetVT() {`) - var saved []*protogen.Field - for _, field := range message.Fields { - fieldName := field.GoName - - if field.Desc.IsList() { - switch field.Desc.Kind() { - case protoreflect.MessageKind, protoreflect.GroupKind: - if p.ShouldPool(field.Message) { - p.P(`for _, mm := range x.`, fieldName, `{`) - p.P(`mm.ResetVT()`) - p.P(`}`) - } - } - p.P(fmt.Sprintf("f%d", len(saved)), ` := x.`, fieldName, `[:0]`) - saved = append(saved, field) - } else { - switch field.Desc.Kind() { - case protoreflect.MessageKind, protoreflect.GroupKind: - if p.ShouldPool(field.Message) { - p.P(`x.`, fieldName, `.ReturnToVTPool()`) - } - case protoreflect.BytesKind: - p.P(fmt.Sprintf("f%d", len(saved)), ` := x.`, fieldName, `[:0]`) - saved = append(saved, field) - } - } - } - - p.P(`x.Reset()`) - for i, field := range saved { - p.P(`x.`, field.GoName, ` = `, fmt.Sprintf("f%d", i)) - } - p.P(`}`) - - p.P(`func (x *`, ccTypeName, `) ReturnToVTPool() {`) - p.P(`if x != nil {`) - p.P(`x.ResetVT()`) - p.P(`vtprotoPool_`, ccTypeName, `.Put(m)`) - p.P(`}`) - p.P(`}`) - - p.P(`func `, ccTypeName, `FromVTPool() *`, ccTypeName, `{`) - p.P(`return vtprotoPool_`, ccTypeName, `.Get().(*`, ccTypeName, `)`) - p.P(`}`) -} diff --git a/features/fastreflection/clear.go b/internal/features/fastreflection/clear.go similarity index 95% rename from features/fastreflection/clear.go rename to internal/features/fastreflection/clear.go index a47cea5..b2d535d 100644 --- a/features/fastreflection/clear.go +++ b/internal/features/fastreflection/clear.go @@ -1,7 +1,7 @@ package fastreflection import ( - "github.com/cosmos/cosmos-proto/generator" + generator2 "github.com/cosmos/cosmos-proto/internal/generator" "google.golang.org/protobuf/compiler/protogen" "google.golang.org/protobuf/reflect/protoreflect" ) @@ -14,7 +14,7 @@ import ( // if oneof: oneof != nil (if oneof is scalar do we need to check it??) // if bytes: len(bytes) != 0 type clearGen struct { - *generator.GeneratedFile + *generator2.GeneratedFile typeName string message *protogen.Message } diff --git a/features/fastreflection/copied/README.md b/internal/features/fastreflection/copied/README.md similarity index 100% rename from features/fastreflection/copied/README.md rename to internal/features/fastreflection/copied/README.md diff --git a/features/fastreflection/copied/file_info.go b/internal/features/fastreflection/copied/file_info.go similarity index 100% rename from features/fastreflection/copied/file_info.go rename to internal/features/fastreflection/copied/file_info.go diff --git a/features/fastreflection/copied/naming.go b/internal/features/fastreflection/copied/naming.go similarity index 100% rename from features/fastreflection/copied/naming.go rename to internal/features/fastreflection/copied/naming.go diff --git a/features/fastreflection/descriptors.go b/internal/features/fastreflection/descriptors.go similarity index 84% rename from features/fastreflection/descriptors.go rename to internal/features/fastreflection/descriptors.go index d8bb373..e9aeaa0 100644 --- a/features/fastreflection/descriptors.go +++ b/internal/features/fastreflection/descriptors.go @@ -2,15 +2,15 @@ package fastreflection import ( "fmt" - "github.com/cosmos/cosmos-proto/generator" + copied2 "github.com/cosmos/cosmos-proto/internal/features/fastreflection/copied" + generator2 "github.com/cosmos/cosmos-proto/internal/generator" "google.golang.org/protobuf/reflect/protoreflect" - "github.com/cosmos/cosmos-proto/features/fastreflection/copied" "google.golang.org/protobuf/compiler/protogen" ) type descGen struct { - *generator.GeneratedFile + *generator2.GeneratedFile file *protogen.File message *protogen.Message } @@ -24,10 +24,10 @@ func (g *descGen) generate() { } g.P(")") g.P("func init() {") - g.P(copied.InitFunctionName(g.file), "()") + g.P(copied2.InitFunctionName(g.file), "()") parentMd, ok := g.message.Desc.Parent().(protoreflect.MessageDescriptor) switch ok { - // case nested message + // case nested message case true: g.P(messageDescriptorName(g.message), " = ", g.file.GoDescriptorIdent.GoName, ".Messages().ByName(\"", parentMd.Name(), "\").Messages().ByName(\"", g.message.Desc.Name(), "\")") default: diff --git a/features/fastreflection/fast_plugin.go b/internal/features/fastreflection/fast_plugin.go similarity index 71% rename from features/fastreflection/fast_plugin.go rename to internal/features/fastreflection/fast_plugin.go index db50a0a..dba120f 100644 --- a/features/fastreflection/fast_plugin.go +++ b/internal/features/fastreflection/fast_plugin.go @@ -1,12 +1,12 @@ package fastreflection import ( - "github.com/cosmos/cosmos-proto/generator" + generator2 "github.com/cosmos/cosmos-proto/internal/generator" "google.golang.org/protobuf/compiler/protogen" ) func init() { - generator.RegisterFeature("fast", func(gen *generator.GeneratedFile, _ *protogen.Plugin) generator.FeatureGenerator { + generator2.RegisterFeature("fast", func(gen *generator2.GeneratedFile, _ *protogen.Plugin) generator2.FeatureGenerator { return fastReflectionFeature{ GeneratedFile: gen, Stable: false, @@ -16,12 +16,12 @@ func init() { } type fastReflectionFeature struct { - *generator.GeneratedFile + *generator2.GeneratedFile Stable, once bool } type fastGenerator struct { - *generator.GeneratedFile + *generator2.GeneratedFile file *protogen.File message *protogen.Message @@ -30,7 +30,7 @@ type fastGenerator struct { err error } -func newGenerator(f *protogen.File, g *generator.GeneratedFile, message *protogen.Message) *fastGenerator { +func newGenerator(f *protogen.File, g *generator2.GeneratedFile, message *protogen.Message) *fastGenerator { return &fastGenerator{ GeneratedFile: g, file: f, diff --git a/features/fastreflection/get.go b/internal/features/fastreflection/get.go similarity index 98% rename from features/fastreflection/get.go rename to internal/features/fastreflection/get.go index ce34047..0995402 100644 --- a/features/fastreflection/get.go +++ b/internal/features/fastreflection/get.go @@ -1,13 +1,13 @@ package fastreflection import ( - "github.com/cosmos/cosmos-proto/generator" + generator2 "github.com/cosmos/cosmos-proto/internal/generator" "google.golang.org/protobuf/compiler/protogen" "google.golang.org/protobuf/reflect/protoreflect" ) type getGen struct { - *generator.GeneratedFile + *generator2.GeneratedFile typeName string message *protogen.Message } diff --git a/features/fastreflection/has.go b/internal/features/fastreflection/has.go similarity index 97% rename from features/fastreflection/has.go rename to internal/features/fastreflection/has.go index 64c9d96..c3e8338 100644 --- a/features/fastreflection/has.go +++ b/internal/features/fastreflection/has.go @@ -1,7 +1,7 @@ package fastreflection import ( - "github.com/cosmos/cosmos-proto/generator" + generator2 "github.com/cosmos/cosmos-proto/internal/generator" "google.golang.org/protobuf/compiler/protogen" "google.golang.org/protobuf/reflect/protoreflect" ) @@ -18,7 +18,7 @@ const ( // if oneof: oneof != nil (if oneof is scalar do we need to check it??) // if bytes: len(bytes) != 0 type hasGen struct { - *generator.GeneratedFile + *generator2.GeneratedFile typeName string message *protogen.Message } diff --git a/features/fastreflection/list.go b/internal/features/fastreflection/list.go similarity index 96% rename from features/fastreflection/list.go rename to internal/features/fastreflection/list.go index 9d21648..d46b423 100644 --- a/features/fastreflection/list.go +++ b/internal/features/fastreflection/list.go @@ -2,14 +2,14 @@ package fastreflection import ( "fmt" - "github.com/cosmos/cosmos-proto/generator" + generator2 "github.com/cosmos/cosmos-proto/internal/generator" "google.golang.org/protobuf/compiler/protogen" "google.golang.org/protobuf/reflect/protoreflect" ) type listGen struct { - *generator.GeneratedFile + *generator2.GeneratedFile field *protogen.Field typeName string @@ -154,7 +154,7 @@ func listTypeName(field *protogen.Field) string { return fmt.Sprintf("_%s_%d_list", field.Parent.GoIdent.GoName, field.Desc.Number()) } -func getGoType(g *generator.GeneratedFile, field *protogen.Field) (goType string) { +func getGoType(g *generator2.GeneratedFile, field *protogen.Field) (goType string) { if field.Desc.IsWeak() { return "struct{}" } @@ -246,7 +246,7 @@ func valueUnwrapper(kind protoreflect.Kind) string { } } -func genPrefValueToGoValue(g *generator.GeneratedFile, field *protogen.Field, inputName string, outputName string) string { +func genPrefValueToGoValue(g *generator2.GeneratedFile, field *protogen.Field, inputName string, outputName string) string { unwrapperFunc := valueUnwrapper(field.Desc.Kind()) unwrapperVar := fmt.Sprintf("%sUnwrapped", inputName) @@ -269,7 +269,7 @@ func genPrefValueToGoValue(g *generator.GeneratedFile, field *protogen.Field, in return outputName } -func zeroValueForField(g *generator.GeneratedFile, field *protogen.Field) string { +func zeroValueForField(g *generator2.GeneratedFile, field *protogen.Field) string { switch field.Desc.Kind() { case protoreflect.BoolKind: return "false" diff --git a/features/fastreflection/map.go b/internal/features/fastreflection/map.go similarity index 98% rename from features/fastreflection/map.go rename to internal/features/fastreflection/map.go index 0bec823..b5c5bf6 100644 --- a/features/fastreflection/map.go +++ b/internal/features/fastreflection/map.go @@ -2,14 +2,14 @@ package fastreflection import ( "fmt" - "github.com/cosmos/cosmos-proto/generator" + generator2 "github.com/cosmos/cosmos-proto/internal/generator" "google.golang.org/protobuf/compiler/protogen" "google.golang.org/protobuf/reflect/protoreflect" ) type mapGen struct { - *generator.GeneratedFile + *generator2.GeneratedFile field *protogen.Field // TODO(fdmylja): maybe we could split this field into 2 fields one for key and one for value for the sake of being more readable typeName string diff --git a/features/fastreflection/mutable.go b/internal/features/fastreflection/mutable.go similarity index 98% rename from features/fastreflection/mutable.go rename to internal/features/fastreflection/mutable.go index 637be52..04ba602 100644 --- a/features/fastreflection/mutable.go +++ b/internal/features/fastreflection/mutable.go @@ -1,13 +1,13 @@ package fastreflection import ( - "github.com/cosmos/cosmos-proto/generator" + generator2 "github.com/cosmos/cosmos-proto/internal/generator" "google.golang.org/protobuf/compiler/protogen" "google.golang.org/protobuf/reflect/protoreflect" ) type mutableGen struct { - *generator.GeneratedFile + *generator2.GeneratedFile typeName string message *protogen.Message } diff --git a/features/fastreflection/new_field.go b/internal/features/fastreflection/new_field.go similarity index 96% rename from features/fastreflection/new_field.go rename to internal/features/fastreflection/new_field.go index fa5ca73..54932af 100644 --- a/features/fastreflection/new_field.go +++ b/internal/features/fastreflection/new_field.go @@ -1,13 +1,13 @@ package fastreflection import ( - "github.com/cosmos/cosmos-proto/generator" + generator2 "github.com/cosmos/cosmos-proto/internal/generator" "google.golang.org/protobuf/compiler/protogen" "google.golang.org/protobuf/reflect/protoreflect" ) type newFieldGen struct { - *generator.GeneratedFile + *generator2.GeneratedFile typeName string message *protogen.Message } diff --git a/features/fastreflection/proto_marshal.go b/internal/features/fastreflection/proto_marshal.go similarity index 98% rename from features/fastreflection/proto_marshal.go rename to internal/features/fastreflection/proto_marshal.go index 0fe4f97..48a29a6 100644 --- a/features/fastreflection/proto_marshal.go +++ b/internal/features/fastreflection/proto_marshal.go @@ -2,7 +2,7 @@ package fastreflection import ( "fmt" - "github.com/cosmos/cosmos-proto/generator" + generator2 "github.com/cosmos/cosmos-proto/internal/generator" "google.golang.org/protobuf/compiler/protogen" "google.golang.org/protobuf/encoding/protowire" "google.golang.org/protobuf/reflect/protoreflect" @@ -110,7 +110,7 @@ func (g *fastGenerator) marshalField(proto3 bool, numGen *counter, field *protog g.P(`if x.`, fieldname, ` != nil {`) } packed := field.Desc.IsPacked() - wireType := generator.ProtoWireType(field.Desc.Kind()) + wireType := generator2.ProtoWireType(field.Desc.Kind()) fieldNumber := field.Desc.Number() if packed { wireType = protowire.BytesType @@ -388,10 +388,10 @@ func (g *fastGenerator) marshalField(proto3 bool, numGen *counter, field *protog g.P(`baseI := i`) accessor := `v` g.mapField(field.Message.Fields[1], accessor) - g.encodeKey(2, generator.ProtoWireType(valKind)) + g.encodeKey(2, generator2.ProtoWireType(valKind)) g.mapField(field.Message.Fields[0], "k") - g.encodeKey(1, generator.ProtoWireType(keyKind)) + g.encodeKey(1, generator2.ProtoWireType(keyKind)) g.encodeVarint(`baseI - i`) g.encodeKey(fieldNumber, wireType) g.P("return ", protoifacePkg.Ident("MarshalOutput"), "{}, nil") diff --git a/features/fastreflection/proto_message.go b/internal/features/fastreflection/proto_message.go similarity index 95% rename from features/fastreflection/proto_message.go rename to internal/features/fastreflection/proto_message.go index a762047..a52eb12 100644 --- a/features/fastreflection/proto_message.go +++ b/internal/features/fastreflection/proto_message.go @@ -2,8 +2,8 @@ package fastreflection import ( "fmt" - "github.com/cosmos/cosmos-proto/features/fastreflection/copied" - "github.com/cosmos/cosmos-proto/generator" + copied2 "github.com/cosmos/cosmos-proto/internal/features/fastreflection/copied" + generator2 "github.com/cosmos/cosmos-proto/internal/generator" "google.golang.org/protobuf/compiler/protogen" ) @@ -20,7 +20,7 @@ const ( runtimePackage = protogen.GoImportPath("github.com/cosmos/cosmos-proto/runtime") ) -func GenProtoMessage(f *protogen.File, g *generator.GeneratedFile, message *protogen.Message) { +func GenProtoMessage(f *protogen.File, g *generator2.GeneratedFile, message *protogen.Message) { genMessage(f, g, message) // check for message declarations within a message declaration for _, nested := range message.Messages { @@ -32,7 +32,7 @@ func GenProtoMessage(f *protogen.File, g *generator.GeneratedFile, message *prot } } -func genMessage(f *protogen.File, g *generator.GeneratedFile, message *protogen.Message) { +func genMessage(f *protogen.File, g *generator2.GeneratedFile, message *protogen.Message) { gen := newGenerator(f, g, message) gen.generateExtraTypes() gen.generateReflectionType() @@ -119,7 +119,7 @@ func (g *fastGenerator) generateReflectionType() { g.P() // gen slowreflection - f := copied.NewFileInfo(g.file) + f := copied2.NewFileInfo(g.file) idx := func() int { var id int var found bool @@ -134,7 +134,7 @@ func (g *fastGenerator) generateReflectionType() { } return id }() - typesVar := copied.MessageTypesVarName(f) + typesVar := copied2.MessageTypesVarName(f) // ProtoReflect method. g.P("func (x *", g.message.GoIdent, ") slowProtoReflect() ", protoreflectPkg.Ident("Message"), " {") diff --git a/features/fastreflection/proto_size.go b/internal/features/fastreflection/proto_size.go similarity index 96% rename from features/fastreflection/proto_size.go rename to internal/features/fastreflection/proto_size.go index e8e7e4d..d79bf0e 100644 --- a/features/fastreflection/proto_size.go +++ b/internal/features/fastreflection/proto_size.go @@ -2,7 +2,7 @@ package fastreflection import ( "fmt" - "github.com/cosmos/cosmos-proto/generator" + generator2 "github.com/cosmos/cosmos-proto/internal/generator" "google.golang.org/protobuf/compiler/protogen" "google.golang.org/protobuf/encoding/protowire" "google.golang.org/protobuf/reflect/protoreflect" @@ -90,12 +90,12 @@ func (g *fastGenerator) field(proto3 bool, field *protogen.Field, oneof bool) { } packed := field.Desc.IsPacked() - wireType := generator.ProtoWireType(field.Desc.Kind()) + wireType := generator2.ProtoWireType(field.Desc.Kind()) fieldNumber := field.Desc.Number() if packed { wireType = protowire.BytesType } - key := generator.KeySize(fieldNumber, wireType) + key := generator2.KeySize(fieldNumber, wireType) switch field.Desc.Kind() { case protoreflect.Fixed64Kind, protoreflect.Sfixed64Kind: if packed { @@ -227,14 +227,14 @@ func (g *fastGenerator) field(proto3 bool, field *protogen.Field, oneof bool) { panic(fmt.Errorf("size does not support group %v", fieldname)) case protoreflect.MessageKind: if field.Desc.IsMap() { - fieldKeySize := generator.KeySize(field.Desc.Number(), generator.ProtoWireType(field.Desc.Kind())) + fieldKeySize := generator2.KeySize(field.Desc.Number(), generator2.ProtoWireType(field.Desc.Kind())) goTypeK, _ := g.FieldGoType(field.Message.Fields[0]) goTypeV, ptr := g.FieldGoType(field.Message.Fields[1]) if ptr { goTypeV = "*" + goTypeV } - keyKeySize := generator.KeySize(1, generator.ProtoWireType(field.Message.Fields[0].Desc.Kind())) - valueKeySize := generator.KeySize(2, generator.ProtoWireType(field.Message.Fields[1].Desc.Kind())) + keyKeySize := generator2.KeySize(1, generator2.ProtoWireType(field.Message.Fields[0].Desc.Kind())) + valueKeySize := generator2.KeySize(2, generator2.ProtoWireType(field.Message.Fields[1].Desc.Kind())) sum := []string{strconv.Itoa(keyKeySize)} g.P("SiZeMaP := func(k ", goTypeK, ", v ", goTypeV, ") {") diff --git a/features/fastreflection/proto_unmarshal.go b/internal/features/fastreflection/proto_unmarshal.go similarity index 95% rename from features/fastreflection/proto_unmarshal.go rename to internal/features/fastreflection/proto_unmarshal.go index b2f660f..7bb0636 100644 --- a/features/fastreflection/proto_unmarshal.go +++ b/internal/features/fastreflection/proto_unmarshal.go @@ -2,7 +2,7 @@ package fastreflection import ( "fmt" - "github.com/cosmos/cosmos-proto/generator" + generator2 "github.com/cosmos/cosmos-proto/internal/generator" "google.golang.org/protobuf/compiler/protogen" "google.golang.org/protobuf/encoding/protowire" "google.golang.org/protobuf/reflect/protoreflect" @@ -76,7 +76,7 @@ func (g *fastGenerator) genUnmarshalMethod() { g.P(`if (iNdEx + skippy) > l {`) g.P(`return `, protoifacePkg.Ident("UnmarshalOutput"), "{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags},", g.Ident("io", `ErrUnexpectedEOF`)) g.P(`}`) - g.P(g.Ident(generator.ProtoPkg, "AppendExtension"), `(m, int32(fieldNum), dAtA[iNdEx:iNdEx+skippy])`) + g.P(g.Ident(generator2.ProtoPkg, "AppendExtension"), `(m, int32(fieldNum), dAtA[iNdEx:iNdEx+skippy])`) g.P(`iNdEx += skippy`) g.P(`} else {`) } @@ -115,7 +115,7 @@ func (g *fastGenerator) genUnmarshalMethod() { panic("missing required field") } g.P(`if hasFields[`, strconv.Itoa(fieldBit/64), `] & uint64(`, fmt.Sprintf("0x%08x", uint64(1)<<(fieldBit%64)), `) == 0 {`) - g.P(`return `, protoifacePkg.Ident("UnmarshalOutput"), "{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags},", `new(`, g.Ident(generator.ProtoPkg, "RequiredNotSetError"), `)`) + g.P(`return `, protoifacePkg.Ident("UnmarshalOutput"), "{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags},", `new(`, g.Ident(generator2.ProtoPkg, "RequiredNotSetError"), `)`) g.P(`}`) } g.P() @@ -151,7 +151,7 @@ func (g *fastGenerator) unmarshalField(field *protogen.Field, message *protogen. } g.P(`case `, strconv.Itoa(int(field.Desc.Number())), `:`) - wireType := generator.ProtoWireType(field.Desc.Kind()) + wireType := generator2.ProtoWireType(field.Desc.Kind()) if field.Desc.IsList() && wireType != protowire.BytesType { g.P(`if wireType == `, strconv.Itoa(int(wireType)), `{`) g.fieldItem(field, fieldname, message, false) @@ -187,12 +187,7 @@ func (g *fastGenerator) unmarshalField(field *protogen.Field, message *protogen. g.P(`elementCount = packedLen`) } - if g.ShouldPool(message) { - g.P(`if elementCount != 0 && len(x.`, fieldname, `) == 0 && cap(x.`, fieldname, `) < elementCount {`) - } else { - g.P(`if elementCount != 0 && len(x.`, fieldname, `) == 0 {`) - } - + g.P(`if elementCount != 0 && len(x.`, fieldname, `) == 0 {`) fieldtyp, _ := g.FieldGoType(field) g.P(`x.`, fieldname, ` = make(`, fieldtyp, `, 0, elementCount)`) g.P(`}`) @@ -444,28 +439,13 @@ func (g *fastGenerator) fieldItem(field *protogen.Field, fieldname string, messa g.P(`}`) g.P(`x.`, fieldname, `[mapkey] = mapvalue`) } else if repeated { - if g.ShouldPool(message) { - g.P(`if len(x.`, fieldname, `) == cap(x.`, fieldname, `) {`) - g.P(`x.`, fieldname, ` = append(x.`, fieldname, `, &`, field.Message.GoIdent, `{})`) - g.P(`} else {`) - g.P(`x.`, fieldname, ` = x.`, fieldname, `[:len(x.`, fieldname, `) + 1]`) - g.P(`if x.`, fieldname, `[len(x.`, fieldname, `) - 1] == nil {`) - g.P(`x.`, fieldname, `[len(x.`, fieldname, `) - 1] = &`, field.Message.GoIdent, `{}`) - g.P(`}`) - g.P(`}`) - } else { - g.P(`x.`, fieldname, ` = append(x.`, fieldname, `, &`, field.Message.GoIdent, `{})`) - } + g.P(`x.`, fieldname, ` = append(x.`, fieldname, `, &`, field.Message.GoIdent, `{})`) varname := fmt.Sprintf("x.%s[len(x.%s) - 1]", fieldname, fieldname) buf := `dAtA[iNdEx:postIndex]` g.decodeMessage(varname, buf, field.Message) } else { g.P(`if x.`, fieldname, ` == nil {`) - if g.ShouldPool(message) && g.ShouldPool(field.Message) { - g.P(`x.`, fieldname, ` = `, field.Message.GoIdent, `FromVTPool()`) - } else { - g.P(`x.`, fieldname, ` = &`, field.Message.GoIdent, `{}`) - } + g.P(`x.`, fieldname, ` = &`, field.Message.GoIdent, `{}`) g.P(`}`) g.decodeMessage("x."+fieldname, "dAtA[iNdEx:postIndex]", field.Message) } diff --git a/features/fastreflection/range.go b/internal/features/fastreflection/range.go similarity index 98% rename from features/fastreflection/range.go rename to internal/features/fastreflection/range.go index 30d073e..e94b996 100644 --- a/features/fastreflection/range.go +++ b/internal/features/fastreflection/range.go @@ -1,13 +1,13 @@ package fastreflection import ( - "github.com/cosmos/cosmos-proto/generator" + generator2 "github.com/cosmos/cosmos-proto/internal/generator" "google.golang.org/protobuf/compiler/protogen" "google.golang.org/protobuf/reflect/protoreflect" ) type rangeGen struct { - *generator.GeneratedFile + *generator2.GeneratedFile typeName string message *protogen.Message diff --git a/features/fastreflection/set.go b/internal/features/fastreflection/set.go similarity index 98% rename from features/fastreflection/set.go rename to internal/features/fastreflection/set.go index d271221..3d1caaf 100644 --- a/features/fastreflection/set.go +++ b/internal/features/fastreflection/set.go @@ -1,13 +1,13 @@ package fastreflection import ( - "github.com/cosmos/cosmos-proto/generator" + generator2 "github.com/cosmos/cosmos-proto/internal/generator" "google.golang.org/protobuf/compiler/protogen" "google.golang.org/protobuf/reflect/protoreflect" ) type setGen struct { - *generator.GeneratedFile + *generator2.GeneratedFile typeName string message *protogen.Message } diff --git a/features/fastreflection/type.go b/internal/features/fastreflection/type.go similarity index 93% rename from features/fastreflection/type.go rename to internal/features/fastreflection/type.go index 77935fa..b736391 100644 --- a/features/fastreflection/type.go +++ b/internal/features/fastreflection/type.go @@ -2,7 +2,7 @@ package fastreflection import ( "fmt" - "github.com/cosmos/cosmos-proto/generator" + generator2 "github.com/cosmos/cosmos-proto/internal/generator" "google.golang.org/protobuf/compiler/protogen" ) @@ -17,7 +17,7 @@ func messageTypeNameVar(message *protogen.Message) string { type messageTypeGen struct { typeName string - *generator.GeneratedFile + *generator2.GeneratedFile message *protogen.Message messageTypeName string diff --git a/features/fastreflection/which_oneof.go b/internal/features/fastreflection/which_oneof.go similarity index 94% rename from features/fastreflection/which_oneof.go rename to internal/features/fastreflection/which_oneof.go index e47aac6..970d974 100644 --- a/features/fastreflection/which_oneof.go +++ b/internal/features/fastreflection/which_oneof.go @@ -1,12 +1,12 @@ package fastreflection import ( - "github.com/cosmos/cosmos-proto/generator" + generator2 "github.com/cosmos/cosmos-proto/internal/generator" "google.golang.org/protobuf/compiler/protogen" ) type whichOneofGen struct { - *generator.GeneratedFile + *generator2.GeneratedFile typeName string message *protogen.Message } diff --git a/features/protoc/feature.go b/internal/features/protoc/feature.go similarity index 57% rename from features/protoc/feature.go rename to internal/features/protoc/feature.go index 29a24e3..4cf4664 100644 --- a/features/protoc/feature.go +++ b/internal/features/protoc/feature.go @@ -1,14 +1,14 @@ package protoc import ( - "github.com/cosmos/cosmos-proto/generator" + generator2 "github.com/cosmos/cosmos-proto/internal/generator" "google.golang.org/protobuf/compiler/protogen" ) func init() { - generator.RegisterFeature("protoc", func(gen *generator.GeneratedFile, plugin *protogen.Plugin) generator.FeatureGenerator { + generator2.RegisterFeature("protoc", func(gen *generator2.GeneratedFile, plugin *protogen.Plugin) generator2.FeatureGenerator { return protocGenGoFeature{ - Plugin: plugin, + Plugin: plugin, GeneratedFile: gen, once: false, } @@ -17,7 +17,7 @@ func init() { type protocGenGoFeature struct { *protogen.Plugin - *generator.GeneratedFile + *generator2.GeneratedFile once bool } @@ -26,4 +26,4 @@ func (pg protocGenGoFeature) GenerateFile(file *protogen.File, plugin *protogen. return pg.once } -func (pg protocGenGoFeature) GenerateHelpers() {} //noop \ No newline at end of file +func (pg protocGenGoFeature) GenerateHelpers() {} //noop diff --git a/features/protoc/genid/any_gen.go b/internal/features/protoc/genid/any_gen.go similarity index 100% rename from features/protoc/genid/any_gen.go rename to internal/features/protoc/genid/any_gen.go diff --git a/features/protoc/genid/api_gen.go b/internal/features/protoc/genid/api_gen.go similarity index 100% rename from features/protoc/genid/api_gen.go rename to internal/features/protoc/genid/api_gen.go diff --git a/features/protoc/genid/descriptor_gen.go b/internal/features/protoc/genid/descriptor_gen.go similarity index 100% rename from features/protoc/genid/descriptor_gen.go rename to internal/features/protoc/genid/descriptor_gen.go diff --git a/features/protoc/genid/doc.go b/internal/features/protoc/genid/doc.go similarity index 100% rename from features/protoc/genid/doc.go rename to internal/features/protoc/genid/doc.go diff --git a/features/protoc/genid/duration_gen.go b/internal/features/protoc/genid/duration_gen.go similarity index 100% rename from features/protoc/genid/duration_gen.go rename to internal/features/protoc/genid/duration_gen.go diff --git a/features/protoc/genid/empty_gen.go b/internal/features/protoc/genid/empty_gen.go similarity index 100% rename from features/protoc/genid/empty_gen.go rename to internal/features/protoc/genid/empty_gen.go diff --git a/features/protoc/genid/field_mask_gen.go b/internal/features/protoc/genid/field_mask_gen.go similarity index 100% rename from features/protoc/genid/field_mask_gen.go rename to internal/features/protoc/genid/field_mask_gen.go diff --git a/features/protoc/genid/goname.go b/internal/features/protoc/genid/goname.go similarity index 100% rename from features/protoc/genid/goname.go rename to internal/features/protoc/genid/goname.go diff --git a/features/protoc/genid/map_entry.go b/internal/features/protoc/genid/map_entry.go similarity index 100% rename from features/protoc/genid/map_entry.go rename to internal/features/protoc/genid/map_entry.go diff --git a/features/protoc/genid/source_context_gen.go b/internal/features/protoc/genid/source_context_gen.go similarity index 100% rename from features/protoc/genid/source_context_gen.go rename to internal/features/protoc/genid/source_context_gen.go diff --git a/features/protoc/genid/struct_gen.go b/internal/features/protoc/genid/struct_gen.go similarity index 100% rename from features/protoc/genid/struct_gen.go rename to internal/features/protoc/genid/struct_gen.go diff --git a/features/protoc/genid/timestamp_gen.go b/internal/features/protoc/genid/timestamp_gen.go similarity index 100% rename from features/protoc/genid/timestamp_gen.go rename to internal/features/protoc/genid/timestamp_gen.go diff --git a/features/protoc/genid/type_gen.go b/internal/features/protoc/genid/type_gen.go similarity index 100% rename from features/protoc/genid/type_gen.go rename to internal/features/protoc/genid/type_gen.go diff --git a/features/protoc/genid/wrappers.go b/internal/features/protoc/genid/wrappers.go similarity index 100% rename from features/protoc/genid/wrappers.go rename to internal/features/protoc/genid/wrappers.go diff --git a/features/protoc/genid/wrappers_gen.go b/internal/features/protoc/genid/wrappers_gen.go similarity index 100% rename from features/protoc/genid/wrappers_gen.go rename to internal/features/protoc/genid/wrappers_gen.go diff --git a/features/protoc/main.go b/internal/features/protoc/main.go similarity index 95% rename from features/protoc/main.go rename to internal/features/protoc/main.go index 3cc5a1a..6a1ad77 100644 --- a/features/protoc/main.go +++ b/internal/features/protoc/main.go @@ -7,8 +7,9 @@ package protoc import ( "fmt" - "github.com/cosmos/cosmos-proto/features/protoc/genid" - "github.com/cosmos/cosmos-proto/generator" + genid2 "github.com/cosmos/cosmos-proto/internal/features/protoc/genid" + version2 "github.com/cosmos/cosmos-proto/internal/features/protoc/version" + generator2 "github.com/cosmos/cosmos-proto/internal/generator" "go/ast" "go/parser" "go/token" @@ -22,7 +23,6 @@ import ( pref "google.golang.org/protobuf/reflect/protoreflect" - "github.com/cosmos/cosmos-proto/features/protoc/version" "google.golang.org/protobuf/compiler/protogen" "google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/runtime/protoimpl" @@ -63,14 +63,14 @@ var ( ) // GenerateFile generates the contents of a .pb.go file. -func GenerateFile(gen *protogen.Plugin, file *protogen.File, g *generator.GeneratedFile) *generator.GeneratedFile { +func GenerateFile(gen *protogen.Plugin, file *protogen.File, g *generator2.GeneratedFile) *generator2.GeneratedFile { // filename := file.GeneratedFilenamePrefix + ".pb.go" // g := gen.NewGeneratedFile(filename, file.GoImportPath) f := newFileInfo(file) - genStandaloneComments(g, f, int32(genid.FileDescriptorProto_Syntax_field_number)) + genStandaloneComments(g, f, int32(genid2.FileDescriptorProto_Syntax_field_number)) genGeneratedHeader(gen, g, f) - genStandaloneComments(g, f, int32(genid.FileDescriptorProto_Package_field_number)) + genStandaloneComments(g, f, int32(genid2.FileDescriptorProto_Package_field_number)) // Emit a static check that enforces a minimum version of the proto package. if GenerateVersionMarkers { @@ -128,7 +128,7 @@ func initFuncName(f *protogen.File) string { return fileVarName(f, "init") } -func genFileDescriptor(gen *protogen.Plugin, g *generator.GeneratedFile, f *fileInfo) { +func genFileDescriptor(gen *protogen.Plugin, g *generator2.GeneratedFile, f *fileInfo) { descProto := proto.Clone(f.Proto).(*descriptorpb.FileDescriptorProto) descProto.SourceCodeInfo = nil // drop source code information @@ -175,7 +175,7 @@ func genFileDescriptor(gen *protogen.Plugin, g *generator.GeneratedFile, f *file } } -func genReflectFileDescriptor(gen *protogen.Plugin, g *generator.GeneratedFile, f *fileInfo) { +func genReflectFileDescriptor(gen *protogen.Plugin, g *generator2.GeneratedFile, f *fileInfo) { g.P("var ", f.GoDescriptorIdent, " ", protoreflectPackage.Ident("FileDescriptor")) g.P() @@ -393,7 +393,7 @@ func genReflectFileDescriptor(gen *protogen.Plugin, g *generator.GeneratedFile, // genStandaloneComments prints all leading comments for a FileDescriptorProto // location identified by the field number n. -func genStandaloneComments(g *generator.GeneratedFile, f *fileInfo, n int32) { +func genStandaloneComments(g *generator2.GeneratedFile, f *fileInfo, n int32) { loc := f.Desc.SourceLocations().ByPath(protoreflect.SourcePath{n}) for _, s := range loc.LeadingDetachedComments { g.P(protogen.Comments(s)) @@ -405,12 +405,12 @@ func genStandaloneComments(g *generator.GeneratedFile, f *fileInfo, n int32) { } } -func genGeneratedHeader(gen *protogen.Plugin, g *generator.GeneratedFile, f *fileInfo) { +func genGeneratedHeader(gen *protogen.Plugin, g *generator2.GeneratedFile, f *fileInfo) { g.P("// Code generated by protoc-gen-go. DO NOT EDIT.") if GenerateVersionMarkers { g.P("// versions:") - protocGenGoVersion := version.String() + protocGenGoVersion := version2.String() protocVersion := "(unknown)" if v := gen.Request.GetCompilerVersion(); v != nil { protocVersion = fmt.Sprintf("v%v.%v.%v", v.GetMajor(), v.GetMinor(), v.GetPatch()) @@ -430,7 +430,7 @@ func genGeneratedHeader(gen *protogen.Plugin, g *generator.GeneratedFile, f *fil g.P() } -func genImport(gen *protogen.Plugin, g *generator.GeneratedFile, f *fileInfo, imp protoreflect.FileImport) { +func genImport(gen *protogen.Plugin, g *generator2.GeneratedFile, f *fileInfo, imp protoreflect.FileImport) { impFile, ok := gen.FilesByPath[imp.Path()] if !ok { return @@ -510,7 +510,7 @@ func genImport(gen *protogen.Plugin, g *generator.GeneratedFile, f *fileInfo, im g.P() } -func genEnumReflectMethods(g *generator.GeneratedFile, f *fileInfo, e *enumInfo) { +func genEnumReflectMethods(g *generator2.GeneratedFile, f *fileInfo, e *enumInfo) { idx := f.allEnumsByPtr[e] typesVar := enumTypesVarName(f) @@ -533,7 +533,7 @@ func genEnumReflectMethods(g *generator.GeneratedFile, f *fileInfo, e *enumInfo) g.P() } -func genEnum(g *generator.GeneratedFile, f *fileInfo, e *enumInfo) { +func genEnum(g *generator2.GeneratedFile, f *fileInfo, e *enumInfo) { // Enum type declaration. g.Annotate(e.GoIdent.GoName, e.Location) leadingComments := appendDeprecationSuffix(e.Comments.Leading, @@ -623,7 +623,7 @@ func genEnum(g *generator.GeneratedFile, f *fileInfo, e *enumInfo) { } } -func genMessage(g *generator.GeneratedFile, f *fileInfo, m *messageInfo) { +func genMessage(g *generator2.GeneratedFile, f *fileInfo, m *messageInfo) { if m.Desc.IsMapEntry() { return } @@ -644,9 +644,9 @@ func genMessage(g *generator.GeneratedFile, f *fileInfo, m *messageInfo) { genMessageOneofWrapperTypes(g, f, m) } -func genMessageKnownFunctions(g *generator.GeneratedFile, f *fileInfo, m *messageInfo) { +func genMessageKnownFunctions(g *generator2.GeneratedFile, f *fileInfo, m *messageInfo) { switch m.Desc.FullName() { - case genid.Any_message_fullname: + case genid2.Any_message_fullname: g.P("// New marshals src into a new Any instance.") g.P("func New(src ", protoPackage.Ident("Message"), ") (*Any, error) {") g.P(" dst := new(Any)") @@ -775,7 +775,7 @@ func genMessageKnownFunctions(g *generator.GeneratedFile, f *fileInfo, m *messag g.P("}") g.P() - case genid.Timestamp_message_fullname: + case genid2.Timestamp_message_fullname: g.P("// Now constructs a new Timestamp from the current time.") g.P("func Now() *Timestamp {") g.P(" return New(", timePackage.Ident("Now"), "())") @@ -850,7 +850,7 @@ func genMessageKnownFunctions(g *generator.GeneratedFile, f *fileInfo, m *messag g.P("}") g.P() - case genid.Duration_message_fullname: + case genid2.Duration_message_fullname: g.P("// New constructs a new Duration from the provided time.Duration.") g.P("func New(d ", timePackage.Ident("Duration"), ") *Duration {") g.P(" nanos := d.Nanoseconds()") @@ -942,7 +942,7 @@ func genMessageKnownFunctions(g *generator.GeneratedFile, f *fileInfo, m *messag g.P("}") g.P() - case genid.Struct_message_fullname: + case genid2.Struct_message_fullname: g.P("// NewStruct constructs a Struct from a general-purpose Go map.") g.P("// The map keys must be valid UTF-8.") g.P("// The map values are converted using NewValue.") @@ -983,7 +983,7 @@ func genMessageKnownFunctions(g *generator.GeneratedFile, f *fileInfo, m *messag g.P("}") g.P() - case genid.ListValue_message_fullname: + case genid2.ListValue_message_fullname: g.P("// NewList constructs a ListValue from a general-purpose Go slice.") g.P("// The slice elements are converted using NewValue.") g.P("func NewList(v []interface{}) (*ListValue, error) {") @@ -1020,7 +1020,7 @@ func genMessageKnownFunctions(g *generator.GeneratedFile, f *fileInfo, m *messag g.P("}") g.P() - case genid.Value_message_fullname: + case genid2.Value_message_fullname: g.P("// NewValue constructs a Value from a general-purpose Go interface.") g.P("//") g.P("// ╔════════════════════════╤════════════════════════════════════════════╗") @@ -1176,7 +1176,7 @@ func genMessageKnownFunctions(g *generator.GeneratedFile, f *fileInfo, m *messag g.P("}") g.P() - case genid.FieldMask_message_fullname: + case genid2.FieldMask_message_fullname: g.P("// New constructs a field mask from a list of paths and verifies that") g.P("// each one is valid according to the specified message type.") g.P("func New(m ", protoPackage.Ident("Message"), ", paths ...string) (*FieldMask, error) {") @@ -1360,15 +1360,15 @@ func genMessageKnownFunctions(g *generator.GeneratedFile, f *fileInfo, m *messag g.P("}") g.P() - case genid.BoolValue_message_fullname, - genid.Int32Value_message_fullname, - genid.Int64Value_message_fullname, - genid.UInt32Value_message_fullname, - genid.UInt64Value_message_fullname, - genid.FloatValue_message_fullname, - genid.DoubleValue_message_fullname, - genid.StringValue_message_fullname, - genid.BytesValue_message_fullname: + case genid2.BoolValue_message_fullname, + genid2.Int32Value_message_fullname, + genid2.Int64Value_message_fullname, + genid2.UInt32Value_message_fullname, + genid2.UInt64Value_message_fullname, + genid2.FloatValue_message_fullname, + genid2.DoubleValue_message_fullname, + genid2.StringValue_message_fullname, + genid2.BytesValue_message_fullname: funcName := strings.TrimSuffix(m.GoIdent.GoName, "Value") typeName := strings.ToLower(funcName) switch typeName { @@ -1388,7 +1388,7 @@ func genMessageKnownFunctions(g *generator.GeneratedFile, f *fileInfo, m *messag } } -func genMessageFields(g *generator.GeneratedFile, f *fileInfo, m *messageInfo) { +func genMessageFields(g *generator2.GeneratedFile, f *fileInfo, m *messageInfo) { sf := f.allMessageFieldsByPtr[m] genMessageInternalFields(g, f, m, sf) for _, field := range m.Fields { @@ -1396,27 +1396,27 @@ func genMessageFields(g *generator.GeneratedFile, f *fileInfo, m *messageInfo) { } } -func genMessageInternalFields(g *generator.GeneratedFile, f *fileInfo, m *messageInfo, sf *structFields) { - g.P(genid.State_goname, " ", protoimplPackage.Ident("MessageState")) - sf.append(genid.State_goname) - g.P(genid.SizeCache_goname, " ", protoimplPackage.Ident("SizeCache")) - sf.append(genid.SizeCache_goname) +func genMessageInternalFields(g *generator2.GeneratedFile, f *fileInfo, m *messageInfo, sf *structFields) { + g.P(genid2.State_goname, " ", protoimplPackage.Ident("MessageState")) + sf.append(genid2.State_goname) + g.P(genid2.SizeCache_goname, " ", protoimplPackage.Ident("SizeCache")) + sf.append(genid2.SizeCache_goname) if m.hasWeak { - g.P(genid.WeakFields_goname, " ", protoimplPackage.Ident("WeakFields")) - sf.append(genid.WeakFields_goname) + g.P(genid2.WeakFields_goname, " ", protoimplPackage.Ident("WeakFields")) + sf.append(genid2.WeakFields_goname) } - g.P(genid.UnknownFields_goname, " ", protoimplPackage.Ident("UnknownFields")) - sf.append(genid.UnknownFields_goname) + g.P(genid2.UnknownFields_goname, " ", protoimplPackage.Ident("UnknownFields")) + sf.append(genid2.UnknownFields_goname) if m.Desc.ExtensionRanges().Len() > 0 { - g.P(genid.ExtensionFields_goname, " ", protoimplPackage.Ident("ExtensionFields")) - sf.append(genid.ExtensionFields_goname) + g.P(genid2.ExtensionFields_goname, " ", protoimplPackage.Ident("ExtensionFields")) + sf.append(genid2.ExtensionFields_goname) } if sf.count > 0 { g.P() } } -func genMessageField(g *generator.GeneratedFile, f *fileInfo, m *messageInfo, field *protogen.Field, sf *structFields) { +func genMessageField(g *generator2.GeneratedFile, f *fileInfo, m *messageInfo, field *protogen.Field, sf *structFields) { if oneof := field.Oneof; oneof != nil && !oneof.Desc.IsSynthetic() { // It would be a bit simpler to iterate over the oneofs below, // but generating the field here keeps the contents of the Go @@ -1470,7 +1470,7 @@ func genMessageField(g *generator.GeneratedFile, f *fileInfo, m *messageInfo, fi name := field.GoName if field.Desc.IsWeak() { - name = genid.WeakFieldPrefix_goname + name + name = genid2.WeakFieldPrefix_goname + name } g.Annotate(m.GoIdent.GoName+"."+name, field.Location) leadingComments := appendDeprecationSuffix(field.Comments.Leading, @@ -1483,7 +1483,7 @@ func genMessageField(g *generator.GeneratedFile, f *fileInfo, m *messageInfo, fi // genMessageDefaultDecls generates consts and vars holding the default // values of fields. -func genMessageDefaultDecls(g *generator.GeneratedFile, f *fileInfo, m *messageInfo) { +func genMessageDefaultDecls(g *generator2.GeneratedFile, f *fileInfo, m *messageInfo) { var consts, vars []string for _, field := range m.Fields { if !field.Desc.HasDefault() { @@ -1547,13 +1547,13 @@ func genMessageDefaultDecls(g *generator.GeneratedFile, f *fileInfo, m *messageI g.P() } -func genMessageMethods(g *generator.GeneratedFile, f *fileInfo, m *messageInfo) { +func genMessageMethods(g *generator2.GeneratedFile, f *fileInfo, m *messageInfo) { genMessageBaseMethods(g, f, m) genMessageGetterMethods(g, f, m) genMessageSetterMethods(g, f, m) } -func genMessageBaseMethods(g *generator.GeneratedFile, f *fileInfo, m *messageInfo) { +func genMessageBaseMethods(g *generator2.GeneratedFile, f *fileInfo, m *messageInfo) { // Reset method. g.P("func (x *", m.GoIdent, ") Reset() {") g.P("*x = ", m.GoIdent, "{}") @@ -1593,7 +1593,7 @@ func genMessageBaseMethods(g *generator.GeneratedFile, f *fileInfo, m *messageIn } } -func genMessageGetterMethods(g *generator.GeneratedFile, f *fileInfo, m *messageInfo) { +func genMessageGetterMethods(g *generator2.GeneratedFile, f *fileInfo, m *messageInfo) { for _, field := range m.Fields { genNoInterfacePragma(g, m.isTracked) @@ -1620,9 +1620,9 @@ func genMessageGetterMethods(g *generator.GeneratedFile, f *fileInfo, m *message g.P(leadingComments, "func (x *", m.GoIdent, ") Get", field.GoName, "() ", protoPackage.Ident("Message"), "{") g.P("var w ", protoimplPackage.Ident("WeakFields")) g.P("if x != nil {") - g.P("w = x.", genid.WeakFields_goname) + g.P("w = x.", genid2.WeakFields_goname) if m.isTracked { - g.P("_ = x.", genid.WeakFieldPrefix_goname+field.GoName) + g.P("_ = x.", genid2.WeakFieldPrefix_goname+field.GoName) } g.P("}") g.P("return ", protoimplPackage.Ident("X"), ".GetWeak(w, ", field.Desc.Number(), ", ", strconv.Quote(string(field.Message.Desc.FullName())), ")") @@ -1654,7 +1654,7 @@ func genMessageGetterMethods(g *generator.GeneratedFile, f *fileInfo, m *message } } -func genMessageSetterMethods(g *generator.GeneratedFile, f *fileInfo, m *messageInfo) { +func genMessageSetterMethods(g *generator2.GeneratedFile, f *fileInfo, m *messageInfo) { for _, field := range m.Fields { if !field.Desc.IsWeak() { continue @@ -1668,9 +1668,9 @@ func genMessageSetterMethods(g *generator.GeneratedFile, f *fileInfo, m *message g.P(leadingComments, "func (x *", m.GoIdent, ") Set", field.GoName, "(v ", protoPackage.Ident("Message"), ") {") g.P("var w *", protoimplPackage.Ident("WeakFields")) g.P("if x != nil {") - g.P("w = &x.", genid.WeakFields_goname) + g.P("w = &x.", genid2.WeakFields_goname) if m.isTracked { - g.P("_ = x.", genid.WeakFieldPrefix_goname+field.GoName) + g.P("_ = x.", genid2.WeakFieldPrefix_goname+field.GoName) } g.P("}") g.P(protoimplPackage.Ident("X"), ".SetWeak(w, ", field.Desc.Number(), ", ", strconv.Quote(string(field.Message.Desc.FullName())), ", v)") @@ -1682,7 +1682,7 @@ func genMessageSetterMethods(g *generator.GeneratedFile, f *fileInfo, m *message // fieldGoType returns the Go type used for a field. // // If it returns pointer=true, the struct field is a pointer to the type. -func fieldGoType(g *generator.GeneratedFile, f *fileInfo, field *protogen.Field) (goType string, pointer bool) { +func fieldGoType(g *generator2.GeneratedFile, f *fileInfo, field *protogen.Field) (goType string, pointer bool) { if field.Desc.IsWeak() { return "struct{}", false } @@ -1733,7 +1733,7 @@ func fieldProtobufTagValue(field *protogen.Field) string { return TagMarshal(field.Desc, enumName) } -func fieldDefaultValue(g *generator.GeneratedFile, f *fileInfo, m *messageInfo, field *protogen.Field) string { +func fieldDefaultValue(g *generator2.GeneratedFile, f *fileInfo, m *messageInfo, field *protogen.Field) string { if field.Desc.IsList() { return "nil" } @@ -1770,7 +1770,7 @@ func fieldJSONTagValue(field *protogen.Field) string { return string(field.Desc.Name()) + ",omitempty" } -func genExtensions(g *generator.GeneratedFile, f *fileInfo) { +func genExtensions(g *generator2.GeneratedFile, f *fileInfo) { if len(f.allExtensions) == 0 { return } @@ -1838,7 +1838,7 @@ func genExtensions(g *generator.GeneratedFile, f *fileInfo) { // genMessageOneofWrapperTypes generates the oneof wrapper types and // associates the types with the parent message type. -func genMessageOneofWrapperTypes(g *generator.GeneratedFile, f *fileInfo, m *messageInfo) { +func genMessageOneofWrapperTypes(g *generator2.GeneratedFile, f *fileInfo, m *messageInfo) { for _, oneof := range m.Oneofs { if oneof.Desc.IsSynthetic() { continue @@ -1882,7 +1882,7 @@ func oneofInterfaceName(oneof *protogen.Oneof) string { // genNoInterfacePragma generates a standalone "nointerface" pragma to // decorate methods with field-tracking support. -func genNoInterfacePragma(g *generator.GeneratedFile, tracked bool) { +func genNoInterfacePragma(g *generator2.GeneratedFile, tracked bool) { if tracked { g.P("//go:nointerface") g.P() @@ -2010,7 +2010,7 @@ func TagMarshal(fd pref.FieldDescriptor, enumName string) string { return strings.Join(tag, ",") } -func genMessageReflectMethods(g *generator.GeneratedFile, f *fileInfo, m *messageInfo) { +func genMessageReflectMethods(g *generator2.GeneratedFile, f *fileInfo, m *messageInfo) { // This is being handled by the fast reflection feature. //idx := f.allMessagesByPtr[m] diff --git a/features/protoc/version/version.go b/internal/features/protoc/version/version.go similarity index 100% rename from features/protoc/version/version.go rename to internal/features/protoc/version/version.go diff --git a/generator/features.go b/internal/generator/features.go similarity index 100% rename from generator/features.go rename to internal/generator/features.go diff --git a/generator/generatedfile.go b/internal/generator/generatedfile.go similarity index 77% rename from generator/generatedfile.go rename to internal/generator/generatedfile.go index 8a17b46..fc63008 100644 --- a/generator/generatedfile.go +++ b/internal/generator/generatedfile.go @@ -6,9 +6,7 @@ package generator import ( "fmt" - vtproto "github.com/cosmos/cosmos-proto/pulsarproto" "google.golang.org/protobuf/compiler/protogen" - "google.golang.org/protobuf/proto" "google.golang.org/protobuf/reflect/protoreflect" ) @@ -22,28 +20,6 @@ func (p *GeneratedFile) Ident(path, ident string) string { return p.QualifiedGoIdent(protogen.GoImportPath(path).Ident(ident)) } -func (b *GeneratedFile) ShouldPool(message *protogen.Message) bool { - if message == nil { - return false - } - if b.Ext.Poolable[message.GoIdent] { - return true - } - ext := proto.GetExtension(message.Desc.Options(), vtproto.E_Mempool) - if mempool, ok := ext.(bool); ok { - return mempool - } - return false -} - -func (b *GeneratedFile) Alloc(vname string, message *protogen.Message) { - if b.ShouldPool(message) { - b.P(vname, " := ", message.GoIdent, `FromVTPool()`) - } else { - b.P(vname, " := new(", message.GoIdent, `)`) - } -} - func (p *GeneratedFile) FieldGoType(field *protogen.Field) (goType string, pointer bool) { if field.Desc.IsWeak() { return "struct{}", false diff --git a/generator/generator.go b/internal/generator/generator.go similarity index 100% rename from generator/generator.go rename to internal/generator/generator.go diff --git a/generator/helpers.go b/internal/generator/helpers.go similarity index 100% rename from generator/helpers.go rename to internal/generator/helpers.go diff --git a/testpb/1.proto b/internal/testpb/1.proto similarity index 80% rename from testpb/1.proto rename to internal/testpb/1.proto index 4504a52..0e6a3bb 100644 --- a/testpb/1.proto +++ b/internal/testpb/1.proto @@ -1,8 +1,6 @@ syntax="proto3"; -option go_package = "github.com/cosmos/cosmos-proto/testpb"; - -import "google/protobuf/descriptor.proto"; +option go_package = "github.com/cosmos/cosmos-proto/internal/testpb"; enum Enumeration { One = 0; @@ -34,7 +32,6 @@ message A { string ONEOF_STRING = 21; }; repeated Enumeration LIST_ENUM = 22; - google.protobuf.FileDescriptorProto imported = 23; } message B { diff --git a/testpb/1.pulsar.go b/internal/testpb/1.pulsar.go similarity index 88% rename from testpb/1.pulsar.go rename to internal/testpb/1.pulsar.go index 28499e4..4d1ee46 100644 --- a/testpb/1.pulsar.go +++ b/internal/testpb/1.pulsar.go @@ -7,7 +7,6 @@ import ( 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" io "io" math "math" reflect "reflect" @@ -226,12 +225,11 @@ var ( fd_A_ONEOF_B protoreflect.FieldDescriptor fd_A_ONEOF_STRING protoreflect.FieldDescriptor fd_A_LIST_ENUM protoreflect.FieldDescriptor - fd_A_imported protoreflect.FieldDescriptor ) func init() { - file_testpb_1_proto_init() - md_A = File_testpb_1_proto.Messages().ByName("A") + file_internal_testpb_1_proto_init() + md_A = File_internal_testpb_1_proto.Messages().ByName("A") fd_A_enum = md_A.Fields().ByName("enum") fd_A_some_boolean = md_A.Fields().ByName("some_boolean") fd_A_INT32 = md_A.Fields().ByName("INT32") @@ -254,7 +252,6 @@ func init() { fd_A_ONEOF_B = md_A.Fields().ByName("ONEOF_B") fd_A_ONEOF_STRING = md_A.Fields().ByName("ONEOF_STRING") fd_A_LIST_ENUM = md_A.Fields().ByName("LIST_ENUM") - fd_A_imported = md_A.Fields().ByName("imported") } var _ protoreflect.Message = (*fastReflection_A)(nil) @@ -266,7 +263,7 @@ func (x *A) ProtoReflect() protoreflect.Message { } func (x *A) slowProtoReflect() protoreflect.Message { - mi := &file_testpb_1_proto_msgTypes[0] + mi := &file_internal_testpb_1_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -458,12 +455,6 @@ func (x *fastReflection_A) Range(f func(protoreflect.FieldDescriptor, protorefle return } } - if x.Imported != nil { - value := protoreflect.ValueOfMessage(x.Imported.ProtoReflect()) - if !f(fd_A_imported, value) { - return - } - } } // Has reports whether a field is populated. @@ -535,8 +526,6 @@ func (x *fastReflection_A) Has(fd protoreflect.FieldDescriptor) bool { } case "A.LIST_ENUM": return len(x.LIST_ENUM) != 0 - case "A.imported": - return x.Imported != nil default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: A")) @@ -597,8 +586,6 @@ func (x *fastReflection_A) Clear(fd protoreflect.FieldDescriptor) { x.ONEOF = nil case "A.LIST_ENUM": x.LIST_ENUM = nil - case "A.imported": - x.Imported = nil default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: A")) @@ -700,9 +687,6 @@ func (x *fastReflection_A) Get(descriptor protoreflect.FieldDescriptor) protoref } listValue := &_A_22_list{list: &x.LIST_ENUM} return protoreflect.ValueOfList(listValue) - case "A.imported": - value := x.Imported - return protoreflect.ValueOfMessage(value.ProtoReflect()) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: A")) @@ -775,8 +759,6 @@ func (x *fastReflection_A) Set(fd protoreflect.FieldDescriptor, value protorefle lv := value.List() clv := lv.(*_A_22_list) x.LIST_ENUM = *clv.list - case "A.imported": - x.Imported = value.Message().Interface().(*descriptorpb.FileDescriptorProto) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: A")) @@ -836,11 +818,6 @@ func (x *fastReflection_A) Mutable(fd protoreflect.FieldDescriptor) protoreflect } value := &_A_22_list{list: &x.LIST_ENUM} return protoreflect.ValueOfList(value) - case "A.imported": - if x.Imported == nil { - x.Imported = new(descriptorpb.FileDescriptorProto) - } - return protoreflect.ValueOfMessage(x.Imported.ProtoReflect()) case "A.enum": panic(fmt.Errorf("field enum of message A is not mutable")) case "A.some_boolean": @@ -937,9 +914,6 @@ func (x *fastReflection_A) NewField(fd protoreflect.FieldDescriptor) protoreflec case "A.LIST_ENUM": list := []Enumeration{} return protoreflect.ValueOfList(&_A_22_list{list: &list}) - case "A.imported": - m := new(descriptorpb.FileDescriptorProto) - return protoreflect.ValueOfMessage(m.ProtoReflect()) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: A")) @@ -1126,10 +1100,6 @@ func (x *fastReflection_A) ProtoMethods() *protoiface.Methods { } n += 2 + runtime.Sov(uint64(l)) + l } - if x.Imported != nil { - l = options.Size(x.Imported) - n += 2 + l + runtime.Sov(uint64(l)) - } if x.unknownFields != nil { n += len(x.unknownFields) } @@ -1184,22 +1154,6 @@ func (x *fastReflection_A) ProtoMethods() *protoiface.Methods { i-- dAtA[i] = 0xaa } - if x.Imported != nil { - encoded, err := options.Marshal(x.Imported) - if err != nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xba - } if len(x.LIST_ENUM) > 0 { var pksize2 int for _, num := range x.LIST_ENUM { @@ -2075,42 +2029,6 @@ func (x *fastReflection_A) ProtoMethods() *protoiface.Methods { } else { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field LIST_ENUM", wireType) } - case 23: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Imported", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if x.Imported == nil { - x.Imported = &descriptorpb.FileDescriptorProto{} - } - if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Imported); err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - iNdEx = postIndex default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -2152,8 +2070,8 @@ var ( ) func init() { - file_testpb_1_proto_init() - md_B = File_testpb_1_proto.Messages().ByName("B") + file_internal_testpb_1_proto_init() + md_B = File_internal_testpb_1_proto.Messages().ByName("B") fd_B_x = md_B.Fields().ByName("x") } @@ -2166,7 +2084,7 @@ func (x *B) ProtoReflect() protoreflect.Message { } func (x *B) slowProtoReflect() protoreflect.Message { - mi := &file_testpb_1_proto_msgTypes[1] + mi := &file_internal_testpb_1_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2569,8 +2487,8 @@ func (x *fastReflection_B) ProtoMethods() *protoiface.Methods { // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.27.0 -// protoc v3.15.7 -// source: testpb/1.proto +// protoc v3.18.1 +// source: internal/testpb/1.proto const ( // Verify that this generated code is sufficiently up-to-date. @@ -2609,11 +2527,11 @@ func (x Enumeration) String() string { } func (Enumeration) Descriptor() protoreflect.EnumDescriptor { - return file_testpb_1_proto_enumTypes[0].Descriptor() + return file_internal_testpb_1_proto_enumTypes[0].Descriptor() } func (Enumeration) Type() protoreflect.EnumType { - return &file_testpb_1_proto_enumTypes[0] + return &file_internal_testpb_1_proto_enumTypes[0] } func (x Enumeration) Number() protoreflect.EnumNumber { @@ -2622,7 +2540,7 @@ func (x Enumeration) Number() protoreflect.EnumNumber { // Deprecated: Use Enumeration.Descriptor instead. func (Enumeration) EnumDescriptor() ([]byte, []int) { - return file_testpb_1_proto_rawDescGZIP(), []int{0} + return file_internal_testpb_1_proto_rawDescGZIP(), []int{0} } type A struct { @@ -2652,15 +2570,14 @@ type A struct { // Types that are assignable to ONEOF: // *A_ONEOF_B // *A_ONEOF_STRING - ONEOF isA_ONEOF `protobuf_oneof:"ONEOF"` - LIST_ENUM []Enumeration `protobuf:"varint,22,rep,packed,name=LIST_ENUM,json=LISTENUM,proto3,enum=Enumeration" json:"LIST_ENUM,omitempty"` - Imported *descriptorpb.FileDescriptorProto `protobuf:"bytes,23,opt,name=imported,proto3" json:"imported,omitempty"` + ONEOF isA_ONEOF `protobuf_oneof:"ONEOF"` + LIST_ENUM []Enumeration `protobuf:"varint,22,rep,packed,name=LIST_ENUM,json=LISTENUM,proto3,enum=Enumeration" json:"LIST_ENUM,omitempty"` } func (x *A) Reset() { *x = A{} if protoimpl.UnsafeEnabled { - mi := &file_testpb_1_proto_msgTypes[0] + mi := &file_internal_testpb_1_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2674,7 +2591,7 @@ func (*A) ProtoMessage() {} // Deprecated: Use A.ProtoReflect.Descriptor instead. func (*A) Descriptor() ([]byte, []int) { - return file_testpb_1_proto_rawDescGZIP(), []int{0} + return file_internal_testpb_1_proto_rawDescGZIP(), []int{0} } func (x *A) GetEnum() Enumeration { @@ -2838,13 +2755,6 @@ func (x *A) GetLIST_ENUM() []Enumeration { return nil } -func (x *A) GetImported() *descriptorpb.FileDescriptorProto { - if x != nil { - return x.Imported - } - return nil -} - type isA_ONEOF interface { isA_ONEOF() } @@ -2872,7 +2782,7 @@ type B struct { func (x *B) Reset() { *x = B{} if protoimpl.UnsafeEnabled { - mi := &file_testpb_1_proto_msgTypes[1] + mi := &file_internal_testpb_1_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2886,7 +2796,7 @@ func (*B) ProtoMessage() {} // Deprecated: Use B.ProtoReflect.Descriptor instead. func (*B) Descriptor() ([]byte, []int) { - return file_testpb_1_proto_rawDescGZIP(), []int{1} + return file_internal_testpb_1_proto_rawDescGZIP(), []int{1} } func (x *B) GetX() string { @@ -2896,112 +2806,104 @@ func (x *B) GetX() string { return "" } -var File_testpb_1_proto protoreflect.FileDescriptor - -var file_testpb_1_proto_rawDesc = []byte{ - 0x0a, 0x0e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, 0x31, 0x2e, 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, 0xe7, 0x05, 0x0a, 0x01, 0x41, 0x12, 0x20, 0x0a, 0x04, 0x65, 0x6e, 0x75, 0x6d, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0c, 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x04, 0x65, 0x6e, 0x75, 0x6d, 0x12, 0x21, 0x0a, 0x0c, 0x73, 0x6f, - 0x6d, 0x65, 0x5f, 0x62, 0x6f, 0x6f, 0x6c, 0x65, 0x61, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, - 0x52, 0x0b, 0x73, 0x6f, 0x6d, 0x65, 0x42, 0x6f, 0x6f, 0x6c, 0x65, 0x61, 0x6e, 0x12, 0x14, 0x0a, - 0x05, 0x49, 0x4e, 0x54, 0x33, 0x32, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x49, 0x4e, - 0x54, 0x33, 0x32, 0x12, 0x16, 0x0a, 0x06, 0x53, 0x49, 0x4e, 0x54, 0x33, 0x32, 0x18, 0x04, 0x20, - 0x01, 0x28, 0x11, 0x52, 0x06, 0x53, 0x49, 0x4e, 0x54, 0x33, 0x32, 0x12, 0x16, 0x0a, 0x06, 0x55, - 0x49, 0x4e, 0x54, 0x33, 0x32, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x55, 0x49, 0x4e, - 0x54, 0x33, 0x32, 0x12, 0x14, 0x0a, 0x05, 0x49, 0x4e, 0x54, 0x36, 0x34, 0x18, 0x06, 0x20, 0x01, - 0x28, 0x03, 0x52, 0x05, 0x49, 0x4e, 0x54, 0x36, 0x34, 0x12, 0x16, 0x0a, 0x06, 0x53, 0x49, 0x4e, - 0x47, 0x36, 0x34, 0x18, 0x07, 0x20, 0x01, 0x28, 0x12, 0x52, 0x06, 0x53, 0x49, 0x4e, 0x47, 0x36, - 0x34, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x49, 0x4e, 0x54, 0x36, 0x34, 0x18, 0x08, 0x20, 0x01, 0x28, - 0x04, 0x52, 0x06, 0x55, 0x49, 0x4e, 0x54, 0x36, 0x34, 0x12, 0x1a, 0x0a, 0x08, 0x53, 0x46, 0x49, - 0x58, 0x45, 0x44, 0x33, 0x32, 0x18, 0x09, 0x20, 0x01, 0x28, 0x0f, 0x52, 0x08, 0x53, 0x46, 0x49, - 0x58, 0x45, 0x44, 0x33, 0x32, 0x12, 0x18, 0x0a, 0x07, 0x46, 0x49, 0x58, 0x45, 0x44, 0x33, 0x32, - 0x18, 0x0a, 0x20, 0x01, 0x28, 0x07, 0x52, 0x07, 0x46, 0x49, 0x58, 0x45, 0x44, 0x33, 0x32, 0x12, - 0x14, 0x0a, 0x05, 0x46, 0x4c, 0x4f, 0x41, 0x54, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x02, 0x52, 0x05, - 0x46, 0x4c, 0x4f, 0x41, 0x54, 0x12, 0x1a, 0x0a, 0x08, 0x53, 0x46, 0x49, 0x58, 0x45, 0x44, 0x36, - 0x34, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x10, 0x52, 0x08, 0x53, 0x46, 0x49, 0x58, 0x45, 0x44, 0x36, - 0x34, 0x12, 0x18, 0x0a, 0x07, 0x46, 0x49, 0x58, 0x45, 0x44, 0x36, 0x34, 0x18, 0x0d, 0x20, 0x01, - 0x28, 0x06, 0x52, 0x07, 0x46, 0x49, 0x58, 0x45, 0x44, 0x36, 0x34, 0x12, 0x16, 0x0a, 0x06, 0x44, - 0x4f, 0x55, 0x42, 0x4c, 0x45, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x01, 0x52, 0x06, 0x44, 0x4f, 0x55, - 0x42, 0x4c, 0x45, 0x12, 0x16, 0x0a, 0x06, 0x53, 0x54, 0x52, 0x49, 0x4e, 0x47, 0x18, 0x0f, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x06, 0x53, 0x54, 0x52, 0x49, 0x4e, 0x47, 0x12, 0x14, 0x0a, 0x05, 0x42, - 0x59, 0x54, 0x45, 0x53, 0x18, 0x10, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x42, 0x59, 0x54, 0x45, - 0x53, 0x12, 0x1c, 0x0a, 0x07, 0x4d, 0x45, 0x53, 0x53, 0x41, 0x47, 0x45, 0x18, 0x11, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x02, 0x2e, 0x42, 0x52, 0x07, 0x4d, 0x45, 0x53, 0x53, 0x41, 0x47, 0x45, 0x12, - 0x1d, 0x0a, 0x03, 0x4d, 0x41, 0x50, 0x18, 0x12, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x41, - 0x2e, 0x4d, 0x41, 0x50, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x03, 0x4d, 0x41, 0x50, 0x12, 0x16, - 0x0a, 0x04, 0x4c, 0x49, 0x53, 0x54, 0x18, 0x13, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x02, 0x2e, 0x42, - 0x52, 0x04, 0x4c, 0x49, 0x53, 0x54, 0x12, 0x1d, 0x0a, 0x07, 0x4f, 0x4e, 0x45, 0x4f, 0x46, 0x5f, - 0x42, 0x18, 0x14, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x02, 0x2e, 0x42, 0x48, 0x00, 0x52, 0x06, 0x4f, - 0x4e, 0x45, 0x4f, 0x46, 0x42, 0x12, 0x23, 0x0a, 0x0c, 0x4f, 0x4e, 0x45, 0x4f, 0x46, 0x5f, 0x53, - 0x54, 0x52, 0x49, 0x4e, 0x47, 0x18, 0x15, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x0b, 0x4f, - 0x4e, 0x45, 0x4f, 0x46, 0x53, 0x54, 0x52, 0x49, 0x4e, 0x47, 0x12, 0x29, 0x0a, 0x09, 0x4c, 0x49, - 0x53, 0x54, 0x5f, 0x45, 0x4e, 0x55, 0x4d, 0x18, 0x16, 0x20, 0x03, 0x28, 0x0e, 0x32, 0x0c, 0x2e, - 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x08, 0x4c, 0x49, 0x53, - 0x54, 0x45, 0x4e, 0x55, 0x4d, 0x12, 0x40, 0x0a, 0x08, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x65, - 0x64, 0x18, 0x17, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x44, 0x65, - 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x52, 0x08, 0x69, - 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x1a, 0x3a, 0x0a, 0x08, 0x4d, 0x41, 0x50, 0x45, 0x6e, - 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x18, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x02, 0x2e, 0x42, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, - 0x02, 0x38, 0x01, 0x42, 0x07, 0x0a, 0x05, 0x4f, 0x4e, 0x45, 0x4f, 0x46, 0x22, 0x11, 0x0a, 0x01, - 0x42, 0x12, 0x0c, 0x0a, 0x01, 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x01, 0x78, 0x2a, - 0x1f, 0x0a, 0x0b, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x07, - 0x0a, 0x03, 0x4f, 0x6e, 0x65, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x54, 0x77, 0x6f, 0x10, 0x01, - 0x42, 0x27, 0x5a, 0x25, 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, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, +var File_internal_testpb_1_proto protoreflect.FileDescriptor + +var file_internal_testpb_1_proto_rawDesc = []byte{ + 0x0a, 0x17, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, + 0x62, 0x2f, 0x31, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xa5, 0x05, 0x0a, 0x01, 0x41, 0x12, + 0x20, 0x0a, 0x04, 0x65, 0x6e, 0x75, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0c, 0x2e, + 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x04, 0x65, 0x6e, 0x75, + 0x6d, 0x12, 0x21, 0x0a, 0x0c, 0x73, 0x6f, 0x6d, 0x65, 0x5f, 0x62, 0x6f, 0x6f, 0x6c, 0x65, 0x61, + 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0b, 0x73, 0x6f, 0x6d, 0x65, 0x42, 0x6f, 0x6f, + 0x6c, 0x65, 0x61, 0x6e, 0x12, 0x14, 0x0a, 0x05, 0x49, 0x4e, 0x54, 0x33, 0x32, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x05, 0x52, 0x05, 0x49, 0x4e, 0x54, 0x33, 0x32, 0x12, 0x16, 0x0a, 0x06, 0x53, 0x49, + 0x4e, 0x54, 0x33, 0x32, 0x18, 0x04, 0x20, 0x01, 0x28, 0x11, 0x52, 0x06, 0x53, 0x49, 0x4e, 0x54, + 0x33, 0x32, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x49, 0x4e, 0x54, 0x33, 0x32, 0x18, 0x05, 0x20, 0x01, + 0x28, 0x0d, 0x52, 0x06, 0x55, 0x49, 0x4e, 0x54, 0x33, 0x32, 0x12, 0x14, 0x0a, 0x05, 0x49, 0x4e, + 0x54, 0x36, 0x34, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x49, 0x4e, 0x54, 0x36, 0x34, + 0x12, 0x16, 0x0a, 0x06, 0x53, 0x49, 0x4e, 0x47, 0x36, 0x34, 0x18, 0x07, 0x20, 0x01, 0x28, 0x12, + 0x52, 0x06, 0x53, 0x49, 0x4e, 0x47, 0x36, 0x34, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x49, 0x4e, 0x54, + 0x36, 0x34, 0x18, 0x08, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x55, 0x49, 0x4e, 0x54, 0x36, 0x34, + 0x12, 0x1a, 0x0a, 0x08, 0x53, 0x46, 0x49, 0x58, 0x45, 0x44, 0x33, 0x32, 0x18, 0x09, 0x20, 0x01, + 0x28, 0x0f, 0x52, 0x08, 0x53, 0x46, 0x49, 0x58, 0x45, 0x44, 0x33, 0x32, 0x12, 0x18, 0x0a, 0x07, + 0x46, 0x49, 0x58, 0x45, 0x44, 0x33, 0x32, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x07, 0x52, 0x07, 0x46, + 0x49, 0x58, 0x45, 0x44, 0x33, 0x32, 0x12, 0x14, 0x0a, 0x05, 0x46, 0x4c, 0x4f, 0x41, 0x54, 0x18, + 0x0b, 0x20, 0x01, 0x28, 0x02, 0x52, 0x05, 0x46, 0x4c, 0x4f, 0x41, 0x54, 0x12, 0x1a, 0x0a, 0x08, + 0x53, 0x46, 0x49, 0x58, 0x45, 0x44, 0x36, 0x34, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x10, 0x52, 0x08, + 0x53, 0x46, 0x49, 0x58, 0x45, 0x44, 0x36, 0x34, 0x12, 0x18, 0x0a, 0x07, 0x46, 0x49, 0x58, 0x45, + 0x44, 0x36, 0x34, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x06, 0x52, 0x07, 0x46, 0x49, 0x58, 0x45, 0x44, + 0x36, 0x34, 0x12, 0x16, 0x0a, 0x06, 0x44, 0x4f, 0x55, 0x42, 0x4c, 0x45, 0x18, 0x0e, 0x20, 0x01, + 0x28, 0x01, 0x52, 0x06, 0x44, 0x4f, 0x55, 0x42, 0x4c, 0x45, 0x12, 0x16, 0x0a, 0x06, 0x53, 0x54, + 0x52, 0x49, 0x4e, 0x47, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x53, 0x54, 0x52, 0x49, + 0x4e, 0x47, 0x12, 0x14, 0x0a, 0x05, 0x42, 0x59, 0x54, 0x45, 0x53, 0x18, 0x10, 0x20, 0x01, 0x28, + 0x0c, 0x52, 0x05, 0x42, 0x59, 0x54, 0x45, 0x53, 0x12, 0x1c, 0x0a, 0x07, 0x4d, 0x45, 0x53, 0x53, + 0x41, 0x47, 0x45, 0x18, 0x11, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x02, 0x2e, 0x42, 0x52, 0x07, 0x4d, + 0x45, 0x53, 0x53, 0x41, 0x47, 0x45, 0x12, 0x1d, 0x0a, 0x03, 0x4d, 0x41, 0x50, 0x18, 0x12, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x41, 0x2e, 0x4d, 0x41, 0x50, 0x45, 0x6e, 0x74, 0x72, 0x79, + 0x52, 0x03, 0x4d, 0x41, 0x50, 0x12, 0x16, 0x0a, 0x04, 0x4c, 0x49, 0x53, 0x54, 0x18, 0x13, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x02, 0x2e, 0x42, 0x52, 0x04, 0x4c, 0x49, 0x53, 0x54, 0x12, 0x1d, 0x0a, + 0x07, 0x4f, 0x4e, 0x45, 0x4f, 0x46, 0x5f, 0x42, 0x18, 0x14, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x02, + 0x2e, 0x42, 0x48, 0x00, 0x52, 0x06, 0x4f, 0x4e, 0x45, 0x4f, 0x46, 0x42, 0x12, 0x23, 0x0a, 0x0c, + 0x4f, 0x4e, 0x45, 0x4f, 0x46, 0x5f, 0x53, 0x54, 0x52, 0x49, 0x4e, 0x47, 0x18, 0x15, 0x20, 0x01, + 0x28, 0x09, 0x48, 0x00, 0x52, 0x0b, 0x4f, 0x4e, 0x45, 0x4f, 0x46, 0x53, 0x54, 0x52, 0x49, 0x4e, + 0x47, 0x12, 0x29, 0x0a, 0x09, 0x4c, 0x49, 0x53, 0x54, 0x5f, 0x45, 0x4e, 0x55, 0x4d, 0x18, 0x16, + 0x20, 0x03, 0x28, 0x0e, 0x32, 0x0c, 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x52, 0x08, 0x4c, 0x49, 0x53, 0x54, 0x45, 0x4e, 0x55, 0x4d, 0x1a, 0x3a, 0x0a, 0x08, + 0x4d, 0x41, 0x50, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x18, 0x0a, 0x05, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x02, 0x2e, 0x42, 0x52, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x07, 0x0a, 0x05, 0x4f, 0x4e, 0x45, 0x4f, + 0x46, 0x22, 0x11, 0x0a, 0x01, 0x42, 0x12, 0x0c, 0x0a, 0x01, 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x01, 0x78, 0x2a, 0x1f, 0x0a, 0x0b, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x12, 0x07, 0x0a, 0x03, 0x4f, 0x6e, 0x65, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, + 0x54, 0x77, 0x6f, 0x10, 0x01, 0x42, 0x30, 0x5a, 0x2e, 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, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, + 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( - file_testpb_1_proto_rawDescOnce sync.Once - file_testpb_1_proto_rawDescData = file_testpb_1_proto_rawDesc + file_internal_testpb_1_proto_rawDescOnce sync.Once + file_internal_testpb_1_proto_rawDescData = file_internal_testpb_1_proto_rawDesc ) -func file_testpb_1_proto_rawDescGZIP() []byte { - file_testpb_1_proto_rawDescOnce.Do(func() { - file_testpb_1_proto_rawDescData = protoimpl.X.CompressGZIP(file_testpb_1_proto_rawDescData) +func file_internal_testpb_1_proto_rawDescGZIP() []byte { + file_internal_testpb_1_proto_rawDescOnce.Do(func() { + file_internal_testpb_1_proto_rawDescData = protoimpl.X.CompressGZIP(file_internal_testpb_1_proto_rawDescData) }) - return file_testpb_1_proto_rawDescData + return file_internal_testpb_1_proto_rawDescData } -var file_testpb_1_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_testpb_1_proto_msgTypes = make([]protoimpl.MessageInfo, 3) -var file_testpb_1_proto_goTypes = []interface{}{ - (Enumeration)(0), // 0: Enumeration - (*A)(nil), // 1: A - (*B)(nil), // 2: B - nil, // 3: A.MAPEntry - (*descriptorpb.FileDescriptorProto)(nil), // 4: google.protobuf.FileDescriptorProto +var file_internal_testpb_1_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_internal_testpb_1_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_internal_testpb_1_proto_goTypes = []interface{}{ + (Enumeration)(0), // 0: Enumeration + (*A)(nil), // 1: A + (*B)(nil), // 2: B + nil, // 3: A.MAPEntry } -var file_testpb_1_proto_depIdxs = []int32{ +var file_internal_testpb_1_proto_depIdxs = []int32{ 0, // 0: A.enum:type_name -> Enumeration 2, // 1: A.MESSAGE:type_name -> B 3, // 2: A.MAP:type_name -> A.MAPEntry 2, // 3: A.LIST:type_name -> B 2, // 4: A.ONEOF_B:type_name -> B 0, // 5: A.LIST_ENUM:type_name -> Enumeration - 4, // 6: A.imported:type_name -> google.protobuf.FileDescriptorProto - 2, // 7: A.MAPEntry.value:type_name -> B - 8, // [8:8] is the sub-list for method output_type - 8, // [8:8] is the sub-list for method input_type - 8, // [8:8] is the sub-list for extension type_name - 8, // [8:8] is the sub-list for extension extendee - 0, // [0:8] is the sub-list for field type_name -} - -func init() { file_testpb_1_proto_init() } -func file_testpb_1_proto_init() { - if File_testpb_1_proto != nil { + 2, // 6: A.MAPEntry.value:type_name -> B + 7, // [7:7] is the sub-list for method output_type + 7, // [7:7] is the sub-list for method input_type + 7, // [7:7] is the sub-list for extension type_name + 7, // [7:7] is the sub-list for extension extendee + 0, // [0:7] is the sub-list for field type_name +} + +func init() { file_internal_testpb_1_proto_init() } +func file_internal_testpb_1_proto_init() { + if File_internal_testpb_1_proto != nil { return } if !protoimpl.UnsafeEnabled { - file_testpb_1_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_internal_testpb_1_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*A); i { case 0: return &v.state @@ -3013,7 +2915,7 @@ func file_testpb_1_proto_init() { return nil } } - file_testpb_1_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_internal_testpb_1_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*B); i { case 0: return &v.state @@ -3026,7 +2928,7 @@ func file_testpb_1_proto_init() { } } } - file_testpb_1_proto_msgTypes[0].OneofWrappers = []interface{}{ + file_internal_testpb_1_proto_msgTypes[0].OneofWrappers = []interface{}{ (*A_ONEOF_B)(nil), (*A_ONEOF_STRING)(nil), } @@ -3034,19 +2936,19 @@ func file_testpb_1_proto_init() { out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_testpb_1_proto_rawDesc, + RawDescriptor: file_internal_testpb_1_proto_rawDesc, NumEnums: 1, NumMessages: 3, NumExtensions: 0, NumServices: 0, }, - GoTypes: file_testpb_1_proto_goTypes, - DependencyIndexes: file_testpb_1_proto_depIdxs, - EnumInfos: file_testpb_1_proto_enumTypes, - MessageInfos: file_testpb_1_proto_msgTypes, + GoTypes: file_internal_testpb_1_proto_goTypes, + DependencyIndexes: file_internal_testpb_1_proto_depIdxs, + EnumInfos: file_internal_testpb_1_proto_enumTypes, + MessageInfos: file_internal_testpb_1_proto_msgTypes, }.Build() - File_testpb_1_proto = out.File - file_testpb_1_proto_rawDesc = nil - file_testpb_1_proto_goTypes = nil - file_testpb_1_proto_depIdxs = nil + File_internal_testpb_1_proto = out.File + file_internal_testpb_1_proto_rawDesc = nil + file_internal_testpb_1_proto_goTypes = nil + file_internal_testpb_1_proto_depIdxs = nil } diff --git a/testpb/clear_test.go b/internal/testpb/clear_test.go similarity index 100% rename from testpb/clear_test.go rename to internal/testpb/clear_test.go diff --git a/testpb/codec_test.go b/internal/testpb/codec_test.go similarity index 100% rename from testpb/codec_test.go rename to internal/testpb/codec_test.go diff --git a/testpb/get_test.go b/internal/testpb/get_test.go similarity index 100% rename from testpb/get_test.go rename to internal/testpb/get_test.go diff --git a/testpb/has_test.go b/internal/testpb/has_test.go similarity index 100% rename from testpb/has_test.go rename to internal/testpb/has_test.go diff --git a/testpb/list_bench_test.go b/internal/testpb/list_bench_test.go similarity index 100% rename from testpb/list_bench_test.go rename to internal/testpb/list_bench_test.go diff --git a/testpb/list_test.go b/internal/testpb/list_test.go similarity index 100% rename from testpb/list_test.go rename to internal/testpb/list_test.go diff --git a/testpb/map_bench_test.go b/internal/testpb/map_bench_test.go similarity index 100% rename from testpb/map_bench_test.go rename to internal/testpb/map_bench_test.go diff --git a/testpb/map_test.go b/internal/testpb/map_test.go similarity index 100% rename from testpb/map_test.go rename to internal/testpb/map_test.go diff --git a/testpb/mutable_test.go b/internal/testpb/mutable_test.go similarity index 100% rename from testpb/mutable_test.go rename to internal/testpb/mutable_test.go diff --git a/testpb/new_field_test.go b/internal/testpb/new_field_test.go similarity index 100% rename from testpb/new_field_test.go rename to internal/testpb/new_field_test.go diff --git a/testpb/proto_message_bench_test.go b/internal/testpb/proto_message_bench_test.go similarity index 100% rename from testpb/proto_message_bench_test.go rename to internal/testpb/proto_message_bench_test.go diff --git a/testpb/proto_methods_test.go b/internal/testpb/proto_methods_test.go similarity index 100% rename from testpb/proto_methods_test.go rename to internal/testpb/proto_methods_test.go diff --git a/testpb/range_test.go b/internal/testpb/range_test.go similarity index 100% rename from testpb/range_test.go rename to internal/testpb/range_test.go diff --git a/testpb/set_test.go b/internal/testpb/set_test.go similarity index 100% rename from testpb/set_test.go rename to internal/testpb/set_test.go diff --git a/testpb/type_bench_test.go b/internal/testpb/type_bench_test.go similarity index 100% rename from testpb/type_bench_test.go rename to internal/testpb/type_bench_test.go diff --git a/testpb/type_test.go b/internal/testpb/type_test.go similarity index 100% rename from testpb/type_test.go rename to internal/testpb/type_test.go diff --git a/testpb/whichoneof_test.go b/internal/testpb/whichoneof_test.go similarity index 100% rename from testpb/whichoneof_test.go rename to internal/testpb/whichoneof_test.go diff --git a/internal/testprotos/test3/test.pulsar.go b/internal/testprotos/test3/test.pulsar.go index a181a59..87d4b0f 100644 --- a/internal/testprotos/test3/test.pulsar.go +++ b/internal/testprotos/test3/test.pulsar.go @@ -11221,7 +11221,7 @@ func (x *fastReflection_ForeignMessage) ProtoMethods() *protoiface.Methods { // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.27.0 -// protoc v3.15.7 +// protoc v3.18.1 // source: internal/testprotos/test3/test.proto const ( diff --git a/internal/testprotos/test3/test_import.pulsar.go b/internal/testprotos/test3/test_import.pulsar.go index d8dc8f9..24509ce 100644 --- a/internal/testprotos/test3/test_import.pulsar.go +++ b/internal/testprotos/test3/test_import.pulsar.go @@ -374,7 +374,7 @@ func (x *fastReflection_ImportMessage) ProtoMethods() *protoiface.Methods { // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.27.0 -// protoc v3.15.7 +// protoc v3.18.1 // source: internal/testprotos/test3/test_import.proto const ( diff --git a/pulsarproto/ext.pb.go b/pulsarproto/ext.pb.go deleted file mode 100644 index ca9ab93..0000000 --- a/pulsarproto/ext.pb.go +++ /dev/null @@ -1,95 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.26.0 -// protoc v3.16.0 -// source: github.com/planetscale/vtprotobuf/vtproto/ext.proto - -package vtproto - -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_github_com_planetscale_vtprotobuf_vtproto_ext_proto_extTypes = []protoimpl.ExtensionInfo{ - { - ExtendedType: (*descriptorpb.MessageOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 64101, - Name: "vtproto.mempool", - Tag: "varint,64101,opt,name=mempool", - Filename: "github.com/planetscale/vtprotobuf/vtproto/ext.proto", - }, -} - -// Extension fields to descriptorpb.MessageOptions. -var ( - // optional bool mempool = 64101; - E_Mempool = &file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_extTypes[0] -) - -var File_github_com_planetscale_vtprotobuf_vtproto_ext_proto protoreflect.FileDescriptor - -var file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_rawDesc = []byte{ - 0x0a, 0x33, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x6c, 0x61, - 0x6e, 0x65, 0x74, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2f, 0x76, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x62, 0x75, 0x66, 0x2f, 0x76, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x65, 0x78, 0x74, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x76, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x20, - 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, - 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x3a, 0x3b, 0x0a, 0x07, 0x6d, 0x65, 0x6d, 0x70, 0x6f, 0x6f, 0x6c, 0x12, 0x1f, 0x2e, 0x67, 0x6f, - 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, - 0x73, 0x73, 0x61, 0x67, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xe5, 0xf4, 0x03, - 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x6d, 0x65, 0x6d, 0x70, 0x6f, 0x6f, 0x6c, 0x42, 0x49, 0x0a, - 0x13, 0x63, 0x6f, 0x6d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x62, 0x75, 0x66, 0x42, 0x07, 0x56, 0x54, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x5a, 0x29, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x6c, 0x61, 0x6e, 0x65, 0x74, - 0x73, 0x63, 0x61, 0x6c, 0x65, 0x2f, 0x76, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, - 0x2f, 0x76, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, -} - -var file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_goTypes = []interface{}{ - (*descriptorpb.MessageOptions)(nil), // 0: google.protobuf.MessageOptions -} -var file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_depIdxs = []int32{ - 0, // 0: vtproto.mempool:extendee -> google.protobuf.MessageOptions - 1, // [1:1] is the sub-list for method output_type - 1, // [1:1] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 0, // [0:1] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_init() } -func file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_init() { - if File_github_com_planetscale_vtprotobuf_vtproto_ext_proto != nil { - return - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_rawDesc, - NumEnums: 0, - NumMessages: 0, - NumExtensions: 1, - NumServices: 0, - }, - GoTypes: file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_goTypes, - DependencyIndexes: file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_depIdxs, - ExtensionInfos: file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_extTypes, - }.Build() - File_github_com_planetscale_vtprotobuf_vtproto_ext_proto = out.File - file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_rawDesc = nil - file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_goTypes = nil - file_github_com_planetscale_vtprotobuf_vtproto_ext_proto_depIdxs = nil -} \ No newline at end of file diff --git a/scripts/fastreflect.sh b/scripts/fastreflect.sh index b0bd8be..135c1e3 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=protoc+fast "$file" + protoc -I=. --plugin /usr/bin/protoc-gen-go-pulsar --go-pulsar_out=. --go-pulsar_opt=features=protoc+fast "$file" done }