gRPC C++ with buffers

468 views
Skip to first unread message

Erik Smith

unread,
Aug 17, 2022, 6:02:55 PM8/17/22
to grpc.io
Is there an example of how to use a gRPC client/server with just a buffer payload?  The closest answer I've seen so far is that it requires a protobuf message with a bytes field

erik

Christopher Warrington - MSFT

unread,
Aug 22, 2022, 9:16:59 PM8/22/22
to grpc.io
Serialization is controlled by specializations of SerializationTraits [1].
There is a built-in one for the grpc::ByteBuffer type [2].

So, using something like grpc::ServerAsyncResponseWriter<grpc::ByteBuffer>
or grpc::ServerWriteReactor<grpc::ByteBuffer> should already work if you can
use grpc::ByteBuffer as your buffer type.

Note: the ProtoBuf codegen writes a lot of the glue code to register
"handler" code for the various methods that you want to expose. If you want
to use raw byte buffers, you'll need to write this code yourself. It's been
a while since I looked at what protoc generates. I'd start by running
codegen on the helloworld.proto file and looking at what it emits for the
the Greeter::AsyncService and Greeter::CallbackService base classes.

I've also not used the callback/reactor model in C++, only the
"async"/completion queue model. I _assume_ the callback/reactor model uses
SerializationTraits as well.


--
Christopher Warrington
Microsoft Corp.
Reply all
Reply to author
Forward
0 new messages