Open 3D Engine AzNetworking API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AzNetworking::ISerializer Class Referenceabstract

Interface class for all serializers to derive from. More...

#include <ISerializer.h>

Inherited by AzNetworking::DeltaSerializerApply, AzNetworking::DeltaSerializerCreate, AzNetworking::HashSerializer, AzNetworking::NetworkInputSerializer, AzNetworking::NetworkOutputSerializer, and AzNetworking::StringifySerializer.

Classes

struct  SerializeHelper
 
struct  SerializeHelper< false, false >
 
struct  SerializeHelper< true, false >
 
struct  SerializeHelper< true, true >
 

Public Member Functions

virtual bool IsValid () const
 
void Invalidate ()
 Mark the serializer as invalid.
 
virtual SerializerMode GetSerializerMode () const =0
 
virtual bool Serialize (bool &value, const char *name)=0
 
bool Serialize (char &value, const char *name, uint8_t minValue=AZStd::numeric_limits< uint8_t >::min(), uint8_t maxValue=AZStd::numeric_limits< uint8_t >::max())
 
virtual bool Serialize (int8_t &value, const char *name, int8_t minValue=AZStd::numeric_limits< int8_t >::min(), int8_t maxValue=AZStd::numeric_limits< int8_t >::max())=0
 
virtual bool Serialize (int16_t &value, const char *name, int16_t minValue=AZStd::numeric_limits< int16_t >::min(), int16_t maxValue=AZStd::numeric_limits< int16_t >::max())=0
 
virtual bool Serialize (int32_t &value, const char *name, int32_t minValue=AZStd::numeric_limits< int32_t >::min(), int32_t maxValue=AZStd::numeric_limits< int32_t >::max())=0
 
virtual bool Serialize (long &value, const char *name, long minValue=AZStd::numeric_limits< long >::min(), long maxValue=AZStd::numeric_limits< long >::max())=0
 
virtual bool Serialize (AZ::s64 &value, const char *name, AZ::s64 minValue=AZStd::numeric_limits< AZ::s64 >::min(), AZ::s64 maxValue=AZStd::numeric_limits< AZ::s64 >::max())=0
 
virtual bool Serialize (uint8_t &value, const char *name, uint8_t minValue=AZStd::numeric_limits< uint8_t >::min(), uint8_t maxValue=AZStd::numeric_limits< uint8_t >::max())=0
 
virtual bool Serialize (uint16_t &value, const char *name, uint16_t minValue=AZStd::numeric_limits< uint16_t >::min(), uint16_t maxValue=AZStd::numeric_limits< uint16_t >::max())=0
 
virtual bool Serialize (uint32_t &value, const char *name, uint32_t minValue=AZStd::numeric_limits< uint32_t >::min(), uint32_t maxValue=AZStd::numeric_limits< uint32_t >::max())=0
 
virtual bool Serialize (unsigned long &value, const char *name, unsigned long minValue=AZStd::numeric_limits< unsigned long >::min(), unsigned long maxValue=AZStd::numeric_limits< uint64_t >::max())=0
 
virtual bool Serialize (AZ::u64 &value, const char *name, AZ::u64 minValue=AZStd::numeric_limits< AZ::u64 >::min(), AZ::u64 maxValue=AZStd::numeric_limits< AZ::u64 >::max())=0
 
virtual bool Serialize (float &value, const char *name, float minValue=AZStd::numeric_limits< float >::min(), float maxValue=AZStd::numeric_limits< float >::max())=0
 
virtual bool Serialize (double &value, const char *name, double minValue=AZStd::numeric_limits< double >::min(), double maxValue=AZStd::numeric_limits< double >::max())=0
 
virtual bool SerializeBytes (uint8_t *buffer, uint32_t bufferCapacity, bool isString, uint32_t &outSize, const char *name)=0
 
template<typename TYPE >
bool Serialize (TYPE &value, const char *name)
 
virtual bool BeginObject (const char *name)=0
 
virtual bool EndObject (const char *name)=0
 
virtual const uint8_t * GetBuffer () const =0
 
virtual uint32_t GetCapacity () const =0
 
virtual uint32_t GetSize () const =0
 
virtual void ClearTrackedChangesFlag ()=0
 
virtual bool GetTrackedChangesFlag () const =0
 

Protected Attributes

bool m_serializerValid = true
 

Detailed Description

Interface class for all serializers to derive from.

ISerializer defines an abstract interface for visiting an object hierarchy and performing operations upon that hierarchy, typically reading from or writing data to the object hierarchy for reasons of persistence or network transmission.

While the most common types of serializers are provided by the AzNetworking framework, users can implement custom serializers and perform complex operations on any serializable structures. A few types native to AzNetworking, many of which relate to packets, demonstrate this.

Provided serializers include NetworkInputSerializer for writing an object model into a bytestream, NetworkOutputSerializer for writing to an object model, TrackChangesSerializer which is used to efficiently serialize objects without incurring significant copy or comparison overhead, and HashSerializer which can be used to generate a hash of all visited data which is important for automated desync detection.

Member Function Documentation

◆ BeginObject()

virtual bool AzNetworking::ISerializer::BeginObject ( const char *  name)
pure virtual

Begins serializing an object.

Parameters
namestring name of the object
Returns
boolean true on success, false for failure

Implemented in AzNetworking::DeltaSerializerCreate, AzNetworking::DeltaSerializerApply, AzNetworking::HashSerializer, AzNetworking::NetworkInputSerializer, AzNetworking::NetworkOutputSerializer, and AzNetworking::StringifySerializer.

◆ ClearTrackedChangesFlag()

virtual void AzNetworking::ISerializer::ClearTrackedChangesFlag ( )
pure virtual

This is a helper for network serialization. It clears the track changes flag internal to some serializers

Implemented in AzNetworking::DeltaSerializerCreate, AzNetworking::DeltaSerializerApply, AzNetworking::HashSerializer, AzNetworking::NetworkInputSerializer, AzNetworking::NetworkOutputSerializer, and AzNetworking::StringifySerializer.

◆ EndObject()

virtual bool AzNetworking::ISerializer::EndObject ( const char *  name)
pure virtual

Ends serializing an object.

Parameters
namestring name of the object
Returns
boolean true on success, false for failure

Implemented in AzNetworking::DeltaSerializerCreate, AzNetworking::DeltaSerializerApply, AzNetworking::HashSerializer, AzNetworking::NetworkInputSerializer, AzNetworking::NetworkOutputSerializer, and AzNetworking::StringifySerializer.

◆ GetBuffer()

virtual const uint8_t * AzNetworking::ISerializer::GetBuffer ( ) const
pure virtual

Returns a pointer to the internal serialization buffer.

Returns
pointer to the internal serialization buffer

Implemented in AzNetworking::DeltaSerializerCreate, AzNetworking::DeltaSerializerApply, AzNetworking::HashSerializer, AzNetworking::NetworkInputSerializer, AzNetworking::NetworkOutputSerializer, and AzNetworking::StringifySerializer.

◆ GetCapacity()

virtual uint32_t AzNetworking::ISerializer::GetCapacity ( ) const
pure virtual

Returns the total capacity serialization buffer in bytes.

Returns
total capacity serialization buffer in bytes

Implemented in AzNetworking::DeltaSerializerCreate, AzNetworking::DeltaSerializerApply, AzNetworking::HashSerializer, AzNetworking::NetworkInputSerializer, AzNetworking::NetworkOutputSerializer, and AzNetworking::StringifySerializer.

◆ GetSerializerMode()

virtual SerializerMode AzNetworking::ISerializer::GetSerializerMode ( ) const
pure virtual

Returns an enum the represents the serializer mode. returns WriteToObject if the serializer is writing values to the objects it visits, otherwise returns ReadFromObject

Returns
boolean true if the serializer is writing to objects that it visits

Implemented in AzNetworking::DeltaSerializerCreate, AzNetworking::DeltaSerializerApply, AzNetworking::HashSerializer, AzNetworking::NetworkInputSerializer, AzNetworking::NetworkOutputSerializer, and AzNetworking::StringifySerializer.

◆ GetSize()

virtual uint32_t AzNetworking::ISerializer::GetSize ( ) const
pure virtual

Returns the size of the data contained in the serialization buffer in bytes.

Returns
size of the data contained in the serialization buffer in bytes

Implemented in AzNetworking::DeltaSerializerCreate, AzNetworking::DeltaSerializerApply, AzNetworking::HashSerializer, AzNetworking::NetworkInputSerializer, AzNetworking::NetworkOutputSerializer, and AzNetworking::StringifySerializer.

◆ GetTrackedChangesFlag()

virtual bool AzNetworking::ISerializer::GetTrackedChangesFlag ( ) const
pure virtual

This is a helper for network serialization. It allows the owner of the serializer to query whether or not the serializer modified the state of an object during serialization

Returns
boolean true if the track changes flag is raised

Implemented in AzNetworking::DeltaSerializerCreate, AzNetworking::DeltaSerializerApply, AzNetworking::HashSerializer, AzNetworking::NetworkInputSerializer, AzNetworking::NetworkOutputSerializer, and AzNetworking::StringifySerializer.

◆ IsValid()

bool AzNetworking::ISerializer::IsValid ( ) const
inlinevirtual

Returns true if the serializer is valid and in a consistent state.

Returns
boolean true if the serializer is valid and in a consistent state

◆ Serialize() [1/15]

virtual bool AzNetworking::ISerializer::Serialize ( AZ::s64 &  value,
const char *  name,
AZ::s64  minValue = AZStd::numeric_limits< AZ::s64 >::min(),
AZ::s64  maxValue = AZStd::numeric_limits< AZ::s64 >::max() 
)
pure virtual

Serialize a signed 64-bit integer (long long).

Parameters
valuesigned 64-bit integer input value to serialize
namestring name of the value being serialized
minValuethe minimum value expected during serialization
maxValuethe maximum value expected during serialization
Returns
boolean true for success, false for failure

Implemented in AzNetworking::DeltaSerializerCreate, AzNetworking::DeltaSerializerApply, AzNetworking::HashSerializer, AzNetworking::NetworkInputSerializer, AzNetworking::NetworkOutputSerializer, and AzNetworking::StringifySerializer.

◆ Serialize() [2/15]

virtual bool AzNetworking::ISerializer::Serialize ( AZ::u64 &  value,
const char *  name,
AZ::u64  minValue = AZStd::numeric_limits< AZ::u64 >::min(),
AZ::u64  maxValue = AZStd::numeric_limits< AZ::u64 >::max() 
)
pure virtual

Serialize an unsigned 64-bit integer (unsigned long long).

Parameters
valueunsigned 64-bit integer input value to serialize
namestring name of the value being serialized
minValuethe minimum value expected during serialization
maxValuethe maximum value expected during serialization
Returns
boolean true for success, false for failure

Implemented in AzNetworking::DeltaSerializerCreate, AzNetworking::DeltaSerializerApply, AzNetworking::HashSerializer, AzNetworking::NetworkInputSerializer, AzNetworking::NetworkOutputSerializer, and AzNetworking::StringifySerializer.

◆ Serialize() [3/15]

virtual bool AzNetworking::ISerializer::Serialize ( bool &  value,
const char *  name 
)
pure virtual

Serialize a boolean.

Parameters
valueboolean input value to serialize
namestring name of the value being serialized
Returns
boolean true for success, false for serialization failure

Implemented in AzNetworking::DeltaSerializerCreate, AzNetworking::DeltaSerializerApply, AzNetworking::HashSerializer, AzNetworking::NetworkInputSerializer, AzNetworking::NetworkOutputSerializer, and AzNetworking::StringifySerializer.

◆ Serialize() [4/15]

bool AzNetworking::ISerializer::Serialize ( char &  value,
const char *  name,
uint8_t  minValue = AZStd::numeric_limits<uint8_t>::min(),
uint8_t  maxValue = AZStd::numeric_limits<uint8_t>::max() 
)
inline

Serialize a character.

Parameters
valuecharacter input value to serialize
namestring name of the value being serialized
minValuethe minimum value expected during serialization
maxValuethe maximum value expected during serialization
Returns
boolean true for success, false for failure

◆ Serialize() [5/15]

virtual bool AzNetworking::ISerializer::Serialize ( double &  value,
const char *  name,
double  minValue = AZStd::numeric_limits< double >::min(),
double  maxValue = AZStd::numeric_limits< double >::max() 
)
pure virtual

Serialize a 64-bit floating point number.

Parameters
value64-bit floating point input value to serialize
namestring name of the value being serialized
minValuethe minimum value expected during serialization
maxValuethe maximum value expected during serialization
Returns
boolean true for success, false for failure

Implemented in AzNetworking::DeltaSerializerCreate, AzNetworking::DeltaSerializerApply, AzNetworking::HashSerializer, AzNetworking::NetworkInputSerializer, AzNetworking::NetworkOutputSerializer, and AzNetworking::StringifySerializer.

◆ Serialize() [6/15]

virtual bool AzNetworking::ISerializer::Serialize ( float &  value,
const char *  name,
float  minValue = AZStd::numeric_limits< float >::min(),
float  maxValue = AZStd::numeric_limits< float >::max() 
)
pure virtual

Serialize a 32-bit floating point number.

Parameters
value32-bit floating point input value to serialize
namestring name of the value being serialized
minValuethe minimum value expected during serialization
maxValuethe maximum value expected during serialization
Returns
boolean true for success, false for failure

Implemented in AzNetworking::DeltaSerializerCreate, AzNetworking::DeltaSerializerApply, AzNetworking::HashSerializer, AzNetworking::NetworkInputSerializer, AzNetworking::NetworkOutputSerializer, and AzNetworking::StringifySerializer.

◆ Serialize() [7/15]

virtual bool AzNetworking::ISerializer::Serialize ( int16_t &  value,
const char *  name,
int16_t  minValue = AZStd::numeric_limits< int16_t >::min(),
int16_t  maxValue = AZStd::numeric_limits< int16_t >::max() 
)
pure virtual

Serialize a signed short.

Parameters
valuesigned short input value to serialize
namestring name of the value being serialized
minValuethe minimum value expected during serialization
maxValuethe maximum value expected during serialization
Returns
boolean true for success, false for failure

Implemented in AzNetworking::DeltaSerializerCreate, AzNetworking::DeltaSerializerApply, AzNetworking::HashSerializer, AzNetworking::NetworkInputSerializer, AzNetworking::NetworkOutputSerializer, and AzNetworking::StringifySerializer.

◆ Serialize() [8/15]

virtual bool AzNetworking::ISerializer::Serialize ( int32_t &  value,
const char *  name,
int32_t  minValue = AZStd::numeric_limits< int32_t >::min(),
int32_t  maxValue = AZStd::numeric_limits< int32_t >::max() 
)
pure virtual

Serialize a signed integer.

Parameters
valuesigned integer input value to serialize
namestring name of the value being serialized
minValuethe minimum value expected during serialization
maxValuethe maximum value expected during serialization
Returns
boolean true for success, false for failure

Implemented in AzNetworking::DeltaSerializerCreate, AzNetworking::DeltaSerializerApply, AzNetworking::HashSerializer, AzNetworking::NetworkInputSerializer, AzNetworking::NetworkOutputSerializer, and AzNetworking::StringifySerializer.

◆ Serialize() [9/15]

virtual bool AzNetworking::ISerializer::Serialize ( int8_t &  value,
const char *  name,
int8_t  minValue = AZStd::numeric_limits< int8_t >::min(),
int8_t  maxValue = AZStd::numeric_limits< int8_t >::max() 
)
pure virtual

Serialize a signed byte.

Parameters
valuesigned byte input value to serialize
namestring name of the value being serialized
minValuethe minimum value expected during serialization
maxValuethe maximum value expected during serialization
Returns
boolean true for success, false for failure

Implemented in AzNetworking::DeltaSerializerCreate, AzNetworking::DeltaSerializerApply, AzNetworking::HashSerializer, AzNetworking::NetworkInputSerializer, AzNetworking::NetworkOutputSerializer, and AzNetworking::StringifySerializer.

◆ Serialize() [10/15]

virtual bool AzNetworking::ISerializer::Serialize ( long &  value,
const char *  name,
long  minValue = AZStd::numeric_limits< long >::min(),
long  maxValue = AZStd::numeric_limits< long >::max() 
)
pure virtual

Serialize a signed long integer.

Parameters
valuesigned long integer input value to serialize
namestring name of the value being serialized
minValuethe minimum value expected during serialization
maxValuethe maximum value expected during serialization
Returns
boolean true for success, false for failure

Implemented in AzNetworking::DeltaSerializerCreate, AzNetworking::DeltaSerializerApply, AzNetworking::HashSerializer, AzNetworking::NetworkInputSerializer, AzNetworking::NetworkOutputSerializer, and AzNetworking::StringifySerializer.

◆ Serialize() [11/15]

template<typename TYPE >
bool AzNetworking::ISerializer::Serialize ( TYPE &  value,
const char *  name 
)
inline

Serialize interface for deducing whether or not TYPE is an enum or an object.

Parameters
valueobject instance to serialize
namestring name of the object
Returns
boolean true for success, false for serialization failure

◆ Serialize() [12/15]

virtual bool AzNetworking::ISerializer::Serialize ( uint16_t &  value,
const char *  name,
uint16_t  minValue = AZStd::numeric_limits< uint16_t >::min(),
uint16_t  maxValue = AZStd::numeric_limits< uint16_t >::max() 
)
pure virtual

Serialize an unsigned short.

Parameters
valueunsigned integer short value to serialize
namestring name of the value being serialized
minValuethe minimum value expected during serialization
maxValuethe maximum value expected during serialization
Returns
boolean true for success, false for failure

Implemented in AzNetworking::DeltaSerializerCreate, AzNetworking::DeltaSerializerApply, AzNetworking::HashSerializer, AzNetworking::NetworkInputSerializer, AzNetworking::NetworkOutputSerializer, and AzNetworking::StringifySerializer.

◆ Serialize() [13/15]

virtual bool AzNetworking::ISerializer::Serialize ( uint32_t &  value,
const char *  name,
uint32_t  minValue = AZStd::numeric_limits< uint32_t >::min(),
uint32_t  maxValue = AZStd::numeric_limits< uint32_t >::max() 
)
pure virtual

Serialize an unsigned integer.

Parameters
valueunsigned integer input value to serialize
namestring name of the value being serialized
minValuethe minimum value expected during serialization
maxValuethe maximum value expected during serialization
Returns
boolean true for success, false for failure

Implemented in AzNetworking::DeltaSerializerCreate, AzNetworking::DeltaSerializerApply, AzNetworking::HashSerializer, AzNetworking::NetworkInputSerializer, AzNetworking::NetworkOutputSerializer, and AzNetworking::StringifySerializer.

◆ Serialize() [14/15]

virtual bool AzNetworking::ISerializer::Serialize ( uint8_t &  value,
const char *  name,
uint8_t  minValue = AZStd::numeric_limits< uint8_t >::min(),
uint8_t  maxValue = AZStd::numeric_limits< uint8_t >::max() 
)
pure virtual

Serialize an unsigned byte.

Parameters
valueunsigned byte input value to serialize
namestring name of the value being serialized
minValuethe minimum value expected during serialization
maxValuethe maximum value expected during serialization
Returns
boolean true for success, false for failure

Implemented in AzNetworking::DeltaSerializerCreate, AzNetworking::DeltaSerializerApply, AzNetworking::HashSerializer, AzNetworking::NetworkInputSerializer, AzNetworking::NetworkOutputSerializer, and AzNetworking::StringifySerializer.

◆ Serialize() [15/15]

virtual bool AzNetworking::ISerializer::Serialize ( unsigned long &  value,
const char *  name,
unsigned long  minValue = AZStd::numeric_limits< unsigned long >::min(),
unsigned long  maxValue = AZStd::numeric_limits< uint64_t >::max() 
)
pure virtual

Serialize an unsigned long integer.

Parameters
valueunsigned long integer input value to serialize
namestring name of the value being serialized
minValuethe minimum value expected during serialization
maxValuethe maximum value expected during serialization
Returns
boolean true for success, false for failure

Implemented in AzNetworking::DeltaSerializerCreate, AzNetworking::DeltaSerializerApply, AzNetworking::HashSerializer, AzNetworking::NetworkInputSerializer, AzNetworking::NetworkOutputSerializer, and AzNetworking::StringifySerializer.

◆ SerializeBytes()

virtual bool AzNetworking::ISerializer::SerializeBytes ( uint8_t *  buffer,
uint32_t  bufferCapacity,
bool  isString,
uint32_t &  outSize,
const char *  name 
)
pure virtual

Serialize a raw set of bytes.

Parameters
bufferbuffer to serialize
bufferCapacitysize of the buffer
isStringtrue if the data being serialized is a string
outSizebytes serialized
namestring name of the object
Returns
boolean true for success, false for serialization failure

Implemented in AzNetworking::DeltaSerializerCreate, AzNetworking::DeltaSerializerApply, AzNetworking::HashSerializer, AzNetworking::NetworkInputSerializer, AzNetworking::NetworkOutputSerializer, and AzNetworking::StringifySerializer.


The documentation for this class was generated from the following files: