Servus  1.3.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
 
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
 

Change Notifications

typedef std::function< void() > DeserializedCallback
 Callbacks for change notifications. More...
 
typedef std::function< void() > SerializeCallback
 
void registerDeserializedCallback (const DeserializedCallback &callback)
 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 &callback)
 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 38 of file serializable.h.

Member Typedef Documentation

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

Callbacks for change notifications.

Definition at line 98 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.
bool servus::Serializable::fromJSON ( const std::string &  json)

Update this serializable from its JSON representation.

Returns
true on success, false on error.
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 callback)

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 &  callback)

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.
std::string servus::Serializable::toJSON ( ) const
Returns
the JSON representation of this serializable.

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