andrewrk / genesis

Genesis Digital Audio Workstation
http://genesisdaw.org
Other
193 stars 20 forks source link

serialize and deserialize in a way that makes room for changes to file format #16

Closed andrewrk closed 9 years ago

andrewrk commented 9 years ago

Currently, serializing and deserializing operates on the fields serially and the code to serialize and deserialize is hard coded. This is problematic for two reasons:

Instead, each serializable thing should have a list of fields. Each field would have:

To serialize:

  1. write the number of fields
  2. iterate over the fields
    1. save space for 4 bytes to write the length of this field
    2. write the field identifier enum value (the "key")
    3. call the callback to get the pointer for the field
    4. based on the type of the field, call the appropriate serialize function using the field pointer
    5. go back and write the size in the space saved above

To deserialize:

  1. read the number of fields
  2. for as many as there are:
    1. read the length of this field
    2. read the field identifier
    3. if the field identifier is unrecognized, use the field length to skip this field. possibly make note of this situation and warn the user that the file contained unrecognized information.
    4. call the callback to get the pointer to the field
    5. based on the type of the field, call the appropriate deserialize function using the field pointer
    6. mark the field as found
  3. iterate over the fields
    1. if the field is not found, call the callback for setting the default value
    2. if the default value callback is null, then deserializing resulted in an invalid format error