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 <<(constbool& 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.