From a2f8e612d700df49e6b88ec47cbcf8bbd6076149 Mon Sep 17 00:00:00 2001 From: Arvind Bright Date: Tue, 16 Apr 2024 16:56:07 -0700 Subject: [PATCH] cmd/protoc-gen-go-grpc: reuse route_guide_grpc.pb.go as golden file (#7134) --- .../protoc-gen-go-grpc_test.sh | 12 +- cmd/protoc-gen-go-grpc/testdata/golden.pb.go | 249 ------------- cmd/protoc-gen-go-grpc/testdata/golden.proto | 38 -- .../testdata/golden_grpc.pb.go | 341 ------------------ 4 files changed, 7 insertions(+), 633 deletions(-) delete mode 100644 cmd/protoc-gen-go-grpc/testdata/golden.pb.go delete mode 100644 cmd/protoc-gen-go-grpc/testdata/golden.proto delete mode 100644 cmd/protoc-gen-go-grpc/testdata/golden_grpc.pb.go diff --git a/cmd/protoc-gen-go-grpc/protoc-gen-go-grpc_test.sh b/cmd/protoc-gen-go-grpc/protoc-gen-go-grpc_test.sh index e60ddcdfd7b..451f5f902f1 100755 --- a/cmd/protoc-gen-go-grpc/protoc-gen-go-grpc_test.sh +++ b/cmd/protoc-gen-go-grpc/protoc-gen-go-grpc_test.sh @@ -31,14 +31,16 @@ popd protoc \ --go-grpc_out="${TEMPDIR}" \ --go-grpc_opt=paths=source_relative \ - "$WORKDIR/testdata/golden.proto" + "examples/route_guide/routeguide/route_guide.proto" -GOLDENFILE="${WORKDIR}/testdata/golden_grpc.pb.go" -GENFILE="${TEMPDIR}/cmd/protoc-gen-go-grpc/testdata/golden_grpc.pb.go" +GOLDENFILE="examples/route_guide/routeguide/route_guide_grpc.pb.go" +GENFILE="${TEMPDIR}/examples/route_guide/routeguide/route_guide_grpc.pb.go" -DIFF=$(diff "${GOLDENFILE}" "${GENFILE}") +# diff is piped to [[ $? == 1 ]] to avoid exiting on diff but exit on error +# (like if the file was not found). See man diff for more info. +DIFF=$(diff "${GOLDENFILE}" "${GENFILE}" || [[ $? == 1 ]]) if [[ -n "${DIFF}" ]]; then - echo -e "ERROR: Generated file golden_grpc.pb.go differs from golden file:\n${DIFF}" + echo -e "ERROR: Generated file differs from golden file:\n${DIFF}" echo -e "If you have made recent changes to protoc-gen-go-grpc," \ "please regenerate the golden files by running:" \ "\n\t go generate google.golang.org/grpc/..." >&2 diff --git a/cmd/protoc-gen-go-grpc/testdata/golden.pb.go b/cmd/protoc-gen-go-grpc/testdata/golden.pb.go deleted file mode 100644 index 5f146ab4999..00000000000 --- a/cmd/protoc-gen-go-grpc/testdata/golden.pb.go +++ /dev/null @@ -1,249 +0,0 @@ -// Copyright 2024 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. - -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.33.0 -// protoc v4.25.2 -// source: cmd/protoc-gen-go-grpc/testdata/golden.proto - -package testdata - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type EventRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Content []byte `protobuf:"bytes,1,opt,name=content,proto3" json:"content,omitempty"` -} - -func (x *EventRequest) Reset() { - *x = EventRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_cmd_protoc_gen_go_grpc_testdata_golden_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *EventRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*EventRequest) ProtoMessage() {} - -func (x *EventRequest) ProtoReflect() protoreflect.Message { - mi := &file_cmd_protoc_gen_go_grpc_testdata_golden_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use EventRequest.ProtoReflect.Descriptor instead. -func (*EventRequest) Descriptor() ([]byte, []int) { - return file_cmd_protoc_gen_go_grpc_testdata_golden_proto_rawDescGZIP(), []int{0} -} - -func (x *EventRequest) GetContent() []byte { - if x != nil { - return x.Content - } - return nil -} - -type EventResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Content []byte `protobuf:"bytes,1,opt,name=content,proto3" json:"content,omitempty"` -} - -func (x *EventResponse) Reset() { - *x = EventResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_cmd_protoc_gen_go_grpc_testdata_golden_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *EventResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*EventResponse) ProtoMessage() {} - -func (x *EventResponse) ProtoReflect() protoreflect.Message { - mi := &file_cmd_protoc_gen_go_grpc_testdata_golden_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use EventResponse.ProtoReflect.Descriptor instead. -func (*EventResponse) Descriptor() ([]byte, []int) { - return file_cmd_protoc_gen_go_grpc_testdata_golden_proto_rawDescGZIP(), []int{1} -} - -func (x *EventResponse) GetContent() []byte { - if x != nil { - return x.Content - } - return nil -} - -var File_cmd_protoc_gen_go_grpc_testdata_golden_proto protoreflect.FileDescriptor - -var file_cmd_protoc_gen_go_grpc_testdata_golden_proto_rawDesc = []byte{ - 0x0a, 0x2c, 0x63, 0x6d, 0x64, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x2d, 0x67, 0x65, 0x6e, - 0x2d, 0x67, 0x6f, 0x2d, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x64, 0x61, 0x74, - 0x61, 0x2f, 0x67, 0x6f, 0x6c, 0x64, 0x65, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, - 0x6d, 0x61, 0x69, 0x6e, 0x22, 0x28, 0x0a, 0x0c, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x22, 0x29, - 0x0a, 0x0d, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, - 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, - 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x32, 0x99, 0x02, 0x0a, 0x1d, 0x42, 0x69, - 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x53, 0x74, 0x72, 0x65, 0x61, - 0x6d, 0x69, 0x6e, 0x67, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x38, 0x0a, 0x0b, 0x55, - 0x6e, 0x61, 0x72, 0x79, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x12, 0x2e, 0x6d, 0x61, 0x69, - 0x6e, 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, - 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3b, 0x0a, 0x0c, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x4d, - 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x12, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x45, 0x76, 0x65, - 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x6d, 0x61, 0x69, 0x6e, - 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, - 0x28, 0x01, 0x12, 0x3b, 0x0a, 0x0c, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x4d, 0x65, 0x74, 0x68, - 0x6f, 0x64, 0x12, 0x12, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x45, 0x76, - 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x30, 0x01, 0x12, - 0x44, 0x0a, 0x13, 0x42, 0x69, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, - 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x12, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x45, 0x76, - 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x6d, 0x61, 0x69, - 0x6e, 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, - 0x00, 0x28, 0x01, 0x30, 0x01, 0x42, 0x38, 0x5a, 0x36, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, - 0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2f, - 0x63, 0x6d, 0x64, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x2d, 0x67, 0x65, 0x6e, 0x2d, 0x67, - 0x6f, 0x2d, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x64, 0x61, 0x74, 0x61, 0x62, - 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_cmd_protoc_gen_go_grpc_testdata_golden_proto_rawDescOnce sync.Once - file_cmd_protoc_gen_go_grpc_testdata_golden_proto_rawDescData = file_cmd_protoc_gen_go_grpc_testdata_golden_proto_rawDesc -) - -func file_cmd_protoc_gen_go_grpc_testdata_golden_proto_rawDescGZIP() []byte { - file_cmd_protoc_gen_go_grpc_testdata_golden_proto_rawDescOnce.Do(func() { - file_cmd_protoc_gen_go_grpc_testdata_golden_proto_rawDescData = protoimpl.X.CompressGZIP(file_cmd_protoc_gen_go_grpc_testdata_golden_proto_rawDescData) - }) - return file_cmd_protoc_gen_go_grpc_testdata_golden_proto_rawDescData -} - -var file_cmd_protoc_gen_go_grpc_testdata_golden_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_cmd_protoc_gen_go_grpc_testdata_golden_proto_goTypes = []interface{}{ - (*EventRequest)(nil), // 0: main.EventRequest - (*EventResponse)(nil), // 1: main.EventResponse -} -var file_cmd_protoc_gen_go_grpc_testdata_golden_proto_depIdxs = []int32{ - 0, // 0: main.BidirectionalStreamingService.UnaryMethod:input_type -> main.EventRequest - 0, // 1: main.BidirectionalStreamingService.ClientMethod:input_type -> main.EventRequest - 0, // 2: main.BidirectionalStreamingService.ServerMethod:input_type -> main.EventRequest - 0, // 3: main.BidirectionalStreamingService.BidirectionalMethod:input_type -> main.EventRequest - 1, // 4: main.BidirectionalStreamingService.UnaryMethod:output_type -> main.EventResponse - 1, // 5: main.BidirectionalStreamingService.ClientMethod:output_type -> main.EventResponse - 1, // 6: main.BidirectionalStreamingService.ServerMethod:output_type -> main.EventResponse - 1, // 7: main.BidirectionalStreamingService.BidirectionalMethod:output_type -> main.EventResponse - 4, // [4:8] is the sub-list for method output_type - 0, // [0:4] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_cmd_protoc_gen_go_grpc_testdata_golden_proto_init() } -func file_cmd_protoc_gen_go_grpc_testdata_golden_proto_init() { - if File_cmd_protoc_gen_go_grpc_testdata_golden_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_cmd_protoc_gen_go_grpc_testdata_golden_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*EventRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_cmd_protoc_gen_go_grpc_testdata_golden_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*EventResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_cmd_protoc_gen_go_grpc_testdata_golden_proto_rawDesc, - NumEnums: 0, - NumMessages: 2, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_cmd_protoc_gen_go_grpc_testdata_golden_proto_goTypes, - DependencyIndexes: file_cmd_protoc_gen_go_grpc_testdata_golden_proto_depIdxs, - MessageInfos: file_cmd_protoc_gen_go_grpc_testdata_golden_proto_msgTypes, - }.Build() - File_cmd_protoc_gen_go_grpc_testdata_golden_proto = out.File - file_cmd_protoc_gen_go_grpc_testdata_golden_proto_rawDesc = nil - file_cmd_protoc_gen_go_grpc_testdata_golden_proto_goTypes = nil - file_cmd_protoc_gen_go_grpc_testdata_golden_proto_depIdxs = nil -} diff --git a/cmd/protoc-gen-go-grpc/testdata/golden.proto b/cmd/protoc-gen-go-grpc/testdata/golden.proto deleted file mode 100644 index 1aff384571b..00000000000 --- a/cmd/protoc-gen-go-grpc/testdata/golden.proto +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2024 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. - -syntax = "proto3"; - -option go_package = "google.golang.org/grpc/cmd/protoc-gen-go-grpc/testdata"; - -package main; - -message EventRequest { - bytes content = 1; -} - -message EventResponse { - bytes content = 1; -} - -service BidirectionalStreamingService { - // UnaryMethod is a sample unary method. - rpc UnaryMethod(EventRequest) returns (EventResponse) {} - // ClientMethod is a sample client streaming method. - rpc ClientMethod(stream EventRequest) returns (EventResponse) {} - // ServerMethod is a sample server streaming method. - rpc ServerMethod(EventRequest) returns (stream EventResponse) {} - // BidirectionalMethod is a sample bidirectional streaming method. - rpc BidirectionalMethod(stream EventRequest) returns (stream EventResponse) {} -} diff --git a/cmd/protoc-gen-go-grpc/testdata/golden_grpc.pb.go b/cmd/protoc-gen-go-grpc/testdata/golden_grpc.pb.go deleted file mode 100644 index 2d599a1d437..00000000000 --- a/cmd/protoc-gen-go-grpc/testdata/golden_grpc.pb.go +++ /dev/null @@ -1,341 +0,0 @@ -// Copyright 2024 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. - -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. -// versions: -// - protoc-gen-go-grpc v1.3.0 -// - protoc v4.25.2 -// source: cmd/protoc-gen-go-grpc/testdata/golden.proto - -package testdata - -import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.62.0 or later. -const _ = grpc.SupportPackageIsVersion8 - -const ( - BidirectionalStreamingService_UnaryMethod_FullMethodName = "/main.BidirectionalStreamingService/UnaryMethod" - BidirectionalStreamingService_ClientMethod_FullMethodName = "/main.BidirectionalStreamingService/ClientMethod" - BidirectionalStreamingService_ServerMethod_FullMethodName = "/main.BidirectionalStreamingService/ServerMethod" - BidirectionalStreamingService_BidirectionalMethod_FullMethodName = "/main.BidirectionalStreamingService/BidirectionalMethod" -) - -// BidirectionalStreamingServiceClient is the client API for BidirectionalStreamingService service. -// -// 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. -type BidirectionalStreamingServiceClient interface { - // UnaryMethod is a sample unary method. - UnaryMethod(ctx context.Context, in *EventRequest, opts ...grpc.CallOption) (*EventResponse, error) - // ClientMethod is a sample client streaming method. - ClientMethod(ctx context.Context, opts ...grpc.CallOption) (BidirectionalStreamingService_ClientMethodClient, error) - // ServerMethod is a sample server streaming method. - ServerMethod(ctx context.Context, in *EventRequest, opts ...grpc.CallOption) (BidirectionalStreamingService_ServerMethodClient, error) - // BidirectionalMethod is a sample bidirectional streaming method. - BidirectionalMethod(ctx context.Context, opts ...grpc.CallOption) (BidirectionalStreamingService_BidirectionalMethodClient, error) -} - -type bidirectionalStreamingServiceClient struct { - cc grpc.ClientConnInterface -} - -func NewBidirectionalStreamingServiceClient(cc grpc.ClientConnInterface) BidirectionalStreamingServiceClient { - return &bidirectionalStreamingServiceClient{cc} -} - -func (c *bidirectionalStreamingServiceClient) UnaryMethod(ctx context.Context, in *EventRequest, opts ...grpc.CallOption) (*EventResponse, error) { - cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(EventResponse) - err := c.cc.Invoke(ctx, BidirectionalStreamingService_UnaryMethod_FullMethodName, in, out, cOpts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *bidirectionalStreamingServiceClient) ClientMethod(ctx context.Context, opts ...grpc.CallOption) (BidirectionalStreamingService_ClientMethodClient, error) { - cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - stream, err := c.cc.NewStream(ctx, &BidirectionalStreamingService_ServiceDesc.Streams[0], BidirectionalStreamingService_ClientMethod_FullMethodName, cOpts...) - if err != nil { - return nil, err - } - x := &bidirectionalStreamingServiceClientMethodClient{stream} - return x, nil -} - -type BidirectionalStreamingService_ClientMethodClient interface { - Send(*EventRequest) error - CloseAndRecv() (*EventResponse, error) - grpc.ClientStream -} - -type bidirectionalStreamingServiceClientMethodClient struct { - grpc.ClientStream -} - -func (x *bidirectionalStreamingServiceClientMethodClient) Send(m *EventRequest) error { - return x.ClientStream.SendMsg(m) -} - -func (x *bidirectionalStreamingServiceClientMethodClient) CloseAndRecv() (*EventResponse, error) { - if err := x.ClientStream.CloseSend(); err != nil { - return nil, err - } - m := new(EventResponse) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func (c *bidirectionalStreamingServiceClient) ServerMethod(ctx context.Context, in *EventRequest, opts ...grpc.CallOption) (BidirectionalStreamingService_ServerMethodClient, error) { - cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - stream, err := c.cc.NewStream(ctx, &BidirectionalStreamingService_ServiceDesc.Streams[1], BidirectionalStreamingService_ServerMethod_FullMethodName, cOpts...) - if err != nil { - return nil, err - } - x := &bidirectionalStreamingServiceServerMethodClient{stream} - if err := x.ClientStream.SendMsg(in); err != nil { - return nil, err - } - if err := x.ClientStream.CloseSend(); err != nil { - return nil, err - } - return x, nil -} - -type BidirectionalStreamingService_ServerMethodClient interface { - Recv() (*EventResponse, error) - grpc.ClientStream -} - -type bidirectionalStreamingServiceServerMethodClient struct { - grpc.ClientStream -} - -func (x *bidirectionalStreamingServiceServerMethodClient) Recv() (*EventResponse, error) { - m := new(EventResponse) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func (c *bidirectionalStreamingServiceClient) BidirectionalMethod(ctx context.Context, opts ...grpc.CallOption) (BidirectionalStreamingService_BidirectionalMethodClient, error) { - cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - stream, err := c.cc.NewStream(ctx, &BidirectionalStreamingService_ServiceDesc.Streams[2], BidirectionalStreamingService_BidirectionalMethod_FullMethodName, cOpts...) - if err != nil { - return nil, err - } - x := &bidirectionalStreamingServiceBidirectionalMethodClient{stream} - return x, nil -} - -type BidirectionalStreamingService_BidirectionalMethodClient interface { - Send(*EventRequest) error - Recv() (*EventResponse, error) - grpc.ClientStream -} - -type bidirectionalStreamingServiceBidirectionalMethodClient struct { - grpc.ClientStream -} - -func (x *bidirectionalStreamingServiceBidirectionalMethodClient) Send(m *EventRequest) error { - return x.ClientStream.SendMsg(m) -} - -func (x *bidirectionalStreamingServiceBidirectionalMethodClient) Recv() (*EventResponse, error) { - m := new(EventResponse) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -// BidirectionalStreamingServiceServer is the server API for BidirectionalStreamingService service. -// All implementations must embed UnimplementedBidirectionalStreamingServiceServer -// for forward compatibility -type BidirectionalStreamingServiceServer interface { - // UnaryMethod is a sample unary method. - UnaryMethod(context.Context, *EventRequest) (*EventResponse, error) - // ClientMethod is a sample client streaming method. - ClientMethod(BidirectionalStreamingService_ClientMethodServer) error - // ServerMethod is a sample server streaming method. - ServerMethod(*EventRequest, BidirectionalStreamingService_ServerMethodServer) error - // BidirectionalMethod is a sample bidirectional streaming method. - BidirectionalMethod(BidirectionalStreamingService_BidirectionalMethodServer) error - mustEmbedUnimplementedBidirectionalStreamingServiceServer() -} - -// UnimplementedBidirectionalStreamingServiceServer must be embedded to have forward compatible implementations. -type UnimplementedBidirectionalStreamingServiceServer struct { -} - -func (UnimplementedBidirectionalStreamingServiceServer) UnaryMethod(context.Context, *EventRequest) (*EventResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method UnaryMethod not implemented") -} -func (UnimplementedBidirectionalStreamingServiceServer) ClientMethod(BidirectionalStreamingService_ClientMethodServer) error { - return status.Errorf(codes.Unimplemented, "method ClientMethod not implemented") -} -func (UnimplementedBidirectionalStreamingServiceServer) ServerMethod(*EventRequest, BidirectionalStreamingService_ServerMethodServer) error { - return status.Errorf(codes.Unimplemented, "method ServerMethod not implemented") -} -func (UnimplementedBidirectionalStreamingServiceServer) BidirectionalMethod(BidirectionalStreamingService_BidirectionalMethodServer) error { - return status.Errorf(codes.Unimplemented, "method BidirectionalMethod not implemented") -} -func (UnimplementedBidirectionalStreamingServiceServer) mustEmbedUnimplementedBidirectionalStreamingServiceServer() { -} - -// UnsafeBidirectionalStreamingServiceServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to BidirectionalStreamingServiceServer will -// result in compilation errors. -type UnsafeBidirectionalStreamingServiceServer interface { - mustEmbedUnimplementedBidirectionalStreamingServiceServer() -} - -func RegisterBidirectionalStreamingServiceServer(s grpc.ServiceRegistrar, srv BidirectionalStreamingServiceServer) { - s.RegisterService(&BidirectionalStreamingService_ServiceDesc, srv) -} - -func _BidirectionalStreamingService_UnaryMethod_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(EventRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(BidirectionalStreamingServiceServer).UnaryMethod(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: BidirectionalStreamingService_UnaryMethod_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(BidirectionalStreamingServiceServer).UnaryMethod(ctx, req.(*EventRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _BidirectionalStreamingService_ClientMethod_Handler(srv interface{}, stream grpc.ServerStream) error { - return srv.(BidirectionalStreamingServiceServer).ClientMethod(&bidirectionalStreamingServiceClientMethodServer{stream}) -} - -type BidirectionalStreamingService_ClientMethodServer interface { - SendAndClose(*EventResponse) error - Recv() (*EventRequest, error) - grpc.ServerStream -} - -type bidirectionalStreamingServiceClientMethodServer struct { - grpc.ServerStream -} - -func (x *bidirectionalStreamingServiceClientMethodServer) SendAndClose(m *EventResponse) error { - return x.ServerStream.SendMsg(m) -} - -func (x *bidirectionalStreamingServiceClientMethodServer) Recv() (*EventRequest, error) { - m := new(EventRequest) - if err := x.ServerStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func _BidirectionalStreamingService_ServerMethod_Handler(srv interface{}, stream grpc.ServerStream) error { - m := new(EventRequest) - if err := stream.RecvMsg(m); err != nil { - return err - } - return srv.(BidirectionalStreamingServiceServer).ServerMethod(m, &bidirectionalStreamingServiceServerMethodServer{stream}) -} - -type BidirectionalStreamingService_ServerMethodServer interface { - Send(*EventResponse) error - grpc.ServerStream -} - -type bidirectionalStreamingServiceServerMethodServer struct { - grpc.ServerStream -} - -func (x *bidirectionalStreamingServiceServerMethodServer) Send(m *EventResponse) error { - return x.ServerStream.SendMsg(m) -} - -func _BidirectionalStreamingService_BidirectionalMethod_Handler(srv interface{}, stream grpc.ServerStream) error { - return srv.(BidirectionalStreamingServiceServer).BidirectionalMethod(&bidirectionalStreamingServiceBidirectionalMethodServer{stream}) -} - -type BidirectionalStreamingService_BidirectionalMethodServer interface { - Send(*EventResponse) error - Recv() (*EventRequest, error) - grpc.ServerStream -} - -type bidirectionalStreamingServiceBidirectionalMethodServer struct { - grpc.ServerStream -} - -func (x *bidirectionalStreamingServiceBidirectionalMethodServer) Send(m *EventResponse) error { - return x.ServerStream.SendMsg(m) -} - -func (x *bidirectionalStreamingServiceBidirectionalMethodServer) Recv() (*EventRequest, error) { - m := new(EventRequest) - if err := x.ServerStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -// BidirectionalStreamingService_ServiceDesc is the grpc.ServiceDesc for BidirectionalStreamingService service. -// It's only intended for direct use with grpc.RegisterService, -// and not to be introspected or modified (even as a copy) -var BidirectionalStreamingService_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "main.BidirectionalStreamingService", - HandlerType: (*BidirectionalStreamingServiceServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "UnaryMethod", - Handler: _BidirectionalStreamingService_UnaryMethod_Handler, - }, - }, - Streams: []grpc.StreamDesc{ - { - StreamName: "ClientMethod", - Handler: _BidirectionalStreamingService_ClientMethod_Handler, - ClientStreams: true, - }, - { - StreamName: "ServerMethod", - Handler: _BidirectionalStreamingService_ServerMethod_Handler, - ServerStreams: true, - }, - { - StreamName: "BidirectionalMethod", - Handler: _BidirectionalStreamingService_BidirectionalMethod_Handler, - ServerStreams: true, - ClientStreams: true, - }, - }, - Metadata: "cmd/protoc-gen-go-grpc/testdata/golden.proto", -}