Merge pull request #136 from iamqizhao/non-proto
Interface change to accommodate the support of non-protobuf data formats
This commit is contained in:
@ -388,7 +388,7 @@ func (c *testServiceClient) StreamingOutputCall(ctx context.Context, in *Streami
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
x := &testServiceStreamingOutputCallClient{stream}
|
x := &testServiceStreamingOutputCallClient{stream}
|
||||||
if err := x.ClientStream.SendProto(in); err != nil {
|
if err := x.ClientStream.SendMsg(in); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := x.ClientStream.CloseSend(); err != nil {
|
if err := x.ClientStream.CloseSend(); err != nil {
|
||||||
@ -408,7 +408,7 @@ type testServiceStreamingOutputCallClient struct {
|
|||||||
|
|
||||||
func (x *testServiceStreamingOutputCallClient) Recv() (*StreamingOutputCallResponse, error) {
|
func (x *testServiceStreamingOutputCallClient) Recv() (*StreamingOutputCallResponse, error) {
|
||||||
m := new(StreamingOutputCallResponse)
|
m := new(StreamingOutputCallResponse)
|
||||||
if err := x.ClientStream.RecvProto(m); err != nil {
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
@ -434,7 +434,7 @@ type testServiceStreamingInputCallClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceStreamingInputCallClient) Send(m *StreamingInputCallRequest) error {
|
func (x *testServiceStreamingInputCallClient) Send(m *StreamingInputCallRequest) error {
|
||||||
return x.ClientStream.SendProto(m)
|
return x.ClientStream.SendMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceStreamingInputCallClient) CloseAndRecv() (*StreamingInputCallResponse, error) {
|
func (x *testServiceStreamingInputCallClient) CloseAndRecv() (*StreamingInputCallResponse, error) {
|
||||||
@ -442,7 +442,7 @@ func (x *testServiceStreamingInputCallClient) CloseAndRecv() (*StreamingInputCal
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
m := new(StreamingInputCallResponse)
|
m := new(StreamingInputCallResponse)
|
||||||
if err := x.ClientStream.RecvProto(m); err != nil {
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
@ -468,12 +468,12 @@ type testServiceFullDuplexCallClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceFullDuplexCallClient) Send(m *StreamingOutputCallRequest) error {
|
func (x *testServiceFullDuplexCallClient) Send(m *StreamingOutputCallRequest) error {
|
||||||
return x.ClientStream.SendProto(m)
|
return x.ClientStream.SendMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceFullDuplexCallClient) Recv() (*StreamingOutputCallResponse, error) {
|
func (x *testServiceFullDuplexCallClient) Recv() (*StreamingOutputCallResponse, error) {
|
||||||
m := new(StreamingOutputCallResponse)
|
m := new(StreamingOutputCallResponse)
|
||||||
if err := x.ClientStream.RecvProto(m); err != nil {
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
@ -499,12 +499,12 @@ type testServiceHalfDuplexCallClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceHalfDuplexCallClient) Send(m *StreamingOutputCallRequest) error {
|
func (x *testServiceHalfDuplexCallClient) Send(m *StreamingOutputCallRequest) error {
|
||||||
return x.ClientStream.SendProto(m)
|
return x.ClientStream.SendMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceHalfDuplexCallClient) Recv() (*StreamingOutputCallResponse, error) {
|
func (x *testServiceHalfDuplexCallClient) Recv() (*StreamingOutputCallResponse, error) {
|
||||||
m := new(StreamingOutputCallResponse)
|
m := new(StreamingOutputCallResponse)
|
||||||
if err := x.ClientStream.RecvProto(m); err != nil {
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
@ -539,7 +539,7 @@ func RegisterTestServiceServer(s *grpc.Server, srv TestServiceServer) {
|
|||||||
s.RegisterService(&_TestService_serviceDesc, srv)
|
s.RegisterService(&_TestService_serviceDesc, srv)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _TestService_EmptyCall_Handler(srv interface{}, ctx context.Context, buf []byte) (proto.Message, error) {
|
func _TestService_EmptyCall_Handler(srv interface{}, ctx context.Context, buf []byte) (interface{}, error) {
|
||||||
in := new(Empty)
|
in := new(Empty)
|
||||||
if err := proto.Unmarshal(buf, in); err != nil {
|
if err := proto.Unmarshal(buf, in); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -551,7 +551,7 @@ func _TestService_EmptyCall_Handler(srv interface{}, ctx context.Context, buf []
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func _TestService_UnaryCall_Handler(srv interface{}, ctx context.Context, buf []byte) (proto.Message, error) {
|
func _TestService_UnaryCall_Handler(srv interface{}, ctx context.Context, buf []byte) (interface{}, error) {
|
||||||
in := new(SimpleRequest)
|
in := new(SimpleRequest)
|
||||||
if err := proto.Unmarshal(buf, in); err != nil {
|
if err := proto.Unmarshal(buf, in); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -565,7 +565,7 @@ func _TestService_UnaryCall_Handler(srv interface{}, ctx context.Context, buf []
|
|||||||
|
|
||||||
func _TestService_StreamingOutputCall_Handler(srv interface{}, stream grpc.ServerStream) error {
|
func _TestService_StreamingOutputCall_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||||
m := new(StreamingOutputCallRequest)
|
m := new(StreamingOutputCallRequest)
|
||||||
if err := stream.RecvProto(m); err != nil {
|
if err := stream.RecvMsg(m); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return srv.(TestServiceServer).StreamingOutputCall(m, &testServiceStreamingOutputCallServer{stream})
|
return srv.(TestServiceServer).StreamingOutputCall(m, &testServiceStreamingOutputCallServer{stream})
|
||||||
@ -581,7 +581,7 @@ type testServiceStreamingOutputCallServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceStreamingOutputCallServer) Send(m *StreamingOutputCallResponse) error {
|
func (x *testServiceStreamingOutputCallServer) Send(m *StreamingOutputCallResponse) error {
|
||||||
return x.ServerStream.SendProto(m)
|
return x.ServerStream.SendMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _TestService_StreamingInputCall_Handler(srv interface{}, stream grpc.ServerStream) error {
|
func _TestService_StreamingInputCall_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||||
@ -599,12 +599,12 @@ type testServiceStreamingInputCallServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceStreamingInputCallServer) SendAndClose(m *StreamingInputCallResponse) error {
|
func (x *testServiceStreamingInputCallServer) SendAndClose(m *StreamingInputCallResponse) error {
|
||||||
return x.ServerStream.SendProto(m)
|
return x.ServerStream.SendMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceStreamingInputCallServer) Recv() (*StreamingInputCallRequest, error) {
|
func (x *testServiceStreamingInputCallServer) Recv() (*StreamingInputCallRequest, error) {
|
||||||
m := new(StreamingInputCallRequest)
|
m := new(StreamingInputCallRequest)
|
||||||
if err := x.ServerStream.RecvProto(m); err != nil {
|
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
@ -625,12 +625,12 @@ type testServiceFullDuplexCallServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceFullDuplexCallServer) Send(m *StreamingOutputCallResponse) error {
|
func (x *testServiceFullDuplexCallServer) Send(m *StreamingOutputCallResponse) error {
|
||||||
return x.ServerStream.SendProto(m)
|
return x.ServerStream.SendMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceFullDuplexCallServer) Recv() (*StreamingOutputCallRequest, error) {
|
func (x *testServiceFullDuplexCallServer) Recv() (*StreamingOutputCallRequest, error) {
|
||||||
m := new(StreamingOutputCallRequest)
|
m := new(StreamingOutputCallRequest)
|
||||||
if err := x.ServerStream.RecvProto(m); err != nil {
|
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
@ -651,12 +651,12 @@ type testServiceHalfDuplexCallServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceHalfDuplexCallServer) Send(m *StreamingOutputCallResponse) error {
|
func (x *testServiceHalfDuplexCallServer) Send(m *StreamingOutputCallResponse) error {
|
||||||
return x.ServerStream.SendProto(m)
|
return x.ServerStream.SendMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceHalfDuplexCallServer) Recv() (*StreamingOutputCallRequest, error) {
|
func (x *testServiceHalfDuplexCallServer) Recv() (*StreamingOutputCallRequest, error) {
|
||||||
m := new(StreamingOutputCallRequest)
|
m := new(StreamingOutputCallRequest)
|
||||||
if err := x.ServerStream.RecvProto(m); err != nil {
|
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
|
19
call.go
19
call.go
@ -37,18 +37,17 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/metadata"
|
"google.golang.org/grpc/metadata"
|
||||||
"google.golang.org/grpc/transport"
|
"google.golang.org/grpc/transport"
|
||||||
)
|
)
|
||||||
|
|
||||||
// recv receives and parses an RPC response.
|
// recvResponse receives and parses an RPC response.
|
||||||
// On error, it returns the error and indicates whether the call should be retried.
|
// On error, it returns the error and indicates whether the call should be retried.
|
||||||
//
|
//
|
||||||
// TODO(zhaoq): Check whether the received message sequence is valid.
|
// TODO(zhaoq): Check whether the received message sequence is valid.
|
||||||
func recv(t transport.ClientTransport, c *callInfo, stream *transport.Stream, reply proto.Message) error {
|
func recvResponse(t transport.ClientTransport, c *callInfo, stream *transport.Stream, reply interface{}) error {
|
||||||
// Try to acquire header metadata from the server if there is any.
|
// Try to acquire header metadata from the server if there is any.
|
||||||
var err error
|
var err error
|
||||||
c.headerMD, err = stream.Header()
|
c.headerMD, err = stream.Header()
|
||||||
@ -57,7 +56,7 @@ func recv(t transport.ClientTransport, c *callInfo, stream *transport.Stream, re
|
|||||||
}
|
}
|
||||||
p := &parser{s: stream}
|
p := &parser{s: stream}
|
||||||
for {
|
for {
|
||||||
if err = recvProto(p, reply); err != nil {
|
if err = recv(p, protoCodec{}, reply); err != nil {
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -68,8 +67,8 @@ func recv(t transport.ClientTransport, c *callInfo, stream *transport.Stream, re
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// sendRPC writes out various information of an RPC such as Context and Message.
|
// sendRequest writes out various information of an RPC such as Context and Message.
|
||||||
func sendRPC(ctx context.Context, callHdr *transport.CallHdr, t transport.ClientTransport, args proto.Message, opts *transport.Options) (_ *transport.Stream, err error) {
|
func sendRequest(ctx context.Context, callHdr *transport.CallHdr, t transport.ClientTransport, args interface{}, opts *transport.Options) (_ *transport.Stream, err error) {
|
||||||
stream, err := t.NewStream(ctx, callHdr)
|
stream, err := t.NewStream(ctx, callHdr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -82,7 +81,7 @@ func sendRPC(ctx context.Context, callHdr *transport.CallHdr, t transport.Client
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
// TODO(zhaoq): Support compression.
|
// TODO(zhaoq): Support compression.
|
||||||
outBuf, err := encode(args, compressionNone)
|
outBuf, err := encode(protoCodec{}, args, compressionNone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, transport.StreamErrorf(codes.Internal, "grpc: %v", err)
|
return nil, transport.StreamErrorf(codes.Internal, "grpc: %v", err)
|
||||||
}
|
}
|
||||||
@ -103,7 +102,7 @@ type callInfo struct {
|
|||||||
|
|
||||||
// Invoke is called by the generated code. It sends the RPC request on the
|
// Invoke is called by the generated code. It sends the RPC request on the
|
||||||
// wire and returns after response is received.
|
// wire and returns after response is received.
|
||||||
func Invoke(ctx context.Context, method string, args, reply proto.Message, cc *ClientConn, opts ...CallOption) error {
|
func Invoke(ctx context.Context, method string, args, reply interface{}, cc *ClientConn, opts ...CallOption) error {
|
||||||
var c callInfo
|
var c callInfo
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
if err := o.before(&c); err != nil {
|
if err := o.before(&c); err != nil {
|
||||||
@ -149,7 +148,7 @@ func Invoke(ctx context.Context, method string, args, reply proto.Message, cc *C
|
|||||||
}
|
}
|
||||||
return toRPCErr(err)
|
return toRPCErr(err)
|
||||||
}
|
}
|
||||||
stream, err = sendRPC(ctx, callHdr, t, args, topts)
|
stream, err = sendRequest(ctx, callHdr, t, args, topts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(transport.ConnectionError); ok {
|
if _, ok := err.(transport.ConnectionError); ok {
|
||||||
lastErr = err
|
lastErr = err
|
||||||
@ -161,7 +160,7 @@ func Invoke(ctx context.Context, method string, args, reply proto.Message, cc *C
|
|||||||
return toRPCErr(err)
|
return toRPCErr(err)
|
||||||
}
|
}
|
||||||
// Receive the response
|
// Receive the response
|
||||||
lastErr = recv(t, &c, stream, reply)
|
lastErr = recvResponse(t, &c, stream, reply)
|
||||||
if _, ok := lastErr.(transport.ConnectionError); ok {
|
if _, ok := lastErr.(transport.ConnectionError); ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,7 @@ func (c *routeGuideClient) ListFeatures(ctx context.Context, in *Rectangle, opts
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
x := &routeGuideListFeaturesClient{stream}
|
x := &routeGuideListFeaturesClient{stream}
|
||||||
if err := x.ClientStream.SendProto(in); err != nil {
|
if err := x.ClientStream.SendMsg(in); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := x.ClientStream.CloseSend(); err != nil {
|
if err := x.ClientStream.CloseSend(); err != nil {
|
||||||
@ -206,7 +206,7 @@ type routeGuideListFeaturesClient struct {
|
|||||||
|
|
||||||
func (x *routeGuideListFeaturesClient) Recv() (*Feature, error) {
|
func (x *routeGuideListFeaturesClient) Recv() (*Feature, error) {
|
||||||
m := new(Feature)
|
m := new(Feature)
|
||||||
if err := x.ClientStream.RecvProto(m); err != nil {
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
@ -232,7 +232,7 @@ type routeGuideRecordRouteClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *routeGuideRecordRouteClient) Send(m *Point) error {
|
func (x *routeGuideRecordRouteClient) Send(m *Point) error {
|
||||||
return x.ClientStream.SendProto(m)
|
return x.ClientStream.SendMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *routeGuideRecordRouteClient) CloseAndRecv() (*RouteSummary, error) {
|
func (x *routeGuideRecordRouteClient) CloseAndRecv() (*RouteSummary, error) {
|
||||||
@ -240,7 +240,7 @@ func (x *routeGuideRecordRouteClient) CloseAndRecv() (*RouteSummary, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
m := new(RouteSummary)
|
m := new(RouteSummary)
|
||||||
if err := x.ClientStream.RecvProto(m); err != nil {
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
@ -266,12 +266,12 @@ type routeGuideRouteChatClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *routeGuideRouteChatClient) Send(m *RouteNote) error {
|
func (x *routeGuideRouteChatClient) Send(m *RouteNote) error {
|
||||||
return x.ClientStream.SendProto(m)
|
return x.ClientStream.SendMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *routeGuideRouteChatClient) Recv() (*RouteNote, error) {
|
func (x *routeGuideRouteChatClient) Recv() (*RouteNote, error) {
|
||||||
m := new(RouteNote)
|
m := new(RouteNote)
|
||||||
if err := x.ClientStream.RecvProto(m); err != nil {
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
@ -310,7 +310,7 @@ func RegisterRouteGuideServer(s *grpc.Server, srv RouteGuideServer) {
|
|||||||
s.RegisterService(&_RouteGuide_serviceDesc, srv)
|
s.RegisterService(&_RouteGuide_serviceDesc, srv)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _RouteGuide_GetFeature_Handler(srv interface{}, ctx context.Context, buf []byte) (proto1.Message, error) {
|
func _RouteGuide_GetFeature_Handler(srv interface{}, ctx context.Context, buf []byte) (interface{}, error) {
|
||||||
in := new(Point)
|
in := new(Point)
|
||||||
if err := proto1.Unmarshal(buf, in); err != nil {
|
if err := proto1.Unmarshal(buf, in); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -324,7 +324,7 @@ func _RouteGuide_GetFeature_Handler(srv interface{}, ctx context.Context, buf []
|
|||||||
|
|
||||||
func _RouteGuide_ListFeatures_Handler(srv interface{}, stream grpc.ServerStream) error {
|
func _RouteGuide_ListFeatures_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||||
m := new(Rectangle)
|
m := new(Rectangle)
|
||||||
if err := stream.RecvProto(m); err != nil {
|
if err := stream.RecvMsg(m); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return srv.(RouteGuideServer).ListFeatures(m, &routeGuideListFeaturesServer{stream})
|
return srv.(RouteGuideServer).ListFeatures(m, &routeGuideListFeaturesServer{stream})
|
||||||
@ -340,7 +340,7 @@ type routeGuideListFeaturesServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *routeGuideListFeaturesServer) Send(m *Feature) error {
|
func (x *routeGuideListFeaturesServer) Send(m *Feature) error {
|
||||||
return x.ServerStream.SendProto(m)
|
return x.ServerStream.SendMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _RouteGuide_RecordRoute_Handler(srv interface{}, stream grpc.ServerStream) error {
|
func _RouteGuide_RecordRoute_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||||
@ -358,12 +358,12 @@ type routeGuideRecordRouteServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *routeGuideRecordRouteServer) SendAndClose(m *RouteSummary) error {
|
func (x *routeGuideRecordRouteServer) SendAndClose(m *RouteSummary) error {
|
||||||
return x.ServerStream.SendProto(m)
|
return x.ServerStream.SendMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *routeGuideRecordRouteServer) Recv() (*Point, error) {
|
func (x *routeGuideRecordRouteServer) Recv() (*Point, error) {
|
||||||
m := new(Point)
|
m := new(Point)
|
||||||
if err := x.ServerStream.RecvProto(m); err != nil {
|
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
@ -384,12 +384,12 @@ type routeGuideRouteChatServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *routeGuideRouteChatServer) Send(m *RouteNote) error {
|
func (x *routeGuideRouteChatServer) Send(m *RouteNote) error {
|
||||||
return x.ServerStream.SendProto(m)
|
return x.ServerStream.SendMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *routeGuideRouteChatServer) Recv() (*RouteNote, error) {
|
func (x *routeGuideRouteChatServer) Recv() (*RouteNote, error) {
|
||||||
m := new(RouteNote)
|
m := new(RouteNote)
|
||||||
if err := x.ServerStream.RecvProto(m); err != nil {
|
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
|
@ -388,7 +388,7 @@ func (c *testServiceClient) StreamingOutputCall(ctx context.Context, in *Streami
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
x := &testServiceStreamingOutputCallClient{stream}
|
x := &testServiceStreamingOutputCallClient{stream}
|
||||||
if err := x.ClientStream.SendProto(in); err != nil {
|
if err := x.ClientStream.SendMsg(in); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := x.ClientStream.CloseSend(); err != nil {
|
if err := x.ClientStream.CloseSend(); err != nil {
|
||||||
@ -408,7 +408,7 @@ type testServiceStreamingOutputCallClient struct {
|
|||||||
|
|
||||||
func (x *testServiceStreamingOutputCallClient) Recv() (*StreamingOutputCallResponse, error) {
|
func (x *testServiceStreamingOutputCallClient) Recv() (*StreamingOutputCallResponse, error) {
|
||||||
m := new(StreamingOutputCallResponse)
|
m := new(StreamingOutputCallResponse)
|
||||||
if err := x.ClientStream.RecvProto(m); err != nil {
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
@ -434,7 +434,7 @@ type testServiceStreamingInputCallClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceStreamingInputCallClient) Send(m *StreamingInputCallRequest) error {
|
func (x *testServiceStreamingInputCallClient) Send(m *StreamingInputCallRequest) error {
|
||||||
return x.ClientStream.SendProto(m)
|
return x.ClientStream.SendMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceStreamingInputCallClient) CloseAndRecv() (*StreamingInputCallResponse, error) {
|
func (x *testServiceStreamingInputCallClient) CloseAndRecv() (*StreamingInputCallResponse, error) {
|
||||||
@ -442,7 +442,7 @@ func (x *testServiceStreamingInputCallClient) CloseAndRecv() (*StreamingInputCal
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
m := new(StreamingInputCallResponse)
|
m := new(StreamingInputCallResponse)
|
||||||
if err := x.ClientStream.RecvProto(m); err != nil {
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
@ -468,12 +468,12 @@ type testServiceFullDuplexCallClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceFullDuplexCallClient) Send(m *StreamingOutputCallRequest) error {
|
func (x *testServiceFullDuplexCallClient) Send(m *StreamingOutputCallRequest) error {
|
||||||
return x.ClientStream.SendProto(m)
|
return x.ClientStream.SendMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceFullDuplexCallClient) Recv() (*StreamingOutputCallResponse, error) {
|
func (x *testServiceFullDuplexCallClient) Recv() (*StreamingOutputCallResponse, error) {
|
||||||
m := new(StreamingOutputCallResponse)
|
m := new(StreamingOutputCallResponse)
|
||||||
if err := x.ClientStream.RecvProto(m); err != nil {
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
@ -499,12 +499,12 @@ type testServiceHalfDuplexCallClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceHalfDuplexCallClient) Send(m *StreamingOutputCallRequest) error {
|
func (x *testServiceHalfDuplexCallClient) Send(m *StreamingOutputCallRequest) error {
|
||||||
return x.ClientStream.SendProto(m)
|
return x.ClientStream.SendMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceHalfDuplexCallClient) Recv() (*StreamingOutputCallResponse, error) {
|
func (x *testServiceHalfDuplexCallClient) Recv() (*StreamingOutputCallResponse, error) {
|
||||||
m := new(StreamingOutputCallResponse)
|
m := new(StreamingOutputCallResponse)
|
||||||
if err := x.ClientStream.RecvProto(m); err != nil {
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
@ -539,7 +539,7 @@ func RegisterTestServiceServer(s *grpc.Server, srv TestServiceServer) {
|
|||||||
s.RegisterService(&_TestService_serviceDesc, srv)
|
s.RegisterService(&_TestService_serviceDesc, srv)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _TestService_EmptyCall_Handler(srv interface{}, ctx context.Context, buf []byte) (proto.Message, error) {
|
func _TestService_EmptyCall_Handler(srv interface{}, ctx context.Context, buf []byte) (interface{}, error) {
|
||||||
in := new(Empty)
|
in := new(Empty)
|
||||||
if err := proto.Unmarshal(buf, in); err != nil {
|
if err := proto.Unmarshal(buf, in); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -551,7 +551,7 @@ func _TestService_EmptyCall_Handler(srv interface{}, ctx context.Context, buf []
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func _TestService_UnaryCall_Handler(srv interface{}, ctx context.Context, buf []byte) (proto.Message, error) {
|
func _TestService_UnaryCall_Handler(srv interface{}, ctx context.Context, buf []byte) (interface{}, error) {
|
||||||
in := new(SimpleRequest)
|
in := new(SimpleRequest)
|
||||||
if err := proto.Unmarshal(buf, in); err != nil {
|
if err := proto.Unmarshal(buf, in); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -565,7 +565,7 @@ func _TestService_UnaryCall_Handler(srv interface{}, ctx context.Context, buf []
|
|||||||
|
|
||||||
func _TestService_StreamingOutputCall_Handler(srv interface{}, stream grpc.ServerStream) error {
|
func _TestService_StreamingOutputCall_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||||
m := new(StreamingOutputCallRequest)
|
m := new(StreamingOutputCallRequest)
|
||||||
if err := stream.RecvProto(m); err != nil {
|
if err := stream.RecvMsg(m); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return srv.(TestServiceServer).StreamingOutputCall(m, &testServiceStreamingOutputCallServer{stream})
|
return srv.(TestServiceServer).StreamingOutputCall(m, &testServiceStreamingOutputCallServer{stream})
|
||||||
@ -581,7 +581,7 @@ type testServiceStreamingOutputCallServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceStreamingOutputCallServer) Send(m *StreamingOutputCallResponse) error {
|
func (x *testServiceStreamingOutputCallServer) Send(m *StreamingOutputCallResponse) error {
|
||||||
return x.ServerStream.SendProto(m)
|
return x.ServerStream.SendMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _TestService_StreamingInputCall_Handler(srv interface{}, stream grpc.ServerStream) error {
|
func _TestService_StreamingInputCall_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||||
@ -599,12 +599,12 @@ type testServiceStreamingInputCallServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceStreamingInputCallServer) SendAndClose(m *StreamingInputCallResponse) error {
|
func (x *testServiceStreamingInputCallServer) SendAndClose(m *StreamingInputCallResponse) error {
|
||||||
return x.ServerStream.SendProto(m)
|
return x.ServerStream.SendMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceStreamingInputCallServer) Recv() (*StreamingInputCallRequest, error) {
|
func (x *testServiceStreamingInputCallServer) Recv() (*StreamingInputCallRequest, error) {
|
||||||
m := new(StreamingInputCallRequest)
|
m := new(StreamingInputCallRequest)
|
||||||
if err := x.ServerStream.RecvProto(m); err != nil {
|
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
@ -625,12 +625,12 @@ type testServiceFullDuplexCallServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceFullDuplexCallServer) Send(m *StreamingOutputCallResponse) error {
|
func (x *testServiceFullDuplexCallServer) Send(m *StreamingOutputCallResponse) error {
|
||||||
return x.ServerStream.SendProto(m)
|
return x.ServerStream.SendMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceFullDuplexCallServer) Recv() (*StreamingOutputCallRequest, error) {
|
func (x *testServiceFullDuplexCallServer) Recv() (*StreamingOutputCallRequest, error) {
|
||||||
m := new(StreamingOutputCallRequest)
|
m := new(StreamingOutputCallRequest)
|
||||||
if err := x.ServerStream.RecvProto(m); err != nil {
|
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
@ -651,12 +651,12 @@ type testServiceHalfDuplexCallServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceHalfDuplexCallServer) Send(m *StreamingOutputCallResponse) error {
|
func (x *testServiceHalfDuplexCallServer) Send(m *StreamingOutputCallResponse) error {
|
||||||
return x.ServerStream.SendProto(m)
|
return x.ServerStream.SendMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceHalfDuplexCallServer) Recv() (*StreamingOutputCallRequest, error) {
|
func (x *testServiceHalfDuplexCallServer) Recv() (*StreamingOutputCallRequest, error) {
|
||||||
m := new(StreamingOutputCallRequest)
|
m := new(StreamingOutputCallRequest)
|
||||||
if err := x.ServerStream.RecvProto(m); err != nil {
|
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
|
34
rpc_util.go
34
rpc_util.go
@ -49,6 +49,32 @@ import (
|
|||||||
"google.golang.org/grpc/transport"
|
"google.golang.org/grpc/transport"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Codec defines the interface gRPC uses to encode and decode messages.
|
||||||
|
type Codec interface {
|
||||||
|
// Marshal returns the wire format of v.
|
||||||
|
Marshal(v interface{}) ([]byte, error)
|
||||||
|
// Unmarshal parses the wire format into v.
|
||||||
|
Unmarshal(data []byte, v interface{}) error
|
||||||
|
// String returns the name of the Codec implementation. The returned
|
||||||
|
// string will be used as part of content type in transmission.
|
||||||
|
String() string
|
||||||
|
}
|
||||||
|
|
||||||
|
// protoCodec is a Codec implemetation with protobuf. It is the default codec for gRPC.
|
||||||
|
type protoCodec struct{}
|
||||||
|
|
||||||
|
func (protoCodec) Marshal(v interface{}) ([]byte, error) {
|
||||||
|
return proto.Marshal(v.(proto.Message))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (protoCodec) Unmarshal(data []byte, v interface{}) error {
|
||||||
|
return proto.Unmarshal(data, v.(proto.Message))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (protoCodec) String() string {
|
||||||
|
return "proto"
|
||||||
|
}
|
||||||
|
|
||||||
// CallOption configures a Call before it starts or extracts information from
|
// CallOption configures a Call before it starts or extracts information from
|
||||||
// a Call after it completes.
|
// a Call after it completes.
|
||||||
type CallOption interface {
|
type CallOption interface {
|
||||||
@ -131,7 +157,7 @@ func (p *parser) recvMsg() (pf payloadFormat, msg []byte, err error) {
|
|||||||
|
|
||||||
// encode serializes msg and prepends the message header. If msg is nil, it
|
// encode serializes msg and prepends the message header. If msg is nil, it
|
||||||
// generates the message header of 0 message length.
|
// generates the message header of 0 message length.
|
||||||
func encode(msg proto.Message, pf payloadFormat) ([]byte, error) {
|
func encode(c Codec, msg interface{}, pf payloadFormat) ([]byte, error) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
// Write message fixed header.
|
// Write message fixed header.
|
||||||
buf.WriteByte(uint8(pf))
|
buf.WriteByte(uint8(pf))
|
||||||
@ -140,7 +166,7 @@ func encode(msg proto.Message, pf payloadFormat) ([]byte, error) {
|
|||||||
if msg != nil {
|
if msg != nil {
|
||||||
var err error
|
var err error
|
||||||
// TODO(zhaoq): optimize to reduce memory alloc and copying.
|
// TODO(zhaoq): optimize to reduce memory alloc and copying.
|
||||||
b, err = proto.Marshal(msg)
|
b, err = c.Marshal(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -153,14 +179,14 @@ func encode(msg proto.Message, pf payloadFormat) ([]byte, error) {
|
|||||||
return buf.Bytes(), nil
|
return buf.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func recvProto(p *parser, m proto.Message) error {
|
func recv(p *parser, c Codec, m interface{}) error {
|
||||||
pf, d, err := p.recvMsg()
|
pf, d, err := p.recvMsg()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
switch pf {
|
switch pf {
|
||||||
case compressionNone:
|
case compressionNone:
|
||||||
if err := proto.Unmarshal(d, m); err != nil {
|
if err := c.Unmarshal(d, m); err != nil {
|
||||||
return Errorf(codes.Internal, "grpc: %v", err)
|
return Errorf(codes.Internal, "grpc: %v", err)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -112,9 +112,9 @@ func TestEncode(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{nil, compressionNone, []byte{0, 0, 0, 0, 0}, nil},
|
{nil, compressionNone, []byte{0, 0, 0, 0, 0}, nil},
|
||||||
} {
|
} {
|
||||||
b, err := encode(test.msg, test.pt)
|
b, err := encode(protoCodec{}, test.msg, test.pt)
|
||||||
if err != test.err || !bytes.Equal(b, test.b) {
|
if err != test.err || !bytes.Equal(b, test.b) {
|
||||||
t.Fatalf("encode(_, %d) = %v, %v\nwant %v, %v", test.pt, b, err, test.b, test.err)
|
t.Fatalf("encode(_, _, %d) = %v, %v\nwant %v, %v", test.pt, b, err, test.b, test.err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -176,12 +176,12 @@ func TestBackoff(t *testing.T) {
|
|||||||
// bytes.
|
// bytes.
|
||||||
func bmEncode(b *testing.B, mSize int) {
|
func bmEncode(b *testing.B, mSize int) {
|
||||||
msg := &perfpb.Buffer{Body: make([]byte, mSize)}
|
msg := &perfpb.Buffer{Body: make([]byte, mSize)}
|
||||||
encoded, _ := encode(msg, compressionNone)
|
encoded, _ := encode(protoCodec{}, msg, compressionNone)
|
||||||
encodedSz := int64(len(encoded))
|
encodedSz := int64(len(encoded))
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
encode(msg, compressionNone)
|
encode(protoCodec{}, msg, compressionNone)
|
||||||
}
|
}
|
||||||
b.SetBytes(encodedSz)
|
b.SetBytes(encodedSz)
|
||||||
}
|
}
|
||||||
|
11
server.go
11
server.go
@ -43,14 +43,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/metadata"
|
"google.golang.org/grpc/metadata"
|
||||||
"google.golang.org/grpc/transport"
|
"google.golang.org/grpc/transport"
|
||||||
)
|
)
|
||||||
|
|
||||||
type methodHandler func(srv interface{}, ctx context.Context, buf []byte) (proto.Message, error)
|
type methodHandler func(srv interface{}, ctx context.Context, buf []byte) (interface{}, error)
|
||||||
|
|
||||||
// MethodDesc represents an RPC service's method specification.
|
// MethodDesc represents an RPC service's method specification.
|
||||||
type MethodDesc struct {
|
type MethodDesc struct {
|
||||||
@ -203,8 +202,8 @@ func (s *Server) Serve(lis net.Listener) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) sendProto(t transport.ServerTransport, stream *transport.Stream, msg proto.Message, pf payloadFormat, opts *transport.Options) error {
|
func (s *Server) sendResponse(t transport.ServerTransport, stream *transport.Stream, msg interface{}, pf payloadFormat, opts *transport.Options) error {
|
||||||
p, err := encode(msg, pf)
|
p, err := encode(protoCodec{}, msg, pf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// This typically indicates a fatal issue (e.g., memory
|
// This typically indicates a fatal issue (e.g., memory
|
||||||
// corruption or hardware faults) the application program
|
// corruption or hardware faults) the application program
|
||||||
@ -213,7 +212,7 @@ func (s *Server) sendProto(t transport.ServerTransport, stream *transport.Stream
|
|||||||
// TODO(zhaoq): There exist other options also such as only closing the
|
// TODO(zhaoq): There exist other options also such as only closing the
|
||||||
// faulty stream locally and remotely (Other streams can keep going). Find
|
// faulty stream locally and remotely (Other streams can keep going). Find
|
||||||
// the optimal option.
|
// the optimal option.
|
||||||
log.Fatalf("grpc: Server failed to encode proto message %v", err)
|
log.Fatalf("grpc: Server failed to encode response %v", err)
|
||||||
}
|
}
|
||||||
return t.Write(stream, p, opts)
|
return t.Write(stream, p, opts)
|
||||||
}
|
}
|
||||||
@ -261,7 +260,7 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport.
|
|||||||
Last: true,
|
Last: true,
|
||||||
Delay: false,
|
Delay: false,
|
||||||
}
|
}
|
||||||
if err := s.sendProto(t, stream, reply, compressionNone, opts); err != nil {
|
if err := s.sendResponse(t, stream, reply, compressionNone, opts); err != nil {
|
||||||
if _, ok := err.(transport.ConnectionError); ok {
|
if _, ok := err.(transport.ConnectionError); ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
29
stream.go
29
stream.go
@ -38,7 +38,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/metadata"
|
"google.golang.org/grpc/metadata"
|
||||||
@ -61,17 +60,17 @@ type StreamDesc struct {
|
|||||||
type Stream interface {
|
type Stream interface {
|
||||||
// Context returns the context for this stream.
|
// Context returns the context for this stream.
|
||||||
Context() context.Context
|
Context() context.Context
|
||||||
// SendProto blocks until it sends m, the stream is done or the stream
|
// SendMsg blocks until it sends m, the stream is done or the stream
|
||||||
// breaks.
|
// breaks.
|
||||||
// On error, it aborts the stream and returns an RPC status on client
|
// On error, it aborts the stream and returns an RPC status on client
|
||||||
// side. On server side, it simply returns the error to the caller.
|
// side. On server side, it simply returns the error to the caller.
|
||||||
// SendProto is called by generated code.
|
// SendMsg is called by generated code.
|
||||||
SendProto(m proto.Message) error
|
SendMsg(m interface{}) error
|
||||||
// RecvProto blocks until it receives a proto message or the stream is
|
// RecvMsg blocks until it receives a proto message or the stream is
|
||||||
// done. On client side, it returns io.EOF when the stream is done. On
|
// done. On client side, it returns io.EOF when the stream is done. On
|
||||||
// any other error, it aborts the streama nd returns an RPC status. On
|
// any other error, it aborts the streama nd returns an RPC status. On
|
||||||
// server side, it simply returns the error to the caller.
|
// server side, it simply returns the error to the caller.
|
||||||
RecvProto(m proto.Message) error
|
RecvMsg(m interface{}) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClientStream defines the interface a client stream has to satify.
|
// ClientStream defines the interface a client stream has to satify.
|
||||||
@ -146,7 +145,7 @@ func (cs *clientStream) Trailer() metadata.MD {
|
|||||||
return cs.s.Trailer()
|
return cs.s.Trailer()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *clientStream) SendProto(m proto.Message) (err error) {
|
func (cs *clientStream) SendMsg(m interface{}) (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if err == nil || err == io.EOF {
|
if err == nil || err == io.EOF {
|
||||||
return
|
return
|
||||||
@ -156,21 +155,21 @@ func (cs *clientStream) SendProto(m proto.Message) (err error) {
|
|||||||
}
|
}
|
||||||
err = toRPCErr(err)
|
err = toRPCErr(err)
|
||||||
}()
|
}()
|
||||||
out, err := encode(m, compressionNone)
|
out, err := encode(protoCodec{}, m, compressionNone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return transport.StreamErrorf(codes.Internal, "grpc: %v", err)
|
return transport.StreamErrorf(codes.Internal, "grpc: %v", err)
|
||||||
}
|
}
|
||||||
return cs.t.Write(cs.s, out, &transport.Options{Last: false})
|
return cs.t.Write(cs.s, out, &transport.Options{Last: false})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *clientStream) RecvProto(m proto.Message) (err error) {
|
func (cs *clientStream) RecvMsg(m interface{}) (err error) {
|
||||||
err = recvProto(cs.p, m)
|
err = recv(cs.p, protoCodec{}, m)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if !cs.desc.ClientStreams || cs.desc.ServerStreams {
|
if !cs.desc.ClientStreams || cs.desc.ServerStreams {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Special handling for client streaming rpc.
|
// Special handling for client streaming rpc.
|
||||||
err = recvProto(cs.p, m)
|
err = recv(cs.p, protoCodec{}, m)
|
||||||
cs.t.CloseStream(cs.s, err)
|
cs.t.CloseStream(cs.s, err)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return toRPCErr(errors.New("grpc: client streaming protocol violation: get <nil>, want <EOF>"))
|
return toRPCErr(errors.New("grpc: client streaming protocol violation: get <nil>, want <EOF>"))
|
||||||
@ -245,8 +244,8 @@ func (ss *serverStream) SetTrailer(md metadata.MD) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *serverStream) SendProto(m proto.Message) error {
|
func (ss *serverStream) SendMsg(m interface{}) error {
|
||||||
out, err := encode(m, compressionNone)
|
out, err := encode(protoCodec{}, m, compressionNone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = transport.StreamErrorf(codes.Internal, "grpc: %v", err)
|
err = transport.StreamErrorf(codes.Internal, "grpc: %v", err)
|
||||||
return err
|
return err
|
||||||
@ -254,6 +253,6 @@ func (ss *serverStream) SendProto(m proto.Message) error {
|
|||||||
return ss.t.Write(ss.s, out, &transport.Options{Last: false})
|
return ss.t.Write(ss.s, out, &transport.Options{Last: false})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *serverStream) RecvProto(m proto.Message) error {
|
func (ss *serverStream) RecvMsg(m interface{}) error {
|
||||||
return recvProto(ss.p, m)
|
return recv(ss.p, protoCodec{}, m)
|
||||||
}
|
}
|
||||||
|
@ -388,7 +388,7 @@ func (c *testServiceClient) StreamingOutputCall(ctx context.Context, in *Streami
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
x := &testServiceStreamingOutputCallClient{stream}
|
x := &testServiceStreamingOutputCallClient{stream}
|
||||||
if err := x.ClientStream.SendProto(in); err != nil {
|
if err := x.ClientStream.SendMsg(in); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := x.ClientStream.CloseSend(); err != nil {
|
if err := x.ClientStream.CloseSend(); err != nil {
|
||||||
@ -408,7 +408,7 @@ type testServiceStreamingOutputCallClient struct {
|
|||||||
|
|
||||||
func (x *testServiceStreamingOutputCallClient) Recv() (*StreamingOutputCallResponse, error) {
|
func (x *testServiceStreamingOutputCallClient) Recv() (*StreamingOutputCallResponse, error) {
|
||||||
m := new(StreamingOutputCallResponse)
|
m := new(StreamingOutputCallResponse)
|
||||||
if err := x.ClientStream.RecvProto(m); err != nil {
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
@ -434,7 +434,7 @@ type testServiceStreamingInputCallClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceStreamingInputCallClient) Send(m *StreamingInputCallRequest) error {
|
func (x *testServiceStreamingInputCallClient) Send(m *StreamingInputCallRequest) error {
|
||||||
return x.ClientStream.SendProto(m)
|
return x.ClientStream.SendMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceStreamingInputCallClient) CloseAndRecv() (*StreamingInputCallResponse, error) {
|
func (x *testServiceStreamingInputCallClient) CloseAndRecv() (*StreamingInputCallResponse, error) {
|
||||||
@ -442,7 +442,7 @@ func (x *testServiceStreamingInputCallClient) CloseAndRecv() (*StreamingInputCal
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
m := new(StreamingInputCallResponse)
|
m := new(StreamingInputCallResponse)
|
||||||
if err := x.ClientStream.RecvProto(m); err != nil {
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
@ -468,12 +468,12 @@ type testServiceFullDuplexCallClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceFullDuplexCallClient) Send(m *StreamingOutputCallRequest) error {
|
func (x *testServiceFullDuplexCallClient) Send(m *StreamingOutputCallRequest) error {
|
||||||
return x.ClientStream.SendProto(m)
|
return x.ClientStream.SendMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceFullDuplexCallClient) Recv() (*StreamingOutputCallResponse, error) {
|
func (x *testServiceFullDuplexCallClient) Recv() (*StreamingOutputCallResponse, error) {
|
||||||
m := new(StreamingOutputCallResponse)
|
m := new(StreamingOutputCallResponse)
|
||||||
if err := x.ClientStream.RecvProto(m); err != nil {
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
@ -499,12 +499,12 @@ type testServiceHalfDuplexCallClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceHalfDuplexCallClient) Send(m *StreamingOutputCallRequest) error {
|
func (x *testServiceHalfDuplexCallClient) Send(m *StreamingOutputCallRequest) error {
|
||||||
return x.ClientStream.SendProto(m)
|
return x.ClientStream.SendMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceHalfDuplexCallClient) Recv() (*StreamingOutputCallResponse, error) {
|
func (x *testServiceHalfDuplexCallClient) Recv() (*StreamingOutputCallResponse, error) {
|
||||||
m := new(StreamingOutputCallResponse)
|
m := new(StreamingOutputCallResponse)
|
||||||
if err := x.ClientStream.RecvProto(m); err != nil {
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
@ -539,7 +539,7 @@ func RegisterTestServiceServer(s *grpc.Server, srv TestServiceServer) {
|
|||||||
s.RegisterService(&_TestService_serviceDesc, srv)
|
s.RegisterService(&_TestService_serviceDesc, srv)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _TestService_EmptyCall_Handler(srv interface{}, ctx context.Context, buf []byte) (proto.Message, error) {
|
func _TestService_EmptyCall_Handler(srv interface{}, ctx context.Context, buf []byte) (interface{}, error) {
|
||||||
in := new(Empty)
|
in := new(Empty)
|
||||||
if err := proto.Unmarshal(buf, in); err != nil {
|
if err := proto.Unmarshal(buf, in); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -551,7 +551,7 @@ func _TestService_EmptyCall_Handler(srv interface{}, ctx context.Context, buf []
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func _TestService_UnaryCall_Handler(srv interface{}, ctx context.Context, buf []byte) (proto.Message, error) {
|
func _TestService_UnaryCall_Handler(srv interface{}, ctx context.Context, buf []byte) (interface{}, error) {
|
||||||
in := new(SimpleRequest)
|
in := new(SimpleRequest)
|
||||||
if err := proto.Unmarshal(buf, in); err != nil {
|
if err := proto.Unmarshal(buf, in); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -565,7 +565,7 @@ func _TestService_UnaryCall_Handler(srv interface{}, ctx context.Context, buf []
|
|||||||
|
|
||||||
func _TestService_StreamingOutputCall_Handler(srv interface{}, stream grpc.ServerStream) error {
|
func _TestService_StreamingOutputCall_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||||
m := new(StreamingOutputCallRequest)
|
m := new(StreamingOutputCallRequest)
|
||||||
if err := stream.RecvProto(m); err != nil {
|
if err := stream.RecvMsg(m); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return srv.(TestServiceServer).StreamingOutputCall(m, &testServiceStreamingOutputCallServer{stream})
|
return srv.(TestServiceServer).StreamingOutputCall(m, &testServiceStreamingOutputCallServer{stream})
|
||||||
@ -581,7 +581,7 @@ type testServiceStreamingOutputCallServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceStreamingOutputCallServer) Send(m *StreamingOutputCallResponse) error {
|
func (x *testServiceStreamingOutputCallServer) Send(m *StreamingOutputCallResponse) error {
|
||||||
return x.ServerStream.SendProto(m)
|
return x.ServerStream.SendMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _TestService_StreamingInputCall_Handler(srv interface{}, stream grpc.ServerStream) error {
|
func _TestService_StreamingInputCall_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||||
@ -599,12 +599,12 @@ type testServiceStreamingInputCallServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceStreamingInputCallServer) SendAndClose(m *StreamingInputCallResponse) error {
|
func (x *testServiceStreamingInputCallServer) SendAndClose(m *StreamingInputCallResponse) error {
|
||||||
return x.ServerStream.SendProto(m)
|
return x.ServerStream.SendMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceStreamingInputCallServer) Recv() (*StreamingInputCallRequest, error) {
|
func (x *testServiceStreamingInputCallServer) Recv() (*StreamingInputCallRequest, error) {
|
||||||
m := new(StreamingInputCallRequest)
|
m := new(StreamingInputCallRequest)
|
||||||
if err := x.ServerStream.RecvProto(m); err != nil {
|
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
@ -625,12 +625,12 @@ type testServiceFullDuplexCallServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceFullDuplexCallServer) Send(m *StreamingOutputCallResponse) error {
|
func (x *testServiceFullDuplexCallServer) Send(m *StreamingOutputCallResponse) error {
|
||||||
return x.ServerStream.SendProto(m)
|
return x.ServerStream.SendMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceFullDuplexCallServer) Recv() (*StreamingOutputCallRequest, error) {
|
func (x *testServiceFullDuplexCallServer) Recv() (*StreamingOutputCallRequest, error) {
|
||||||
m := new(StreamingOutputCallRequest)
|
m := new(StreamingOutputCallRequest)
|
||||||
if err := x.ServerStream.RecvProto(m); err != nil {
|
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
@ -651,12 +651,12 @@ type testServiceHalfDuplexCallServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceHalfDuplexCallServer) Send(m *StreamingOutputCallResponse) error {
|
func (x *testServiceHalfDuplexCallServer) Send(m *StreamingOutputCallResponse) error {
|
||||||
return x.ServerStream.SendProto(m)
|
return x.ServerStream.SendMsg(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *testServiceHalfDuplexCallServer) Recv() (*StreamingOutputCallRequest, error) {
|
func (x *testServiceHalfDuplexCallServer) Recv() (*StreamingOutputCallRequest, error) {
|
||||||
m := new(StreamingOutputCallRequest)
|
m := new(StreamingOutputCallRequest)
|
||||||
if err := x.ServerStream.RecvProto(m); err != nil {
|
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
|
Reference in New Issue
Block a user