Photon C++ Client API  5.0.7.3
Public Member Functions | List of all members
Serializer Class Reference
Inheritance diagram for Serializer:
Inheritance graph
[legend]
Collaboration diagram for Serializer:
Collaboration graph
[legend]

Public Member Functions

 Serializer (nByte protocol=SerializationProtocol::DEFAULT)
 
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, int arraySize)
 
template<typename T >
bool push (const T pData, const int *arraySizes)
 
virtual JStringtoString (JString &retStr, bool withTypes=false) const
 
virtual JStringtoString (JString &retStr, bool withTypes=false) const=0
 
JString toString (bool withTypes=false) const
 
- Public Member Functions inherited from Base
virtual ~Base (void)=0
 
- Public Member Functions inherited from LoggingBase< Base >
virtual ~LoggingBase (void)=0
 
- 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 LoggingBase< Base >
static void setListener (const BaseListener *pBaseListener)
 
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,
int  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 int *  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() [1/3]

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.

◆ toString() [2/3]

toString
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.

◆ toString() [3/3]

JString toString

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

Parameters
withTypesset to true, to include type information in the generated string
Returns
a JString representation of the instance and its contents for debugging purposes.
See also
JString