CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::Deserializer Class Referenceabstract

The deserializer class has basic support for reflection-based deserializers. More...

#include <CeresEngine/Serialization/Deserializer.hpp>

Inheritance diagram for CeresEngine::Deserializer:
CeresEngine::IDeserializer CeresEngine::BinaryDeserializer CeresEngine::JSONDeserializer

Classes

struct  Array
 A context struct that contains information for the decoding of an array. More...
 
struct  Map
 A context struct that contains information for the decoding of a map. More...
 
struct  Object
 A context struct that contains information for the decoding of an object. More...
 
struct  Property
 A context struct that contains information for the decoding of a property. More...
 

Public Member Functions

 Deserializer (const SerializationContext &context=SerializationContext::getDefault())
 Creates a new deserializer with a custom context.
 
 ~Deserializer () noexcept override
 Destroys the deserializer.
 
Optional< Boxdeserialize () final
 Deserializes a value from a stream of bytes read from dataStream.
 
virtual void resetState ()
 Resets the deserializer state.
 
virtual Box decode (Box &&existingObject={})=0
 Starts decoding from the deserializer implementation.
 
- Public Member Functions inherited from CeresEngine::IDeserializer
virtual ~IDeserializer ()=default
 

Public Attributes

const SerializationContextcontext
 A shared context that contains a context for the deserializer.
 
DeserializerState state
 An object that stores context for the deserializer.
 

Protected Member Functions

Object beginObject (const SerializedObjectMetadata &metadata, Box &&existingObject={})
 Notifies the deserializer that a new object is starting deserialization.
 
Box endObject (Object &object)
 Notifies the deserializer that an object has ended deserialization.
 
Property beginObjectProperty (const Object &object, const SerializedPropertyMetadata &metadata)
 Notifies the deserializer that a new property is starting deserialization.
 
void endObjectProperty (Object &object, const Property &property, Box &&value)
 Notifies the deserializer that a property has ended deserialization.
 
Box objectReference (SerializedObjectID referenceID)
 Notifies the deserializer that an object reference was deserialized.
 
Box binary (InputStream &stream, Box &&existingObject)
 Decodes a binary input stream into a MetaValue object.
 
Array beginArray (const SerializedArrayMetadata &metadata, Box &&existingObject={})
 Notifies the deserializer that an array is starting deserialization.
 
void arrayElement (const Array &array, Box &&value)
 Notifies the deserializer that an array element was deserialized.
 
Box endArray (Array &array)
 Notifies the deserializer that an array has ended deserialization.
 
Map beginMap (const SerializedMapMetadata &metadata, Box &&existingObject={})
 Notifies the deserializer that a map is starting deserialization.
 
void mapElement (const Map &map, Box &&key, Box &&value)
 Notifies the deserializer that a map element was deserialized.
 
Box endMap (Map &map)
 Notifies the deserializer that a map has ended deserialization.
 

Detailed Description

The deserializer class has basic support for reflection-based deserializers.

It implements the more complicated logic to deal with reflection and leave only the actual wire serialization details for the implementer.

Constructor & Destructor Documentation

◆ Deserializer()

CeresEngine::Deserializer::Deserializer ( const SerializationContext context = SerializationContext::getDefault())
explicit

Creates a new deserializer with a custom context.

◆ ~Deserializer()

CeresEngine::Deserializer::~Deserializer ( )
overridenoexcept

Destroys the deserializer.

Member Function Documentation

◆ arrayElement()

void CeresEngine::Deserializer::arrayElement ( const Array array,
Box &&  value 
)
protected

Notifies the deserializer that an array element was deserialized.

Parameters
arrayThe context of the array that contains the element value.
valueThe value of the array element.

◆ beginArray()

Array CeresEngine::Deserializer::beginArray ( const SerializedArrayMetadata metadata,
Box &&  existingObject = {} 
)
protected

Notifies the deserializer that an array is starting deserialization.

Parameters
metadataThe metadata as stored on the serialized array.
existingObjectIf not empty, determines the object to which perform inplace deserialization to.
Returns
A context for deserializing the array.

◆ beginMap()

Map CeresEngine::Deserializer::beginMap ( const SerializedMapMetadata metadata,
Box &&  existingObject = {} 
)
protected

Notifies the deserializer that a map is starting deserialization.

Parameters
metadataThe metadata as stored on the serialized map.
existingObjectIf not empty, determines the object to which perform inplace deserialization to.
Returns
A context for deserializing the map.

◆ beginObject()

Object CeresEngine::Deserializer::beginObject ( const SerializedObjectMetadata metadata,
Box &&  existingObject = {} 
)
protected

Notifies the deserializer that a new object is starting deserialization.

If existingObject is not empty, deserialization will be performed inplace, directly on the object.

Parameters
metadataThe metadata as stored on the serialized object.
existingObjectIf not empty, determines the object to which perform inplace deserialization to.
Returns
A context for deserializing the object.

◆ beginObjectProperty()

Property CeresEngine::Deserializer::beginObjectProperty ( const Object object,
const SerializedPropertyMetadata metadata 
)
protected

Notifies the deserializer that a new property is starting deserialization.

Parameters
objectThe context for which the deserialized property belongs to.
metadataThe metadata as stored on the serialized property.
Returns
A context for deserializing the property.

◆ binary()

Box CeresEngine::Deserializer::binary ( InputStream stream,
Box &&  existingObject 
)
protected

Decodes a binary input stream into a MetaValue object.

This function receives an input stream and an optional existing MetaValue object. It decodes the binary data from the input stream and populates the MetaValue object with the deserialized data.

Parameters
streamThe input stream to read the binary data from.
existingObjectAn optional existing MetaValue object to populate with the deserialized data.
Returns
A new MetaValue object containing the deserialized data.

◆ decode()

virtual Box CeresEngine::Deserializer::decode ( Box &&  existingObject = {})
pure virtual

Starts decoding from the deserializer implementation.

Usually called from deserialize, but can be called manually by the implementation under certain conditions.

Parameters
existingObjectIf not empty, will attempt to decode the value inplace on this object.
Returns
The decoded object.

Implemented in CeresEngine::BinaryDeserializer, and CeresEngine::JSONDeserializer.

◆ deserialize()

Optional< Box > CeresEngine::Deserializer::deserialize ( )
finalvirtual

Deserializes a value from a stream of bytes read from dataStream.

The layout, format and details on how the object is deserialized is open for the deserializer implementation to decide.

Returns
The deserialized object if successful; an empty optional otherwise.

Implements CeresEngine::IDeserializer.

◆ endArray()

Box CeresEngine::Deserializer::endArray ( Array array)
protected

Notifies the deserializer that an array has ended deserialization.

Parameters
arrayThe context for the deserialized array.
Returns
The deserialized array value.

◆ endMap()

Box CeresEngine::Deserializer::endMap ( Map map)
protected

Notifies the deserializer that a map has ended deserialization.

Parameters
mapThe context for the deserialized map.
Returns
The deserialized map value.

◆ endObject()

Box CeresEngine::Deserializer::endObject ( Object object)
protected

Notifies the deserializer that an object has ended deserialization.

Parameters
objectThe context for the deserialized object.
Returns
The deserialized object value.

◆ endObjectProperty()

void CeresEngine::Deserializer::endObjectProperty ( Object object,
const Property property,
Box &&  value 
)
protected

Notifies the deserializer that a property has ended deserialization.

Parameters
objectThe context for which the deserialized property belongs to.
propertyThe context for deserializing the property.
valueThe value to set the property to. Must be compatible with the type held by the property.

◆ mapElement()

void CeresEngine::Deserializer::mapElement ( const Map map,
Box &&  key,
Box &&  value 
)
protected

Notifies the deserializer that a map element was deserialized.

Parameters
mapThe context of the map that contains the element value.
keyThe key of the map element.
valueThe value of the map element.

◆ objectReference()

Box CeresEngine::Deserializer::objectReference ( SerializedObjectID  referenceID)
protected

Notifies the deserializer that an object reference was deserialized.

Parameters
referenceIDThe serialized object ID.
Returns
A reference to the previously deserialized object with the same ID.

◆ resetState()

virtual void CeresEngine::Deserializer::resetState ( )
virtual

Resets the deserializer state.

Member Data Documentation

◆ context

const SerializationContext& CeresEngine::Deserializer::context

A shared context that contains a context for the deserializer.

◆ state

DeserializerState CeresEngine::Deserializer::state

An object that stores context for the deserializer.


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