Can C data be sent out through grpc stream.Send() without calling unmarshal?

58 views
Skip to first unread message

Steven Jiang

unread,
Oct 12, 2017, 6:30:08 PM10/12/17
to grpc.io
The message has to be constructed in C code.  My current implementation is :
  1. construct grpc message in C and pass it as bytes to GO code through channel;
  2. in Go code, call proto.unmarshal to get grpc message;
  3.  Send the grpc message out via stream.Send(grpcmsg)

What we want is to skip this unmarshal because we've already constructed the grpc message in C.  Is there any way to do a type cast thing to skip unmarshal?


Thanks
Steven

Kun Zhang

unread,
Oct 17, 2017, 7:18:26 PM10/17/17
to grpc.io
It sounds like the real question is that how to send already serialized message in Go.

Doug Fawley

unread,
Oct 17, 2017, 7:44:03 PM10/17/17
to grpc.io
Yes, you can do this!  You need to use a custom codec and use the native grpc API instead of the proto-generated one.  Example:

Codec definition (basically pass-through):

Install it in the client when dialing:

And then call send with a []byte:

Let me know if any of that is not clear.
 
Thanks,
Doug

Steven Jiang

unread,
Oct 18, 2017, 6:35:04 PM10/18/17
to grpc.io
Thanks for the detailed reply, Doug. There is still one issue in my case:
If it's a dialout connection, I can change the dialOption.  But in my case, the connection is not created by me but by grpc client. I just send back the response.
Is there any way to change the codec of the connection initiated by grpc client?

Regards
Steven 
Reply all
Reply to author
Forward
0 new messages