These examples show how to integrate Google Protocol Buffers with Ice for C++.
The Slice-to-C++ compiler, slice2cpp, supports metadata that allows you to specify an alternate mapping for a sequence type. The generated code uses the type name you supply in place of the sequence name. There are two prerequisites: you must add a metadata directive to include the header file containing the definition of your alternate type, and you must supply code that Ice can use to marshal and unmarshal instances of your alternate type.
For example, here is a metadata directive that specifies an alternate type name for a byte sequence:
["cpp:type:tutorial::Person"] sequence<byte> Person;
The type name specified in this example, tutorial::Person, corresponds to the C++ class generated by the Protocol Buffers compiler (protoc) for the definition shown below:
package tutorial;
message Person { ... };
We must also add the following metadata directive before any other Slice definitions to ensure the definition of tutorial::Person is visible. For example:
[["cpp:include:Person.pb.h"]]
Finally, we need to define the marshaling code. The header file StreamProtobuf.h in demo and test directories contains template definitions that can be used with any Protocol Buffer message types. We also need to include this code using a cpp:include metadata directive.
[["cpp:include:StreamProtobuf.h"]]
The makefiles require GNU make 3.80 or later. If your system does not come with GNU make, you can find information on how to acquire it at the following link:
http://www.gnu.org/software/make/
On OS X, the command-line demos require the Xcode Command Line Tools to be
installed (use xcode-select --install
to install them). The Ice Touch sample
programs require the [Ice Builder for Xcode][3].
If you've installed Ice in a non-standard location, you'll need to set the
ICE_HOME
environment variable with the path name of the
installation directory:
$ export ICE_HOME=~/testing/Ice
Review the settings in make/Make.rules
. For example, set PROTOBUF_HOME
to
reflect the installation directory of Protocol Buffers on your system.
When you're ready to start the build, run make
:
$ make
The projects for the programs require the Ice Builder for Visual Studio. Add this extension to Visual Studio before opening the solution.
Open the solution file Ice.protobuf.sln
to build the programs. This file
was created with Visual Studio 2012 and will be converted if you are using a newer
version of Visual Studio.
Select your target configuration: Debug or Release, Win32 or x64 (on supported x64 platforms). Right click on the desired demo/test in the Solution Explorer window and select "Build".
To run the demo, first change to the demo
directory and start the server:
$ server
In a separate window, start the client:
$ client
To run the test, change to the test
directory and run the python script found there.
$ cd test
$ python run.py