7.2.4. Cap’n Proto: AddressBook

Cap’n Proto is an insanely fast data interchange format and capability-based RPC system.” eCAL has implemented Cap’n Proto serialization on top of the binary publisher and subscriber API, such that users can conveniently send Cap’n Proto objects. Currently, the eCAL Capnproto Message API is only available for C++.

In the Cap’n Proto example, we will use their default serialization example and send an address book with multiple entries.

7.2.4.1. AddressBook Cap’n Proto

Cap’n Proto uses its own schema definition language to define the data structures, which is not unlike the Protobuf schema definition language.

As the sender and receiver need the same .capnp files, we place them in a separate directory next to the source directories for the sender and the receiver.

Let’s start with the capnp/addressbook.capnp file!

|fa-folder-open| AddressBook Cap'n Proto File
└─ |fa-file-alt| addressbook.capnp

7.2.4.2. AddressBook Publisher

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

7.2.4.3. AddressBook Subscriber

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

7.2.4.4. AddressBook Dynamic Subscriber

Using Capnproto, it is possible to receive data without knowing the structure of the data in advance. Hence you can use a dynamic subscriber to receive capnproto data, even if you do not have access to the corresponding .capnp file. This is useful for generic applications, such as the eCAL Monitor, which can display all data types without knowing them in advance.

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