Remote Call Framework 3.4
External Serialization

Protocol Buffers

Protocol Buffers is an open source project released by Google, which uses a specialized language to define serialization schemas, from which actual serialization code is generated. The official Protocol Buffers compiler can generate code in a number of languages, including C++, C#, Java and Python.

Protocol Buffer Classes

RCF provides native marshaling support for classes generated by the Protocol Buffers compiler. To enable this support, define RCF_FEATURE_PROTOBUF=1 when building RCF. With RCF_USE_PROTOBUF=1 defined, classes produced by the Protocol Buffers compiler, can be used directly in RCF interface declarations, and will be serialized and deserialized using the Protocol Buffer runtime.

For more information on building RCF with Protocol Buffer support, see Building RCF.

As an example, consider this .proto file.

// Person.proto
message Person {
int32 id = 1;
string name = 2;
string email = 3;
}

Running the Protocol Buffer compiler (in C++ mode) over Person.proto results in the two files Person.pb.h and Person.pb.cc, containing the implementation of the C++ class Person.

// Person.pb.h
class Person : public ::google::protobuf::Message {
// ...
}

You can now include Person.pb.h in your program, and use the class Person in an RCF interface. RCF will detect that the Person class is a Protocol Buffer class, and will use Protocol Buffer functions to serialize and deserialize Person instances.

#include <RCF/../../test/protobuf/messages/cpp/Person.pb.h>
namespace {
RCF_BEGIN(I_X, "I_X")
RCF_METHOD_R1(Person, Echo, const Person &)
RCF_END(I_X)

Protocol Buffer classes can be used together with native C++ classes, in RCF interfaces:

RCF_BEGIN(I_X, "I_X")
RCF_METHOD_R1(Person, Echo, const Person &)
RCF_METHOD_V4(void , SomeOtherMethod, int, const std::vector<std::string> &, Person &, RCF::ByteBuffer)
RCF_END(I_X)

Protocol Buffer Caching

The serialization and deserialization code generated by Protocol Buffers is highly optimized. However, to make the most of this performance, you may want to cache and reuse Protocol Buffer objects from call to call, rather than creating new ones. Protocol Buffer objects are designed to retain any memory they allocate, and will reuse that memory in subsequent serialization and deserialization operations.

RCF provides server-side object caching, for this purpose. Here is an example of enabling server-side caching of Person objects:

RCF::ObjectPool & cache = RCF::getObjectPool();
// Enable server-side caching for Person.
// * Don't cache more than 10 Person objects.
// * Call Person::Clear() before putting a Person object into the cache.
auto clearPerson = [](Person * pPerson) { pPerson->Clear(); };
cache.enableCaching<Person>(10, clearPerson);

Boost.Serialization

Past versions of RCF supported the usage of Boost.Serialization , as a drop in replacement for RCF's internal serialization framework.

As of RCF 3.0, however, usage of Boost.Serialization is deprecated.

Support for Boost.Serialization will be removed from the codebase in a future release.