diff --git a/examples/features/proto/doc.go b/examples/features/proto/doc.go new file mode 100644 index 000000000000..1400e63baa36 --- /dev/null +++ b/examples/features/proto/doc.go @@ -0,0 +1,22 @@ +/* + * + * Copyright 2018 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. + * + */ + +//go:generate protoc -I ./echo --go_out=plugins=grpc,paths=source_relative:./echo ./echo/echo.proto + +// Package proto is for go generate. +package proto diff --git a/examples/features/proto/echo/echo.pb.go b/examples/features/proto/echo/echo.pb.go new file mode 100644 index 000000000000..3536d0279003 --- /dev/null +++ b/examples/features/proto/echo/echo.pb.go @@ -0,0 +1,391 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: echo.proto + +package echo // import "google.golang.org/grpc/examples/features/proto/echo" + +import proto "github.com/golang/protobuf/proto" +import fmt "fmt" +import math "math" + +import ( + context "golang.org/x/net/context" + grpc "google.golang.org/grpc" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package + +type EchoRequest struct { + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *EchoRequest) Reset() { *m = EchoRequest{} } +func (m *EchoRequest) String() string { return proto.CompactTextString(m) } +func (*EchoRequest) ProtoMessage() {} +func (*EchoRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_echo_1650ab141b9ec5a9, []int{0} +} +func (m *EchoRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_EchoRequest.Unmarshal(m, b) +} +func (m *EchoRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_EchoRequest.Marshal(b, m, deterministic) +} +func (dst *EchoRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_EchoRequest.Merge(dst, src) +} +func (m *EchoRequest) XXX_Size() int { + return xxx_messageInfo_EchoRequest.Size(m) +} +func (m *EchoRequest) XXX_DiscardUnknown() { + xxx_messageInfo_EchoRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_EchoRequest proto.InternalMessageInfo + +func (m *EchoRequest) GetMessage() string { + if m != nil { + return m.Message + } + return "" +} + +type EchoResponse struct { + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *EchoResponse) Reset() { *m = EchoResponse{} } +func (m *EchoResponse) String() string { return proto.CompactTextString(m) } +func (*EchoResponse) ProtoMessage() {} +func (*EchoResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_echo_1650ab141b9ec5a9, []int{1} +} +func (m *EchoResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_EchoResponse.Unmarshal(m, b) +} +func (m *EchoResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_EchoResponse.Marshal(b, m, deterministic) +} +func (dst *EchoResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_EchoResponse.Merge(dst, src) +} +func (m *EchoResponse) XXX_Size() int { + return xxx_messageInfo_EchoResponse.Size(m) +} +func (m *EchoResponse) XXX_DiscardUnknown() { + xxx_messageInfo_EchoResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_EchoResponse proto.InternalMessageInfo + +func (m *EchoResponse) GetMessage() string { + if m != nil { + return m.Message + } + return "" +} + +func init() { + proto.RegisterType((*EchoRequest)(nil), "grpc.examples.echo.EchoRequest") + proto.RegisterType((*EchoResponse)(nil), "grpc.examples.echo.EchoResponse") +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// EchoClient is the client API for Echo service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type EchoClient interface { + UnaryEcho(ctx context.Context, in *EchoRequest, opts ...grpc.CallOption) (*EchoResponse, error) + ServerStreamingEcho(ctx context.Context, in *EchoRequest, opts ...grpc.CallOption) (Echo_ServerStreamingEchoClient, error) + ClientStreamingEcho(ctx context.Context, opts ...grpc.CallOption) (Echo_ClientStreamingEchoClient, error) + BidirectionalStreamingEcho(ctx context.Context, opts ...grpc.CallOption) (Echo_BidirectionalStreamingEchoClient, error) +} + +type echoClient struct { + cc *grpc.ClientConn +} + +func NewEchoClient(cc *grpc.ClientConn) EchoClient { + return &echoClient{cc} +} + +func (c *echoClient) UnaryEcho(ctx context.Context, in *EchoRequest, opts ...grpc.CallOption) (*EchoResponse, error) { + out := new(EchoResponse) + err := c.cc.Invoke(ctx, "/grpc.examples.echo.Echo/UnaryEcho", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *echoClient) ServerStreamingEcho(ctx context.Context, in *EchoRequest, opts ...grpc.CallOption) (Echo_ServerStreamingEchoClient, error) { + stream, err := c.cc.NewStream(ctx, &_Echo_serviceDesc.Streams[0], "/grpc.examples.echo.Echo/ServerStreamingEcho", opts...) + if err != nil { + return nil, err + } + x := &echoServerStreamingEchoClient{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 Echo_ServerStreamingEchoClient interface { + Recv() (*EchoResponse, error) + grpc.ClientStream +} + +type echoServerStreamingEchoClient struct { + grpc.ClientStream +} + +func (x *echoServerStreamingEchoClient) Recv() (*EchoResponse, error) { + m := new(EchoResponse) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +func (c *echoClient) ClientStreamingEcho(ctx context.Context, opts ...grpc.CallOption) (Echo_ClientStreamingEchoClient, error) { + stream, err := c.cc.NewStream(ctx, &_Echo_serviceDesc.Streams[1], "/grpc.examples.echo.Echo/ClientStreamingEcho", opts...) + if err != nil { + return nil, err + } + x := &echoClientStreamingEchoClient{stream} + return x, nil +} + +type Echo_ClientStreamingEchoClient interface { + Send(*EchoRequest) error + CloseAndRecv() (*EchoResponse, error) + grpc.ClientStream +} + +type echoClientStreamingEchoClient struct { + grpc.ClientStream +} + +func (x *echoClientStreamingEchoClient) Send(m *EchoRequest) error { + return x.ClientStream.SendMsg(m) +} + +func (x *echoClientStreamingEchoClient) CloseAndRecv() (*EchoResponse, error) { + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + m := new(EchoResponse) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +func (c *echoClient) BidirectionalStreamingEcho(ctx context.Context, opts ...grpc.CallOption) (Echo_BidirectionalStreamingEchoClient, error) { + stream, err := c.cc.NewStream(ctx, &_Echo_serviceDesc.Streams[2], "/grpc.examples.echo.Echo/BidirectionalStreamingEcho", opts...) + if err != nil { + return nil, err + } + x := &echoBidirectionalStreamingEchoClient{stream} + return x, nil +} + +type Echo_BidirectionalStreamingEchoClient interface { + Send(*EchoRequest) error + Recv() (*EchoResponse, error) + grpc.ClientStream +} + +type echoBidirectionalStreamingEchoClient struct { + grpc.ClientStream +} + +func (x *echoBidirectionalStreamingEchoClient) Send(m *EchoRequest) error { + return x.ClientStream.SendMsg(m) +} + +func (x *echoBidirectionalStreamingEchoClient) Recv() (*EchoResponse, error) { + m := new(EchoResponse) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +// EchoServer is the server API for Echo service. +type EchoServer interface { + UnaryEcho(context.Context, *EchoRequest) (*EchoResponse, error) + ServerStreamingEcho(*EchoRequest, Echo_ServerStreamingEchoServer) error + ClientStreamingEcho(Echo_ClientStreamingEchoServer) error + BidirectionalStreamingEcho(Echo_BidirectionalStreamingEchoServer) error +} + +func RegisterEchoServer(s *grpc.Server, srv EchoServer) { + s.RegisterService(&_Echo_serviceDesc, srv) +} + +func _Echo_UnaryEcho_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(EchoRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(EchoServer).UnaryEcho(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/grpc.examples.echo.Echo/UnaryEcho", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(EchoServer).UnaryEcho(ctx, req.(*EchoRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Echo_ServerStreamingEcho_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(EchoRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(EchoServer).ServerStreamingEcho(m, &echoServerStreamingEchoServer{stream}) +} + +type Echo_ServerStreamingEchoServer interface { + Send(*EchoResponse) error + grpc.ServerStream +} + +type echoServerStreamingEchoServer struct { + grpc.ServerStream +} + +func (x *echoServerStreamingEchoServer) Send(m *EchoResponse) error { + return x.ServerStream.SendMsg(m) +} + +func _Echo_ClientStreamingEcho_Handler(srv interface{}, stream grpc.ServerStream) error { + return srv.(EchoServer).ClientStreamingEcho(&echoClientStreamingEchoServer{stream}) +} + +type Echo_ClientStreamingEchoServer interface { + SendAndClose(*EchoResponse) error + Recv() (*EchoRequest, error) + grpc.ServerStream +} + +type echoClientStreamingEchoServer struct { + grpc.ServerStream +} + +func (x *echoClientStreamingEchoServer) SendAndClose(m *EchoResponse) error { + return x.ServerStream.SendMsg(m) +} + +func (x *echoClientStreamingEchoServer) Recv() (*EchoRequest, error) { + m := new(EchoRequest) + if err := x.ServerStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +func _Echo_BidirectionalStreamingEcho_Handler(srv interface{}, stream grpc.ServerStream) error { + return srv.(EchoServer).BidirectionalStreamingEcho(&echoBidirectionalStreamingEchoServer{stream}) +} + +type Echo_BidirectionalStreamingEchoServer interface { + Send(*EchoResponse) error + Recv() (*EchoRequest, error) + grpc.ServerStream +} + +type echoBidirectionalStreamingEchoServer struct { + grpc.ServerStream +} + +func (x *echoBidirectionalStreamingEchoServer) Send(m *EchoResponse) error { + return x.ServerStream.SendMsg(m) +} + +func (x *echoBidirectionalStreamingEchoServer) Recv() (*EchoRequest, error) { + m := new(EchoRequest) + if err := x.ServerStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +var _Echo_serviceDesc = grpc.ServiceDesc{ + ServiceName: "grpc.examples.echo.Echo", + HandlerType: (*EchoServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "UnaryEcho", + Handler: _Echo_UnaryEcho_Handler, + }, + }, + Streams: []grpc.StreamDesc{ + { + StreamName: "ServerStreamingEcho", + Handler: _Echo_ServerStreamingEcho_Handler, + ServerStreams: true, + }, + { + StreamName: "ClientStreamingEcho", + Handler: _Echo_ClientStreamingEcho_Handler, + ClientStreams: true, + }, + { + StreamName: "BidirectionalStreamingEcho", + Handler: _Echo_BidirectionalStreamingEcho_Handler, + ServerStreams: true, + ClientStreams: true, + }, + }, + Metadata: "echo.proto", +} + +func init() { proto.RegisterFile("echo.proto", fileDescriptor_echo_1650ab141b9ec5a9) } + +var fileDescriptor_echo_1650ab141b9ec5a9 = []byte{ + // 234 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x92, 0xb1, 0x4b, 0x03, 0x31, + 0x14, 0x87, 0x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xa6, 0xac, 0x9a, 0xdd, 0xaa, 0x79, 0x83, 0xcd, + 0x1b, 0x41, 0x32, 0xc3, 0x59, 0x98, 0x62, 0x7a, 0x39, 0x1d, 0xde, 0xf3, 0x9f, 0x00, 0x00, 0x00, + 0xff, 0xff, 0x23, 0x14, 0x26, 0x96, 0x30, 0x02, 0x00, 0x00, +} diff --git a/examples/features/proto/echo/echo.proto b/examples/features/proto/echo/echo.proto new file mode 100644 index 000000000000..44d2356d1707 --- /dev/null +++ b/examples/features/proto/echo/echo.proto @@ -0,0 +1,38 @@ +/* + * + * Copyright 2018 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"; + +package grpc.examples.echo; + +option go_package = "google.golang.org/grpc/examples/features/proto/echo"; + +message EchoRequest { + string message = 1; +} + +message EchoResponse { + string message = 1; +} + +service Echo { + rpc UnaryEcho(EchoRequest) returns (EchoResponse) {} + rpc ServerStreamingEcho(EchoRequest) returns (stream EchoResponse) {} + rpc ClientStreamingEcho(stream EchoRequest) returns (EchoResponse) {} + rpc BidirectionalStreamingEcho(stream EchoRequest) returns (stream EchoResponse) {} +}