serialization library

Christian Kamm kamm at nospam.de
Thu Nov 9 03:46:21 PST 2006


> 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.  I think it's similar in many ways to a grammar  
> definition:

Check out
http://www.math.tu-berlin.de/~kamm/d/serializationchunk.zip

The chunk.d contains a hackish implementation of your chunk idea: when  
reading, it discards any chunk-parts it doesn't understand. Once it got to  
one it can process, it discards any other older-versioned chunks of the  
same type. When writing, it is possible to write legacy chunks for older  
versions.

To test it, you need to compile with -version=V1_SER for the 1.0 version  
of the program and with -version=V1_SER -version=V2_SER for the 2.0  
version of the program. Try running the v2 version, copy data_out to  
data_in and run the v1 version. (sorry for the complicated instructions,  
it's just a hack!)

Is this, approximately, what you had in mind? Personally, I'm not sure  
about all those classes required and how it would look in a larger  
project: maybe writing a version number and then having the user write a  
switch statement for it would have been ok too.

Christian



More information about the Digitalmars-d-announce mailing list