Serialisation
Serialisation is a scheme that allows the storage and retrieval of any VObject derived class, to a binary datastream. Serialisation is tightly coupled with the actual run-time type stored in the VObject base class.
Serialize() is a virtual function declared in VObject. It's implementation on a derived class is not mandatory, but the serialisation scheme will not work with that object unless the implementation is provided.
In general terms, if an object contains data which is purely run-time, then Serialize() need not be implemented. In such circumstances it may actually be safer not to implement it. Nevertheless, even if there is no direct requirement to serialise a newly declared class, but there is an expectation that a future subclass may require serialisation, then it is better to implement Serialize().
Where implemented, Serialize() works with a standard "VArchive" object. VArchive is capable of extracting and enumerating the content of any such object.
VArchive is described in more detail elsewhere, but it's most important feature is that it stores the run-time type returned by VObject::GetType() to the archive data stream in DumpObj(). The run-time type is then used when reconstructing nested VObjects, by CreateVObject() in ExtractObj(). This is the tightly coupled link mentioned inititally.
VArchive provides a variety of schemes for tranferring data with files on disk, binary images in memory, and communication ports. In addition, the archive scheme can replicate objects in memory. VArchive supports a range of checking algorithms (like CRC and sum), compression, digital signatures, private/public key encryption, and symmetric encryption.
There really are lots of reasons to use serialisation. |