Pixel Dust Game Engine  v0.9.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Serializer Class Reference

A container for static methods that do the actual serialization. More...

Inheritance diagram for Serializer:
Inheritance graph
[legend]
Collaboration diagram for Serializer:
Collaboration graph
[legend]

Public Member Functions

virtual void serialize_8u (uint64 val)
 Serialize an 8 byte (64 bit) value into a buffer.
 
virtual void serialize_4u (uint32 val)
 Serialize a 4 byte (32 bit) value into a buffer.
 
virtual void serialize_3u (uint32 val)
 Serialize a 3 byte (24 bit) value into a buffer.
 
virtual void serialize_2u (uint16 val)
 Serialize a 2 byte (16 bit) value into a buffer.
 
virtual void serialize_1u (uint8 val)
 Serialize an 1 byte (8 bit) value into a buffer.
 
virtual void serialize_bool (bool val)
 Serialize a boolean (1 bit) value into a buffer.
 
virtual void serialize_uint (uint32 num)
 Serialize an unsigned integer value into a buffer.
 
virtual void serialize_str (const char *str)
 Serialize an string value into a buffer.
 
virtual void serialize_mem (const void *mem, uint32 memLen)
 Serialize an arbitrary block of memory.
 
virtual void serialize_obj (const ISerializable *obj)
 Serialize a serializable object.
 
virtual void serialize_color (const Color &c)
 Serialize a pdg::Color.
 
virtual void serialize_offset (const Offset &o)
 Serialize a pdg::Offset.
 
virtual void serialize_rect (const Rect &r)
 Serialize a pdg::Rect.
 
virtual void serialize_rotr (const RotatedRect &rr)
 Serialize a pdg::RotatedRect.
 
virtual void serialize_quad (const Quad &q)
 Serialize a pdg::Quad.
 
virtual uint32 sizeof_bool (bool val) const
 How many bytes are used to serialize a particular boolean value.
 
virtual uint32 sizeof_uint (uint32 num) const
 How many bytes are used to serialize a particular unsigned integer value.
 
virtual uint32 sizeof_str (const char *str) const
 How many bytes are used to serialize a particular string.
 
virtual uint32 sizeof_mem (const void *mem, uint32 memLen) const
 How many bytes are used to serialize a particular block of memory.
 
virtual uint32 sizeof_obj (const ISerializable *obj)
 How many bytes are used to serialize a particular object, including tags and size data.
 
virtual uint32 sizeof_color (const Color &c) const
 How many bytes are used to serialize a particular pdg::Color value.
 
virtual uint32 sizeof_offset (const Offset &o) const
 How many bytes are used to serialize a particular pdg::Offset, Point or Vector value.
 
virtual uint32 sizeof_rect (const Rect &r) const
 How many bytes are used to serialize a particular pdg::Rect value.
 
virtual uint32 sizeof_rotr (const RotatedRect &rr) const
 How many bytes are used to serialize a particular pdg::RotatedRect value.
 
virtual uint32 sizeof_quad (const Quad &q) const
 How many bytes are used to serialize a particular pdg::Quad value.
 
uint8 * getDataPtr ()
 
size_t getDataSize ()
 
 Serializer ()
 
virtual ~Serializer ()
 
- Public Member Functions inherited from ISerializer
void serialize_8 (int64 val)
 
void serialize_4 (int32 val)
 
void serialize_2 (int16 val)
 
void serialize_1 (int8 val)
 
void serialize_f (float val)
 Serialize a floating point value into a buffer.
 
void serialize_d (double val)
 Serialize a double precision floating point value into a buffer.
 
void serialize_point (const Point &p)
 Serialize a pdg::Point.
 
void serialize_vector (const Vector &v)
 Serialize a pdg::Vector.
 
void serialize_string (const std::string &str)
 Serialize a string value from a std::string.
 
template<typename T >
void serialize_ref (const T *obj) MAY_THROW(unknown_object)
 Serialize a reference to a non-serializable object.
 
uint32 sizeof_8u (uint64 val) const
 
uint32 sizeof_8 (int64 val) const
 
uint32 sizeof_4u (uint32 val) const
 
uint32 sizeof_4 (int32 val) const
 
uint32 sizeof_3u (uint32 val) const
 
uint32 sizeof_2u (uint16 val) const
 
uint32 sizeof_2 (int16 val) const
 
uint32 sizeof_1u (uint8 val) const
 
uint32 sizeof_1 (int8 val) const
 
uint32 sizeof_vector (const Vector &v) const
 
uint32 sizeof_point (const Point &p) const
 
uint32 sizeof_string (const std::string &str) const
 How many bytes are used to serialize a particular std::string.
 
template<typename T >
uint32 sizeof_ref (const T *obj) const MAY_THROW(unknown_object)
 
ISerializersetSendTags (bool sendThem)
 Turn on or off the sync tags for this steam.
 

Protected Member Functions

virtual char * statusDump (int hiliteBytes=0)
 
virtual void startMark ()
 
virtual int bytesFromMark ()
 
virtual void serialize_ptr (const void *ptr)
 
virtual uint32 sizeof_ptr (const void *ptr) const
 
virtual void ensureSpace (size_t bytes)
 
- Protected Member Functions inherited from ISerializer
 ISerializer ()
 

Protected Attributes

uint8 * mDataPtr
 
uint8 * mDataEnd
 
uint8 * p
 
size_t mAllocatedSize
 
size_t mBlockSize
 
std::vector< const
ISerializable * > 
mSerializedInstances
 
std::vector< const
ISerializable * > 
mSerializedSizeInstances
 
int mSerializeObjDepth
 
uint8 * mMark
 
uint8 * mLastBoolPtr
 
int mBoolBitOffset
 
int mBoolSizeCount
 
bool mUsingTags
 
- Protected Attributes inherited from ISerializer
bool mSendTags
 

Additional Inherited Members

- Static Public Attributes inherited from ISerializer
static int s_TraceDepth
 
static bool s_DebugMode
 

Detailed Description

A container for static methods that do the actual serialization.

Constructor & Destructor Documentation

virtual ~Serializer ( )
virtual

Member Function Documentation

virtual int bytesFromMark ( )
protectedvirtual

Implements ISerializer.

virtual void ensureSpace ( size_t  bytes)
protectedvirtual
uint8* getDataPtr ( )
inline
size_t getDataSize ( )
inline
virtual void serialize_1u ( uint8  val)
virtual

Serialize an 1 byte (8 bit) value into a buffer.

internal pointer gets advanced by 1 byte

Parameters
valthe 8 bit value to serialize

Implements ISerializer.

virtual void serialize_2u ( uint16  val)
virtual

Serialize a 2 byte (16 bit) value into a buffer.

internal pointer gets advanced by 2 bytes

Parameters
valthe 16 bit value to serialize

Implements ISerializer.

virtual void serialize_3u ( uint32  val)
virtual

Serialize a 3 byte (24 bit) value into a buffer.

internal pointer gets advanced by 3 bytes

Parameters
valthe 24 bit value to serialize

Implements ISerializer.

virtual void serialize_4u ( uint32  val)
virtual

Serialize a 4 byte (32 bit) value into a buffer.

internal pointer gets advanced by 4 bytes

Parameters
valthe 32 bit value to serialize

Implements ISerializer.

virtual void serialize_8u ( uint64  val)
virtual

Serialize an 8 byte (64 bit) value into a buffer.

internal pointer gets advanced by 8 bytes

Parameters
valthe 64 bit value to serialize

Implements ISerializer.

virtual void serialize_bool ( bool  val)
virtual

Serialize a boolean (1 bit) value into a buffer.

internal pointer gets advanced by 1 or 0 bytes, depending on the bytes needed to store the value

Parameters
valthe boolean to serialize This is optimized for series of boolean values, so that between 1 and 8 bools serialized sequentially only use a single byte

Implements ISerializer.

virtual void serialize_color ( const Color c)
virtual

Serialize a pdg::Color.

internal pointer gets advanced by total size of serialized color

Parameters
cthe Color to serialize

Implements ISerializer.

virtual void serialize_mem ( const void *  mem,
uint32  memLen 
)
virtual

Serialize an arbitrary block of memory.

internal pointer gets advanced by serialized size of the memory block

Parameters
valthe 8 bit value to serialize

Implements ISerializer.

virtual void serialize_obj ( const ISerializable obj)
virtual

Serialize a serializable object.

internal pointer gets advanced by total size of serialized obj

Parameters
objthe object to serialize This works by writing the object's unique tag, then serializing the size of the object via obj->getSerializedSize() and then finally calling obj->serialize() to actually serialize the object's data

Implements ISerializer.

virtual void serialize_offset ( const Offset o)
virtual

Serialize a pdg::Offset.

internal pointer gets advanced by total size of serialized Offset

Parameters
othe Offset to serialize

Implements ISerializer.

virtual void serialize_ptr ( const void *  ptr)
protectedvirtual

Implements ISerializer.

virtual void serialize_quad ( const Quad q)
virtual

Serialize a pdg::Quad.

internal pointer gets advanced by total size of serialized quad

Parameters
qthe Quad to serialize

Implements ISerializer.

virtual void serialize_rect ( const Rect r)
virtual

Serialize a pdg::Rect.

internal pointer gets advanced by total size of serialized rect

Parameters
rthe Rect to serialize

Implements ISerializer.

virtual void serialize_rotr ( const RotatedRect rr)
virtual

Serialize a pdg::RotatedRect.

internal pointer gets advanced by total size of serialized rect

Parameters
rthe Rect to serialize

Implements ISerializer.

virtual void serialize_str ( const char *  str)
virtual

Serialize an string value into a buffer.

internal pointer gets advanced by serialized size of string

Parameters
valthe 8 bit value to serialize

Implements ISerializer.

virtual void serialize_uint ( uint32  num)
virtual

Serialize an unsigned integer value into a buffer.

internal pointer gets advanced by 1, 3 or 5 bytes, depending on the bytes needed to store the value

Parameters
numthe unsigned value to serialize

Implements ISerializer.

virtual uint32 sizeof_bool ( bool  val) const
virtual

How many bytes are used to serialize a particular boolean value.

Implements ISerializer.

virtual uint32 sizeof_color ( const Color c) const
virtual

How many bytes are used to serialize a particular pdg::Color value.

Implements ISerializer.

virtual uint32 sizeof_mem ( const void *  mem,
uint32  memLen 
) const
virtual

How many bytes are used to serialize a particular block of memory.

Implements ISerializer.

virtual uint32 sizeof_obj ( const ISerializable obj)
virtual

How many bytes are used to serialize a particular object, including tags and size data.

Since objects are only serialized once, it is critical that you call this on objects the same order that you actually serialize those object. The first call for a particular object will return the number of bytes for the serialized object stream plus tag overhead. Successive calls will return the number of bytes used to store a reference to the object, usually a much smaller number A NULL object pointer will always take a constant number of bytes needed for the null object tag

Implements ISerializer.

virtual uint32 sizeof_offset ( const Offset o) const
virtual

How many bytes are used to serialize a particular pdg::Offset, Point or Vector value.

Implements ISerializer.

virtual uint32 sizeof_ptr ( const void *  ptr) const
protectedvirtual

Implements ISerializer.

virtual uint32 sizeof_quad ( const Quad q) const
virtual

How many bytes are used to serialize a particular pdg::Quad value.

Implements ISerializer.

virtual uint32 sizeof_rect ( const Rect r) const
virtual

How many bytes are used to serialize a particular pdg::Rect value.

Implements ISerializer.

virtual uint32 sizeof_rotr ( const RotatedRect rr) const
virtual

How many bytes are used to serialize a particular pdg::RotatedRect value.

Implements ISerializer.

virtual uint32 sizeof_str ( const char *  str) const
virtual

How many bytes are used to serialize a particular string.

Implements ISerializer.

virtual uint32 sizeof_uint ( uint32  num) const
virtual

How many bytes are used to serialize a particular unsigned integer value.

Implements ISerializer.

virtual void startMark ( )
protectedvirtual

Implements ISerializer.

virtual char* statusDump ( int  hiliteBytes = 0)
protectedvirtual

Implements ISerializer.

Member Data Documentation

size_t mAllocatedSize
protected
size_t mBlockSize
protected
int mBoolBitOffset
protected
int mBoolSizeCount
mutableprotected
uint8* mDataEnd
protected
uint8* mDataPtr
protected
uint8* mLastBoolPtr
protected
uint8* mMark
protected
std::vector<const ISerializable*> mSerializedInstances
protected
std::vector<const ISerializable*> mSerializedSizeInstances
protected
int mSerializeObjDepth
protected
bool mUsingTags
protected
uint8* p
protected