This utility helps You to keep and edit Your binary data in easy-to-edit XML form. The principle is simple:
...in a "definition" XML file. You specify what structures there are, what members they contain and how are the members encoded into binary.
My file consists of sequence of structures, each of which contains one-byte id, then three bytes with transparency RGB, then padding to 16 bytes followed by 48 chars long filename padded with zeroes and after all the records there is one terminating empty record etc.
You can define signedness and endianness for integer types, paddings for string types, default values for unspecified data, You may forbid specifying some data (see nouser="nouser" in XMLs below) etc.
Example:
types.xml: (defines some basic data types)
<types>
<typedef name="uint8" type="int" size="1" />
<typedef name="uint16" type="int" size="2" />
<typedef name="uint24" type="int" size="3" />
<typedef name="uint32" type="int" size="4" />
</types>
types-graphics.xml: (defines custom structures and data types)
<types>
<include type="xml" file="types.xml" />
<typedef name="surface-item" type="struct">
<item name="id" type="uint8" default="0" />
<item name="r" type="uint8" default="0" />
<item name="g" type="uint8" default="0" />
<item name="b" type="uint8" default="0" />
<item name="padding" type="string" size="12" padstr="$00" default="" nouser="nouser" />
<item name="file" type="string" size="48" padstr="$00" default="" />
</typedef>
<typedef name="root" type="struct">
<item name="surface" type="array" item="surface-item" />
<item name="surface-close" type="surface-item" nouser="nouser" />
</typedef>
</types>
.
...in human-readable and -writeable "data" XML file, structured as described in "definition" XML file:
data.xml:
<data types="types-graphics.xml" roottype="root">
<surface>
<id>1</id>
<file>rocket.png</file>
<!-- now goes the optional transparency color -->
<r>255</r>
<g>0</g>
<b>255</b>
</surface>
<surface>
<id>2</id>
<file>star.png</file>
<!-- ommited structure items get default values as defined in the datatype -->
</surface>
</data>
~~~~~~~
.
3. Generate the binary file
---------------------------
Whenever You need, You run the utility to convert the "data" XML file into **raw binary** using the "definition" XML file. This may be for example run as a post-build step of Your project etc.
php data2bin.php data.xml -o data.bin
.
4. Enjoy Your binary file
-------------------------
0010: 01 ff 00 ff 00 00 00 00 00 00 00 00 00 00 00 00 | ................
0020: 72 6f 63 6b 65 74 2e 70 6e 67 00 00 00 00 00 00 | rocket.png......
0030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
0040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
0050: 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
0060: 73 74 61 72 2e 70 6e 67 00 00 00 00 00 00 00 00 | star.png........
0070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
0080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
0090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
00a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
00b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
00c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
~~~~~~