On Tuesday, February 21, 2023 at 12:15:04 PM UTC-8 Amirsaman Memaripour wrote:
> I am working on a client/server implementation for a gRPC service, where
> both server and client will be written in C++. The server and client will
> use bidirectional streams to communicate, and need to send raw bytes as
> the gRPC (HTTP) payload. The goal is to avoid the overhead of Protobuf and
> use custom serialization code.
From a post of mine [0] in August 2022:
> 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.
[0]:
https://groups.google.com/g/grpc-io/c/VX-ciuDV6Uo/m/_ZV6yWq9AwAJ[1]:
https://grpc.github.io/grpc/cpp/classgrpc_1_1_serialization_traits.html[2]:
https://grpc.github.io/grpc/cpp/classgrpc_1_1_serialization_traits_3_01_byte_buffer_00_01void_01_4.html--
Christopher Warrington
Microsoft Corp.