serialization library
Georg Wrede
georg.wrede at nospam.org
Fri Nov 10 16:00:37 PST 2006
Bill Baxter wrote:
> Walter Bright wrote:
>
>> Bill Baxter wrote:
>>
>>> How do you fix it? Very simple really. Just store the file as a
>>> series of chunks with fixed length headers, and each header contains
>>> the length of the data in that chunk. If you get a chunk header with
>>> a tag you don't understand, just ignore it. A particular chunk can
>>> have sub-chunks too.
>>
>>
>> Evolution of a file format:
>>
>> 1.0: Just spew the struct contents out into a file using something
>> like fwrite().
>>
>> 2.0: Oops! Need to update 1.0 and retain backwards compatibility.
>> Solution: 2.0 files put out 'illegal' values into the 1.0 format to
>> signal it's a 2.0 file.
>>
>> 3.0: Doh! Find another set of illegal 2.0 values. This time, get
>> smarter and have another field with a version number in it.
>>
>> 4.0: Get smart and implement your suggestion, so you can have both
>> backwards and *forwards* compatibility.
>>
>> Think I'm joking? Just look at a few! Everyone learns this the hard way.
>
>
> I guess I'm no exception. ;-) I've been through the 4 step program a
> few times myself.
>
>> Me, if practical, I like file formats to be in ascii so I can examine
>> them easily to see if they're working right.
Heh, something Microsoft is only now trying to learn. And Unix guys knew
right from the start. Even most of the communications protocols are in text.
> 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.
And of course you might look at a few languages ( ~ fileformats)
especially made for serializing.
YAML looks very clean, and is easily readable by humans (XML is not)
JSON looks like ECMA script
The following page, although only vaguely related, gives an excellent
intro to the ideology, at the center:
http://mike.teczno.com/json.html
With these, you'll be right where Walter was talking about.
More information about the Digitalmars-d-announce
mailing list