Introduction
An introduction to GPDS
What?
GPDS is a General Purpose Data Serializer implemented as a very small C++ library.
Features
- Leverages modern C++
- XML backend
- Easy to use
- MIT licensed (open source)
Why?
There are plenty of different existing serializers that allow producing XML output. However, a lot of them enforce a strong scheme on the generated XML. GPDS allows generating XML files with a generic data format that can also be used efficiently within other XML processing applications.
Consider the following class:
Or represented as C++ classes:
class color { public: std::string name; int red; int blue; int green; }; class car { public: std::string manufacturer; std::string model; int year_of_construction; color color; };
Many generic serializers with XML backends would generate the following XML (or similar):
<value> <value type="string">Jeep</value> <value type="string">Grand Cherokee</value> <value type="int">2009</value> <valuelist> <value type="string">Black</value> <value type="int">0</value> <value type="int">0</value> <value type="int">0</value> </valuelist> </value>
This works fine as long as the produced XML content is only used by the class/software that serialized and deserialized to/from it. However, if the produced XML should also be used outside of that class/software it's very tedious to work with as it's not clear what the values refer to.
The goal of GPDS is to produce XML that consists of a more generic structure that can also be used by other applications:
<car> <manufacturer>Jeep</manufacturer> <model>Grand Cherokee</model> <year_of_construction>2009</year_of_construction> <color> <name>Black</name> <red>0</red> <green>0</green> <blue>0</blue> </color> </car>
Furthermore, GPDS provides comments and attributes which allow to take advantage of more powerful XML tools/techniques when processing the generated XML outside of the application which (de)serializes it:
<car> <manufacturer>Jeep</manufacturer> <model>Grand Cherokee</model> <year_of_construction>2009</year_of_construction> <color name="Black" format="rgb"> <red depth="32">0</red> <green depth="32">0</green> <blue depth="32">0</blue> </color> </car>
GPDS also provides several configuration options to still annotate the element types if desired so:
<car> <manufacturer gpds:type="string">Jeep</manufacturer> <model gpds:type="string">Grand Cherokee</model> <year_of_construction gpds:type="int">2009</year_of_construction> <color gpds:type="nested"> <red gpds:type="int">0</red> <green gpds:type="int">0</green> <blue gpds:type="int">0</blue> </color> </car>