ProtocolBufferConverter » History » Version 3
J. Moringen, 06/26/2011 11:48 PM
minor change
1 | 1 | J. Moringen | h1. ProtocolBufferConverter |
---|---|---|---|
2 | 1 | J. Moringen | |
3 | 1 | J. Moringen | h2. Introduction |
4 | 1 | J. Moringen | |
5 | 2 | J. Moringen | 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 on the programming language, 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. |
6 | 1 | J. Moringen | |
7 | 1 | J. Moringen | Advantages of this approach over manual converter writing (as described [[Writing_Converters|here]]) include: |
8 | 1 | J. Moringen | |
9 | 1 | J. Moringen | * IDL-defined message format (as opposed to an informal "definition" through a particular implementation) |
10 | 1 | J. Moringen | * Proper handling of machine Endianess |
11 | 1 | J. Moringen | * Proper handling of machine word sizes |
12 | 1 | J. Moringen | * Some degree of data validation |
13 | 1 | J. Moringen | * Introspection support |
14 | 1 | J. Moringen | * Generated domain classes and (de)serializers |
15 | 1 | J. Moringen | ** Available in multiple programming languages without additional effort |
16 | 1 | J. Moringen | ** Inter-language consistency of domain classes and serialized representations |
17 | 1 | J. Moringen | |
18 | 1 | J. Moringen | 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 [[Writing_Converters|here]]) is reused. |
19 | 1 | J. Moringen | |
20 | 1 | J. Moringen | h2. Message Definition |
21 | 1 | J. Moringen | |
22 | 1 | J. Moringen | A @SimpleImage@ consists of |
23 | 1 | J. Moringen | |
24 | 1 | J. Moringen | * a width (a non-negative integer) |
25 | 1 | J. Moringen | * a height (a non-negative integer) |
26 | 1 | J. Moringen | * image data (an array of bytes) |
27 | 1 | J. Moringen | |
28 | 1 | J. Moringen | This structure is reflected in the protocol buffer message definition: |
29 | 1 | J. Moringen | |
30 | 1 | J. Moringen | source:trunk/cpp/core/examples/protobuf_converter/SimpleImage.proto |
31 | 1 | J. Moringen | |
32 | 1 | J. Moringen | h2. Code (C++) |
33 | 1 | J. Moringen | |
34 | 3 | J. Moringen | 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 below demonstrate how to do this and additionally send and receive @SimpleImage@ messages respectively: |
35 | 1 | J. Moringen | |
36 | 1 | J. Moringen | source:trunk/cpp/core/examples/protobuf_converter/sender.cpp |
37 | 1 | J. Moringen | source:trunk/cpp/core/examples/protobuf_converter/receiver.cpp |