Mar 5 2011 · Random
Another project I worked on a long time ago but never released. The goal of Flexible Binary Format was to create a file format and library for dealing with (tree) structured binary data (in the same vein of what XML does for textual data). This was a reaction both to the verbose and non-binary-friendly nature of XML and to the ugly chunk-based structuring done in many binary file formats.
The code for the C++ library is now up.
I’ll do a high-level, quick-and-dirty tutorial in this post to show how things work.
Build a data tree
Attach a node to the data tree
Make a vector of nodes and sub-nodes
Note: We created 2 nodes on the same path (root/vertex). We access them individually using an index number within brackets.
Attach data to nodes
Once data is attached to a node, you can’t attach a sub-node to it.
(i.e. data is stored on the leaves of the data tree)
The following methods of FlexibleBinaryFormat::TreeBuilder are available to attach data to a node:
Write the data tree out to a file
Read a data tree from a file
Read data from a node
double v0xyz = dt2.GetData<double>("root/vertex/xyz", 0);
// second arg is always 0;
// arg is a leftover from some deprecated stuff in older versions and will be removed