C4 Engine
C4 Engine API Documentation

class Packer

Defined in:  C4Packing.h
Represents an output serialization stream.
Definition

class Packer

Member Functions
Packer::WriteData Writes arbitrary data to the output stream.
Packer::WriteArray Writes an array of objects to the output stream.
Packer::BeginSection Begins measuring the size of a section of the output stream.
Packer::EndSection Ends measuring the size of a section of the output stream.
Packer::BeginChunk Writes a chunk type and begins measuring the size of a chunk in the output stream.
Packer::EndChunk Ends measuring the size of a chunk in the output stream.
Constructor

Packer(Package *package);

Parameters
package A pointer to the package that receives the packed data.
Description
A Packer object is passed to the Packable::Pack function when the engine needs to serialize data stored in an object. The Packer object encapsulates an output serialization stream, and the << operator is typically used to write data to it.
Overloaded Operators
template <typename type> Packer& operator <<(const type& data); Writes the data given by the data parameter to the output stream. The size of the data must be a multiple of four bytes.
Packer& operator <<(const bool& data); Writes the boolean value given by the data parameter to the output stream. (This operation always writes four bytes to the output stream.)
template <int32 len> Packer& operator <<(const String<len>& string); Writes the string given by the string parameter to the output stream.
Description
In order to maintain four-byte alignment, char and int16 types should not be serialized directly with the << operator. Instead, such values should first be copied or cast to a 32-bit type.

The bool type can safely be serialized directly because it is given special handling by the << operator that forces it to always occupy four bytes.

The machine type should never be serialized directly because it can be a different size on different platforms, and this difference can appear between 32-bit and 64-bit versions of the same operating system.
See Also

Unpacker

Packable