class
#include <core/data/des/deserializer.hpp>
Deserializer Base class for deserializers, which defines the interface for deserializing arbitrary data using its reflection metadata.
Deserializers are type visitors which allow overriding the default deserialization behaviour for each type using hooks. Hooks are functions which are called when the deserializer encounters a type, and can be used to customize the deserialization process.
If a type which can't be further decomposed is encountered for which no hook is defined, the deserializer will emit a warning and fail. Implementations should set default hooks for at least the primitive types.
Derived classes
- class BinaryDeserializer
- Implementation of the abstract Deserializer class meant to deserialize data written by a BinarySerializer.
- class JSONDeserializer
- Deserializer implementation which allows reading data from a JSON object.
Public types
-
using Hook = memory::
Function<bool(void*)> - Function type for deserialization hooks.
-
template<typename T>using TypedHook = memory::
Function<bool(T&)> - Function type for deserialization hooks.
Constructors, destructors, conversion operators
- Deserializer() defaulted
- Constructs.
Public functions
-
auto read(const reflection::
Type& type, void* value) -> bool - Deserialize the given value.
-
template<typename T>auto read(T& value) -> bool
- Deserialize the given value.
-
void hook(const reflection::
Type& type, Hook hook) - Sets the hook to be called on deserialization of the given type.
-
template<typename T>void hook(TypedHook<T> hook)
- Sets the hook to be called on deserialization of the given type.
Protected functions
-
auto decompose(const reflection::
Type& type, void* value) -> bool pure virtual - Called for each type with no hook defined.
Typedef documentation
template<typename T>
using cubos:: core:: data:: Deserializer:: TypedHook = memory:: Function<bool(T&)>
Function type for deserialization hooks.
Template parameters | |
---|---|
T | Type. |
Function documentation
bool cubos:: core:: data:: Deserializer:: read(const reflection:: Type& type,
void* value)
Deserialize the given value.
Parameters | |
---|---|
type | Type. |
value | Value. |
Returns | Whether the value was successfully deserialized. |
template<typename T>
bool cubos:: core:: data:: Deserializer:: read(T& value)
Deserialize the given value.
Template parameters | |
---|---|
T | Type. |
Parameters | |
value | Value. |
Returns | Whether the value was successfully deserialized. |
void cubos:: core:: data:: Deserializer:: hook(const reflection:: Type& type,
Hook hook)
Sets the hook to be called on deserialization of the given type.
Parameters | |
---|---|
type | Type. |
hook | Hook. |
bool cubos:: core:: data:: Deserializer:: decompose(const reflection:: Type& type,
void* value) pure virtual protected
Called for each type with no hook defined.
Parameters | |
---|---|
type | Type. |
value | Value. |
Returns | Whether the value was successfully deserialized. |
Should recurse by calling read() again as appropriate.