jeudi 29 décembre 2011

When to use "ParentVersion" and when should I use "CurrentVersion" in pack/unpack method

If you're making your own, you should use CurrentVersion.  ParentVersion is likely a way to support older versions of packed information, or it's doing something fancy.  Here's an example of multiple version support in an unpack():

boolean unpack(container _packedClass)
{
int version = RunBase::getVersion(_packedClass); // this is a better way of conpeek(_packedClass, 1)
boolean ret = true;
;
switch (version)
{
case #CurrentVersion:
[version, #CurrentList] = _packedClass;
break;
case 2:
[version, startDate, endDate] = _packedClass;
break;
default:
ret = false;
break;
}
return ret;
}

It's just a switch on the version number so old data can be handled at least partially.

Aucun commentaire:

Enregistrer un commentaire