Permalink
Browse files

Interface change to accommodate the support of non-protobuf data formats

  • Loading branch information...
iamqizhao committed Mar 25, 2015
1 parent 0bcb969 commit 8b08b2d7b2772be4d5e78a28177d5a06f77e9c9a
Showing with 131 additions and 107 deletions.
  1. +18 −18 benchmark/grpc_testing/test.pb.go
  2. +9 −10 call.go
  3. +15 −14 examples/route_guide/proto/route_guide.pb.go
  4. +18 −18 interop/grpc_testing/test.pb.go
  5. +30 −4 rpc_util.go
  6. +4 −4 rpc_util_test.go
  7. +5 −6 server.go
  8. +14 −15 stream.go
  9. +18 −18 test/grpc_testing/test.pb.go

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
19 call.go
@@ -37,18 +37,17 @@ import (
"io"
"net"
"github.com/golang/protobuf/proto"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"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.
//
// 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.
var err error
c.headerMD, err = stream.Header()
@@ -57,7 +56,7 @@ func recv(t transport.ClientTransport, c *callInfo, stream *transport.Stream, re
}
p := &parser{s: stream}
for {
if err = recvProto(p, reply); err != nil {
if err = recv(p, protoCodec{}, reply); err != nil {
if err == io.EOF {
break
}
@@ -68,8 +67,8 @@ func recv(t transport.ClientTransport, c *callInfo, stream *transport.Stream, re
return nil
}
// sendRPC 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) {
// sendRequest writes out various information of an RPC such as Context and Message.
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)
if err != nil {
return nil, err
@@ -82,7 +81,7 @@ func sendRPC(ctx context.Context, callHdr *transport.CallHdr, t transport.Client
}
}()
// TODO(zhaoq): Support compression.
outBuf, err := encode(args, compressionNone)
outBuf, err := encode(protoCodec{}, args, compressionNone)
if err != nil {
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
// 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
for _, o := range opts {
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)
}
stream, err = sendRPC(ctx, callHdr, t, args, topts)
stream, err = sendRequest(ctx, callHdr, t, args, topts)
if err != nil {
if _, ok := err.(transport.ConnectionError); ok {
lastErr = err
@@ -161,7 +160,7 @@ func Invoke(ctx context.Context, method string, args, reply proto.Message, cc *C
return toRPCErr(err)
}
// Receive the response
lastErr = recv(t, &c, stream, reply)
lastErr = recvResponse(t, &c, stream, reply)
if _, ok := lastErr.(transport.ConnectionError); ok {
continue
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 8b08b2d

Please sign in to comment.