7.3.2. Protobuf: Math

In C++ eCAL also supports the protobuf serialization format for the client/server API.

That means that for the request and response, an interface can be defined as a protobuf message in order to make it easier to handle requests.

7.3.2.1. Protobuf file

We use the special protobuf service definitions in order to implement it in our server/client applications. The “message” format is already known by you from the publisher/subscriber examples. The “service” format and the rpc xyz (type) returns (type) is now added. You will see, which effect this addition has on our example.

|fa-folder-open| Math Protobuf File
└─ |fa-file-alt| math.proto

7.3.2.2. Math Server

In the server we need to implement the service interface defined by the protobuf file. For that we derive from the generated class MathService and implement the methods.

For the data exchange the server reads the input messages from the protobuf message and writes directly to the output message.

|fa-folder-open| C++
   └─ |fa-file-alt| math_server.cpp

7.3.2.3. Math Client

The client handling is similiar to the binary example. The main difference is that our request is now a protobuf message which will be the input for the server. In the response we can read out the results and print them to the console.

|fa-folder-open| C++
   └─ |fa-file-alt| math_client.cpp