ProtocolBufferConverter » History » Version 1
Version 1/19
-
Next ยป -
Current version
J. Moringen, 06/23/2011 08:50 PM
initial version
ProtocolBufferConverter¶
Introduction¶
Google protocol buffers are an approach for IDL-driven generation of domain classes (or at least data-holder classes) and associated serialization and deserialization code. In RSB, arbitrary protocol buffer messages can be processed using the converter mechanism. Depending of the programming, the particular protocol buffer messages, that will be used, may have to be registered in the converter system in some way. However, after the registration, serialization and deserialization works transparently without further implementation or configuration work.
Advantages of this approach over manual converter writing (as described here) include:
- IDL-defined message format (as opposed to an informal "definition" through a particular implementation)
- Proper handling of machine Endianess
- Proper handling of machine word sizes
- Some degree of data validation
- Introspection support
- Generated domain classes and (de)serializers
- Available in multiple programming languages without additional effort
- Inter-language consistency of domain classes and serialized representations
This page describes how to use the ProtocolBufferConverter
class with user-defined protocol buffer messages. The running example of a fictional SimpleImage
data-type (introduced here) is reused.
Message Definition¶
A SimpleImage
consists of
- a width (a non-negative integer)
- a height (a non-negative integer)
- image data (an array of bytes)
This structure is reflected in the protocol buffer message definition:
source:trunk/cpp/core/examples/protobuf_converter/SimpleImage.proto
Code (C++)¶
As explained above, no code has to written for the domain class or its (de)serialization. However, it is necessary to register a template instantiation of the ProtocolBufferConverter
class in the converter registry. The sender and receiver programs demonstrate how to do this and additionally send and receive SimpleImage
messages respectively:
source:trunk/cpp/core/examples/protobuf_converter/sender.cpp
source:trunk/cpp/core/examples/protobuf_converter/receiver.cpp