PDG engine v0.9.5
 All Classes Namespaces Functions Variables Groups Pages
Public Member Functions | List of all members
Deserializer Class Reference

deserialize data from a serialized data stream More...

Public Member Functions

number deserialize_1 ()
 deserialize 1 signed byte More...
 
number deserialize_1u ()
 deserialize 1 unsigned byte More...
 
number deserialize_2 ()
 deserialize 2 signed bytes More...
 
number deserialize_2u ()
 deserialize 2 unsigned bytes More...
 
number deserialize_3u ()
 deserialize 3 unsigned bytes More...
 
number deserialize_4 ()
 deserialize 4 signed bytes More...
 
number deserialize_4u ()
 deserialize 4 unsigned bytes More...
 
number deserialize_8 ()
 deserialize 8 signed bytes More...
 
number deserialize_8u ()
 deserialize 8 unsigned bytes More...
 
boolean deserialize_bool ()
 deserialize a 1 bit boolean value More...
 
Color deserialize_color ()
 deserialize a Color More...
 
number deserialize_d ()
 deserialize a double precision floating point value More...
 
number deserialize_f ()
 deserialize a single precision floating point value More...
 
MemBlock deserialize_mem ()
 deserialize arbitrary binary data More...
 
number deserialize_memGetLen ()
 get size of mem block that is next in the stream More...
 
ISerializable deserialize_obj ()
 deserialize an object More...
 
Offset deserialize_offset ()
 deserialize an Offset More...
 
Point deserialize_point ()
 deserialize a Point More...
 
Quad deserialize_quad ()
 deserialize a Quad More...
 
Rect deserialize_rect ()
 deserialize a Rect More...
 
object deserialize_ref ()
 
RotatedRect deserialize_rotr ()
 deserialize a RotatedRect More...
 
string deserialize_str ()
 deserialize an arbitrary string More...
 
number deserialize_uint ()
 deserialize an unsigned number More...
 
Vector deserialize_vector ()
 deserialize a Vector More...
 
 setDataPtr (BinaryString data)
 set the serialized data More...
 
 setDataPtr (MemBlock data)
 set the serialized data More...
 

Detailed Description

deserialize data from a serialized data stream

Precondition
API Stability: 3 - Stable. The API has proven satisfactory, but cleanup in the underlying code may cause minor changes. Backwards-compatibility is guaranteed.

Deserializer retrieves and reconstructs complex data from a serialized data stream in memory. The stream must have been created by a Serializer. It will correctly rebuild entire object hierarchies, creating new objects of the correct classes without duplication as needed. In order to deserialize objects, you must register them using pdg.registerSerializableClass. Built in serializable objects, such as Sprites and SpriteLayers are pre-registered.

The data stream format written by Serializer is platform neutral, so it can be decoded on a different platform (or even language) than it was created with. Thus it is suitable for saved game files and network messages between client and server.

Remarks
The NetConnection object automatically reconstructs ISerializable objects and gives them to you in your receive callback function.

Deserializer looks for tags written by Serializer at key points in the stream to verify things haven't gotten out of sync. However, if you want your serialized data streams to be versioned, you will have to add that yourself; either on a per object/message basis or for an entire saved stream.

Method Groups

Warning
You must deserialize data in the same order it was serialized and with the deserialize call that corresponds to the serialize call used. Example:
// correct serialization
function serializeStuff(ser) {
ser.serialize_1u(val1);
ser.serialize_2u(val2);
ser.serialize_1(signedVal);
ser.serialize_uint(unsignedVal);
ser.serialize_str(myMessage);
}
// correct deserialization for above
// each call matches in order and type
function deserializeStuff(des) {
val1 = des.serialize_1u();
val2 = des.serialize_2u();
signedVal = des.serialize_1();
unsignedVal = des.serialize_uint();
myMessage = des.serialize_str();
}
See Also
Serializer
ISerializable
pdg.registerSerializableClass

Member Function Documentation

deserialize_1 ( )

deserialize 1 signed byte

Read a one byte signed value from the data stream.

Returns
a number in the range of −127 to 127
See Also
Serializer.serialize_1
deserialize_1u ( )

deserialize 1 unsigned byte

Read an unsigned one byte value from the data stream.

Returns
a number in the range of 0 to 255
See Also
Serializer.serialize_1u
deserialize_2 ( )

deserialize 2 signed bytes

Read a signed two byte value from the data stream.

Returns
a number in the range of −32,767 to 32,767
See Also
Serializer.serialize_2
deserialize_2u ( )

deserialize 2 unsigned bytes

Read an unsigned two byte value from the data stream.

Returns
a number in the range of 0 to 65,535
See Also
Serializer.serialize_2u
deserialize_3u ( )

deserialize 3 unsigned bytes

Read an unsigned three byte value from the data stream.

Returns
a number in the range of 0 to 16,777,216
See Also
Serializer.serialize_3u
deserialize_4 ( )

deserialize 4 signed bytes

Read a signed four byte value from the data stream.

Returns
a number in the range of −2,147,483,647 to 2,147,483,647
See Also
Serializer.serialize_4
deserialize_4u ( )

deserialize 4 unsigned bytes

Read an unsigned four byte value from the data stream.

Returns
a number in the range of 0 to 4,294,967,295
See Also
Serializer.serialize_4u
deserialize_8 ( )

deserialize 8 signed bytes

Read a signed eight byte value from the data stream.

Returns
a number in the range of −9,223,372,036,854,775,807 to 9,223,372,036,854,775,807
See Also
Serializer.serialize_8
deserialize_8u ( )

deserialize 8 unsigned bytes

Read an unsigned eight byte value from the data stream.

Returns
a number in the range of 0 to 18,446,744,073,709,551,615
See Also
Serializer.serialize_8u
deserialize_bool ( )

deserialize a 1 bit boolean value

Read an one bit boolean (true/false) value from the data stream.

Returns
a boolean, either true or false
See Also
Serializer.serialize_bool
deserialize_color ( )

deserialize a Color

Read a Color value from the data stream.

Returns
a Color
See Also
Serializer.serialize_color
deserialize_d ( )

deserialize a double precision floating point value

Read an eight byte double precision floating point value from the data stream.

Returns
a number in the range of 10−308 to 10308, with 17 significant digits
See Also
Serializer.serialize_d
deserialize_f ( )

deserialize a single precision floating point value

Read a four byte single precision floating point value from the data stream.

Returns
a number in the range of 10−38 to 1038, with 9 significant digits
See Also
Serializer.serialize_f
deserialize_mem ( )

deserialize arbitrary binary data

Read a chunk of arbitrary binary data from the stream into a MemBlock. The amount of data that will be read can be discovered by calling deserialize_memGetLen() before you call deserialize_mem(). If you want to get the size afterwards, you must call MemBlock.getDataSize() on the data returned

Remarks
there is no way to read only part of the binary data
Returns
an arbitrary block of binary data as a MemBlock
See Also
Serializer.serialize_mem
deserialize_memGetLen
MemBlock.getDataSize
deserialize_memGetLen ( )

get size of mem block that is next in the stream

Reports the size of the MemBlock that will be created by an immediate call to deserialize_mem(). If you want to get the size after you've made the deserialize_mem() call, use MemBlock.getDataSize()

Returns
the size in bytes of the MemBlock that will be created
See Also
derserialize_mem
MemBlock.getDataSize
deserialize_obj ( )

deserialize an object

This deserializes a object and all its data into the stream. It does this by instantiating a new object of the correct type, then calling that object's deserialize method. The object's deserialize() in turn calls deserialize methods for each of the object's data members. If the given object's data members include other ISerializable objects, then deserialize_obj() is called recursively to deserialize those objects.

The Deserializer keeps track of what objects have already been deserialized from the stream. So if deserialize_obj() is called for an object that has already been deserialized, it just returns a reference to the existing object rather than creating a duplicate object

See Also
Serializer.serialize_obj
ISerializable
deserialize_offset ( )

deserialize an Offset

Read an Offset's x and y values value from the data stream.

Returns
an Offset
See Also
Serializer.serialize_offset
deserialize_point ( )

deserialize a Point

Read a Point value from the data stream.

Returns
a Point
See Also
Serializer.serialize_point
deserialize_quad ( )

deserialize a Quad

Read a Quad (4 point) value from the data stream.

Returns
a Quad
See Also
Serializer.serialize_quad
deserialize_rect ( )

deserialize a Rect

Read a Rect value from the data stream.

Returns
a Rect
See Also
Serializer.serialize_rect
object deserialize_ref ( )
deserialize_rotr ( )

deserialize a RotatedRect

Read a RotatedRect value from the data stream.

Returns
a RotatedRect
See Also
Serializer.serialize_rotr
deserialize_str ( )

deserialize an arbitrary string

Read an arbitrary string from the stream.

Returns
a Unicode string
See Also
Serializer.serialize_str
deserialize_uint ( )

deserialize an unsigned number

Read an unsigned value from the data stream.

Warning
this can only deserialize values encoded with serialize_uint, not with serialize_4u even though the range is identical
Returns
a number in the range of 0 to 4,294,967,295
See Also
Serializer.serialize_uint
deserialize_vector ( )

deserialize a Vector

Read a Vector value from the data stream.

Returns
a Vector
See Also
Serializer.serialize_vector
setDataPtr ( BinaryString  data)

set the serialized data

Set the data block that should be deserialized. It should have been created at some point by a pdg.Serializer.

Deprecated:
Node.js maintainers have deprecated BinaryString, so it may not be around in future versions
Parameters
datathe BinaryString object with the serialized data
See Also
setDataPtr(MemBlock)
Serializer.getDataPtr
setDataPtr ( MemBlock  data)

set the serialized data

Set the data block that should be deserialized. It should have been created at some point by a pdg.Serializer.

Parameters
datathe MemBlock object with the serialized data
See Also
setDataPtr(BinaryString)
Serializer.getDataPtr

User Comments