Photon C++ Client API: Serializer Class Reference

Photon C++ Client API

Photon C++ Client API  4.1.12.2
Serializer Class Reference
Inheritance diagram for Serializer:
Collaboration diagram for Serializer:

Public Member Functions

const nByte * getData (void) const
 
int getSize (void) const
 
template<typename T >
bool push (const T &data)
 
template<typename T >
bool push (const T pData, typename Helpers::ArrayLengthType< T >::type arraySize)
 
template<typename T >
bool push (const T pData, const short *arraySizes)
 
JStringtoString (JString &retStr, bool withTypes=false) const
 
- Public Member Functions inherited from Base
virtual ~Base (void)
 
- Public Member Functions inherited from ToString
virtual ~ToString (void)
 
virtual JString typeToString (void) const
 
JString toString (bool withTypes=false) const
 

Additional Inherited Members

- Static Public Member Functions inherited from Base
static void setListener (const BaseListener *baseListener)
 
static int getDebugOutputLevel (void)
 
static bool setDebugOutputLevel (int debugLevel)
 
static const LogFormatOptionsgetLogFormatOptions (void)
 
static void setLogFormatOptions (const LogFormatOptions &options)
 

Detailed Description

The Serializer class serializes everything, that gets added to it, into a byte-array.

You can add data of suported types to a Serializer instance by calling push() on it, passing that data. A call to push() will automatically serialize the data before adding it to the instance. The content of a Serializer instance can be retrieved in form form of a byte array by calling getData().

If you do multiple calls to push() on the same instance, then the array retrieved by getData() will contain serialized representations of the passed data for all of them. The order in which these representations are stored will match the order of the calls.

The serialized data can be used to construct a DeSerializer instance from it, which provides the interface for retrieving the original datatypes from the byte array.

Remarks
The byte array that is returned by getData() has been serialized into a format, that can be deserialized by the Photon Server and other Photon Client platforms.

Member Function Documentation

§ getData()

const nByte * getData ( void  ) const
Remarks
The size of the array, that's returned by this function, can be retrieved by calling getSize() on the the same instance without adding new data to the instance between the calls to this function and to getSize().
Returns
the payload in form of a byte array

§ getSize()

int getSize ( void  ) const
Returns
the size in bytes of the payload

§ push() [1/3]

bool push ( const T &  data)

Adds a serialized representation of parameter data to the Serializer-instance on which it is called.

Template Parameters
Ttype of parameter data - has to be of one of the supported datatypes
Parameters
datadata to serialize
Returns
true if successful, false in case of an error

§ push() [2/3]

bool push ( const T  pData,
typename Helpers::ArrayLengthType< T >::type  arraySize 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This overload accepts singledimensional arrays and NULL-pointers passed for parameter pData.

Parameters
pDataarray of data to serialize
arraySizethe size of the value array

§ push() [3/3]

bool push ( const T  pData,
const short *  arraySizes 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This overload accepts multidimensional arrays and NULL-pointers passed for parameter val. The array, passed for parameter pData has to be a pointer of the correct abstraction level, meaning a normal pointer for a singledimensional array, a doublepointer for a twodimensional array, a triplepointer for a threedimensional array and so on.

Parameters
pDataarray of data to serialize
arraySizesthe sizes for every dimension of the array

§ toString()

JString & toString ( JString retStr,
bool  withTypes = false 
) const
virtual
Remarks
The cost of this function depends a lot on implementation details of the implementing subclasses, but for container classes this function can become quite expensive, if the instance contains huge amounts of data, as its cost for many container class implementations increases disproportionately high to the size of the payload.
Parameters
retStrreference to a string, to store the return-value in; the information, which is generated by this function, will be attached at the end of any eventually existing previous content of the string
withTypesset to true, to include type information in the generated string
Returns
a JString representation of the instance and its contents for debugging purposes.

Implements ToString.