C4 Engine
C4 Engine API Documentation

Packable::Pack

Defined in:  C4Packing.h
Packs an object's data.
Prototype

virtual void Pack(Packer& data, uint32 packFlags) const;

Parameters
data The Packer object into which the object data is written.
packFlags The packing flags.
Description
The Pack function is called when the engine needs to pack an object's data. The implementation of an override should first call the direct base class's Pack function and then use the functions of the Packer object to pack its own data.

Often, chunks are used when packing data so that the format of the data can be changed in different versions of the code without breaking backwards compatibility. A chunk is written to the output stream by first writing a ChunkHeader structure containing the chunk type and chunk size, and then writing the data belonging to the chunk. Each chunk must have a unique type within the set of chunks written by the particular implementation of the Pack function, and the size of each chunk must match the number of bytes of data written for the chunk.

After writing all of the chunks for an object, a special terminator chunk must be written to the output stream using the following code.
data << TerminatorChunk;
In the Packable::Unpack function, chunks are read by calling the Packable::UnpackChunkList function.
See Also

Packable::Unpack

Packable::UnpackChunkList

Packer

ChunkHeader