Servus
1.3.1
C++ network oriented utilities including a zeroconf implementation
|
Interface for serializable objects. More...
#include <serializable.h>
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... | |
Interface for serializable objects.
Definition at line 38 of file serializable.h.
typedef std::function< void() > servus::Serializable::DeserializedCallback |
Callbacks for change notifications.
Definition at line 98 of file serializable.h.
bool servus::Serializable::fromBinary | ( | const Data & | data | ) |
Update this serializable from its binary representation.
bool servus::Serializable::fromJSON | ( | const std::string & | json | ) |
Update this serializable from its JSON representation.
|
virtual |
|
pure virtual |
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.
if | a 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.
if | a 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.
std::string servus::Serializable::toJSON | ( | ) | const |