serialization library

Georg Wrede georg.wrede at nospam.org
Sat Nov 11 06:54:24 PST 2006


Bill Baxter wrote:
> Georg Wrede wrote:
> 
>> Bill Baxter wrote:
>>
>>> That is one thing I do like about boost::serialization.  With 
>>> basically one line of code I can switch between xml serialization and 
>>> binary serialization.  Only thing I didn't like was I couldn't figure 
>>> out how to keep some things binary.
>>
>> With a text file, you can tell what it is, even when the file has got 
>> misplaced or renamed, but with a binary it's pretty hopeless.
> 
> Having all the structure in ASCII is great, and maybe everything in 
> ASCII while you're debugging, but some things just don't work well as 
> ascii -- images, videos, audio files, 3D meshes, etc.  It makes sense to 
> have the structure annotated in ascii, but when it comes to storing raw 
> image data there's not much to be gained from storing that as a giant 
> ASCII string.  With the boost::serialization's XML I wanted to be able 
> to store that image as something like
> 
> <image width=1024 height=768 format=RGBA type="float">
>   [big hunk o raw binary image data]
> </image>
> 
> But I couldn't find any way to do that.

Probably just as well, since then a normal parser could not handle it.

Or if you didn't care, you could invent your own tag type, like

<image width=1024 height=768 format=RGBA type="float">
    <binarydata 
length=2359296>*^%&ÄÖ/Ä%&*^Ä&%Ö/*^(ÄÖ%&*^/Ö(*%^&ÄÖ/*(^ÄÖ&%*/ÄÖ(*^&%ÄÖ/(*^ÄÖ&%*(/ÄÖ%&*^ÄÖ(/*^&%ÄÖ/*^(ÄÖ&%*^/ÄÖ(%Ä/&(*^ÄÖ*^%ÄÖ/&*fffTHIS_REPRESENTS_2MEGS_OF_BINARY_CRAP_RIGHT_HEREfff^#¤ÄÖ%*^&"ÄÖ¤*^%"Ä#Ö¤*^%ÄÖ</binarydata 
 >
</image>

And, as you can see, you'd immediately lose the gains of having the 
thing as a text file because it gets unwieldy in a text viewer.

You could always serialize into a subdirectory and save the binaries 
(pictures, etc) as separate files there. Then the XML would only contain 
their names. (Not my invention. Java uses this, OpenOffice, and others.)

To save space you then zip the whole thing, thus getting your single 
serialization file, as originally wanted.

---

This can be very simple in the program, I remember seeing somewhere a 
library that made a zip file on disk look to the program like a 
subdirectory tree. Thus the zipping, creation of directories and other 
chores become transparent to the programmer.

Or you could just use the Phobos zip without a tree.



More information about the Digitalmars-d-announce mailing list