diff --git a/rpc_util.go b/rpc_util.go index 4be93ff5..46a6801b 100644 --- a/rpc_util.go +++ b/rpc_util.go @@ -160,7 +160,7 @@ func (p *parser) recvMsg() (pf payloadFormat, msg []byte, err error) { // generates the message header of 0 message length. func encode(c Codec, msg interface{}, pf payloadFormat) ([]byte, error) { var b []byte - var length uint32 + var length uint if msg != nil { var err error // TODO(zhaoq): optimize to reduce memory alloc and copying. @@ -168,7 +168,7 @@ func encode(c Codec, msg interface{}, pf payloadFormat) ([]byte, error) { if err != nil { return nil, err } - length = uint32(len(b)) + length = uint(len(b)) } if length > math.MaxUint32 { return nil, Errorf(codes.InvalidArgument, "grpc: message too large (%d bytes)", length) @@ -184,7 +184,7 @@ func encode(c Codec, msg interface{}, pf payloadFormat) ([]byte, error) { // Write payload format buf[0] = byte(pf) // Write length of b into buf - binary.BigEndian.PutUint32(buf[1:], length) + binary.BigEndian.PutUint32(buf[1:], uint32(length)) // Copy encoded msg to buf copy(buf[5:], b)