B.1 How to Serialize
This section contains description of all steps necessary to add an de/serialization
feature to a class. More detailed information about de/serialization is
in section Serialization and Deserialization.
We have also prepared an example of de/serialization
methods. For better understanding we suggest to read also chapter about
base class TObj.
-
Implement the class as successor of the base class TObj.
-
Implement virtual method uint GetSerSize(BOOL subclass)
This method counts the length of type map for all attributes of the
class. Call methods TObj::GetSerSize<type>() for each attribute
of the class within this method.
-
Implement virtual method uint Serialize(BYTE** rawbytes,BOOL subclass)
This method serializes the class. Call methods TObj::Serialize<type>()
for each attribute of the class within it.
-
Implement deserialization constructor Classname(BYTE** rawbytes,uint
len,BOOL subclass)
This constructor creates a new object and initializes its attributes
to values decoded from the type map (argument rawbytes). Call methods TObj::Deserialize<type>()
to decode all values. It is necessary to call these methods in the same
order as the serialisation methods were called in the step 3.
Important notes:
-
The attributes of the predecessor classes should be also encoded in the
type map. So in the steps 2,3 and 4 call the proper methods of the direct
predecessor of the class.
-
If the class contains a subclass (e.g. an object constructed and destructed
by the class), then it can be also de/serialised. Whether to de/serialise
the subclass is specified by the argument subclass.
-
The argument rawbytes (steps 3 and 4) points to a pointer to the
buffer prepared for the type map. This pointer is automatically shifted
during the de/serialisation by the proper size. So it always points to
the first unused byte in the buffer.