Serializer concepts

The serializer subsystem allows declaring serializeable types, that can be easily memberwise saved and loaded to various storage entities, such as registry, in a totally human-readable format. To declare such a structure, you should use the DECLARE_SERIALIZEABLE_STRUCx() macro, where x represents the number of fields. Alternatively, you can use the DECLARE_SERIALIZEABLE_STRUCx_I() macro to declare structures with default field values (will be placed into generated default constructor). The main idea of serializer is to provide a human-readable representation of certain internal program structures on some storage device (such as registry). The serializer should not be used for just saving some data into binary files. For that purpose C/C++ allow using extremely fast pointer-based save/load and other techniques. A serializeable structure will always have a default constructor and a constructor with parameters directly reflecting the field list. To serialize such structure use the SERIALIZE_OBJECT() macro. To deserialize - DESERIALIZE_OBJECT(). Here is a simple usage example:
DECLARE_SERIALIZEABLE_STRUC4(SomeParams,
							int,	SomeIntVal,
							unsigned,	SomeOtherIntVal,
							String, SomeStringVal,
							int,		SomeOtherVal);
//---- OR ----
DECLARE_SERIALIZEABLE_STRUC4_I(SomeParams,
							int,	SomeIntVal, 123,
							unsigned,	SomeOtherIntVal, 456,
							String, SomeStringVal, _T("InitialStringValue"),
							int,		SomeOtherVal, 789);
...
void SomeFunc()
{
	SomeParams params(1, 2, _T("TestString"), 4);
	RegistryKey key(HKEY_LOCAL_MACHINE, _T(...));
	key.SerializeObject(params);
	params = SomeParams();
	key.DeserializeObject(params);
}
You can see the serializer usage example in SAMPLES\WINDOWS\REGISTRY.
Remarks:
To develop your own class capable of serialization and deserialization of structure, you should add a _SerializerEntry method to it. Additionally you should add the serialization and deserialization methods. However, you can use the following macros to implement standard methods:
  • IMPLEMENT_STD_SERIALIZE_METHOD
  • IMPLEMENT_STD_DESERIALIZE_METHOD
  • IMPLEMENT_EMPTY_SERIALIZE_WRAPPER
  • IMPLEMENT_EMPTY_DESERIALIZE_WRAPPER
A typical call sequence for a serialization/deserialization operation is the following:
  • SomeSerializer::SerializeObject() is called by user code
  • SomeSerializer::BeginSerialization() performs some initialization, if required
  • SerializedType::__SERIALIZER_ITERATION_THUNK() iterates all over the fields of a structure
  • SomeSerializer::_SerializerEntry() is called for each serialized field
  • SomeSerializer::EndSerialization() performs some finalization, if required
Normally, most of the serializer calls are inlined, so that should not be a significant overhead. For details, see the BazisLib::Win32::RegistryEntry::_SerializerEntry.
Attention:
The serialized structures may only contain fields of the following types:
  • int
  • unsigned
  • bool
  • String
  • LONGLONG
  • ULONGLONG
SourceForge.net Logo