
Once you've gotten your message buffer sent to a receiving end (through a file or network interface), you can inflate and re-construct the same data structure using the MsgIn class. Note that the current marshaling code does not compensate for varying byte order across networks, but because all computers you'll be running this code on are little-endian, that probably doesn't matter to you.

The generated code makes use of the pre-defined visitors in MsgBase.h and MsgBase.cpp. It also needs you to generate a source file for your packets file, using perl -MSource Packets.pl. The generated source code is simple:
/* * This file was auto-generated on 2008-11-15 11:16:13 */ #include "Packets.h"

If you run the perl script, passing in the "Headers" module, it will print the declaration of your data structures to the console output. The included rules file lets you do this automatically as part of a Microsoft Visual Studio project, but for now, try doing it on the command line. If you don't have perl installed, get it either as part of Cygwin, or from ActiveState.

The idea is to describe your various data structures using a basic high-level language, and then generate the necessary code machinations to go between that description and byte streams automatically. This example uses a custom Perl script, although there are various standardized tools that can do the same thing (such as the ASN.1 standards suite).

This package provides simple generation of headers and source for marshaling binary data between C++ structs and byte streams. The nice thing about it is that you can easily extend the system to support generating property sheets, or going to/from XML, or one of a number of other things you want to do to data structures. You do so by just adding new visitor classes, without having to change the data structure code.

If you're using UDP for your networking, you will typically mark your packets with a "packet ID." That packet ID will be used to detect the case of duplicated UDP packets, and sometimes also dropped packets.