serialization library
Walter Bright
newshound at digitalmars.com
Wed Nov 8 19:24:10 PST 2006
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.
Me, if practical, I like file formats to be in ascii so I can examine
them easily to see if they're working right.
More information about the Digitalmars-d-announce
mailing list