Servus
1.6.0
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 |
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 &) | |
Serializable & | operator= (const Serializable &) |
Serializable (Serializable &&) | |
Serializable & | operator= (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... | |
Interface for serializable objects.
Definition at line 32 of file serializable.h.
typedef std::function<void()> servus::Serializable::DeserializedCallback |
Callbacks for change notifications.
Definition at line 93 of file serializable.h.
bool servus::Serializable::fromBinary | ( | const Data & | data | ) |
Update this serializable from its binary representation.
Referenced by getSchema().
bool servus::Serializable::fromJSON | ( | const std::string & | json | ) |
Update this serializable from its JSON representation.
Referenced by getSchema().
|
inlinevirtual |
Definition at line 62 of file serializable.h.
References fromBinary(), fromJSON(), servus::Serializable::Data::size, toBinary(), and toJSON().
|
virtual |
|
pure virtual |
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.
if | a 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.
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.
Referenced by getSchema().
std::string servus::Serializable::toJSON | ( | ) | const |
Referenced by getSchema().