Servus  1.5.1
C++ network oriented utilities including a zeroconf implementation
servus::Serializable Class Referenceabstract

Interface for serializable objects. More...

#include <serializable.h>

+ Collaboration diagram for servus::Serializable:

Classes

struct  Data
 Pointer + size wrapper for binary serialization. More...
 

Public Member Functions

Serialization methods
virtual std::string getTypeName () const =0
 
virtual uint128_t getTypeIdentifier () const
 
virtual std::string getSchema () const
 
bool fromBinary (const Data &data)
 Update this serializable from its binary representation. More...
 
bool fromBinary (const void *data, const size_t size)
 
Data toBinary () const
 Get a binary representation of this object. More...
 
bool fromJSON (const std::string &json)
 Update this serializable from its JSON representation. More...
 
std::string toJSON () const
 

Protected Member Functions

 Serializable (const Serializable &)
 
Serializableoperator= (const Serializable &)
 
 Serializable (Serializable &&)
 
Serializableoperator= (Serializable &&)
 

Change Notifications

typedef std::function< void()> DeserializedCallback
 Callbacks for change notifications. More...
 
typedef std::function< void()> SerializeCallback
 
void registerDeserializedCallback (const DeserializedCallback &)
 Register a function called after the object has been updated remotely (via a subscriber, a http server, loading from file...). More...
 
void registerSerializeCallback (const SerializeCallback &)
 Register a function to be called when the serializable object is about to be serialized. More...
 

Detailed Description

Interface for serializable objects.

Definition at line 32 of file serializable.h.

Member Typedef Documentation

typedef std::function<void()> servus::Serializable::DeserializedCallback

Callbacks for change notifications.

Definition at line 89 of file serializable.h.

Member Function Documentation

bool servus::Serializable::fromBinary ( const Data data)

Update this serializable from its binary representation.

Returns
true on success, false on error.

Referenced by getSchema().

+ Here is the caller graph for this function:

bool servus::Serializable::fromJSON ( const std::string &  json)

Update this serializable from its JSON representation.

Returns
true on success, false on error.

Referenced by getSchema().

+ Here is the caller graph for this function:

virtual std::string servus::Serializable::getSchema ( ) const
inlinevirtual
Returns
the description of the objects' data layout.

Definition at line 58 of file serializable.h.

References fromBinary(), fromJSON(), servus::Serializable::Data::size, toBinary(), and toJSON().

+ Here is the call graph for this function:

virtual uint128_t servus::Serializable::getTypeIdentifier ( ) const
virtual
Returns
the universally unique identifier of this serializable.
virtual std::string servus::Serializable::getTypeName ( ) const
pure virtual
Returns
the fully qualified, demangled class name.
void servus::Serializable::registerDeserializedCallback ( const DeserializedCallback )

Register a function called after the object has been updated remotely (via a subscriber, a http server, loading from file...).

Only one callback is supported at the moment, to deregister the callback, call this function with a 'nullptr' (or 0) parameter.

Exceptions
ifa DeserializedCallback is already registered and the specified callback is not 'nullptr' (or 0)
void servus::Serializable::registerSerializeCallback ( const SerializeCallback &  )

Register a function to be called when the serializable object is about to be serialized.

Only one callback is supported at the moment, to deregister the callback, call this function with a 'nullptr' (or 0) parameter.

Exceptions
ifa SerializedCallback is already registered and the specified callback is not 'nullptr' (or 0)
Data servus::Serializable::toBinary ( ) const

Get a binary representation of this object.

The returned data is not thread safe, that is, it should not be modified until the caller of this method has completed its execution.

Returns
the binary representation of this object.

Referenced by getSchema().

+ Here is the caller graph for this function:

std::string servus::Serializable::toJSON ( ) const
Returns
the JSON representation of this serializable.

Referenced by getSchema().

+ Here is the caller graph for this function:


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