20 #ifndef SERVUS_SERIALIZABLE_H
21 #define SERVUS_SERIALIZABLE_H
24 #include <servus/types.h>
26 #ifdef SERVUS_USE_CXX03
27 # include <boost/function/function0.hpp>
28 # include <boost/shared_ptr.hpp>
30 # include <functional>
42 SERVUS_API
virtual ~Serializable();
50 #ifdef SERVUS_USE_CXX03
51 boost::shared_ptr< const void >
ptr;
53 std::shared_ptr< const void >
ptr;
69 SERVUS_API
bool fromBinary(
const void* data,
const size_t size );
85 SERVUS_API
bool fromJSON(
const std::string& json );
88 SERVUS_API std::string
toJSON()
const;
94 #ifdef SERVUS_USE_CXX03
96 typedef boost::function< void() > SerializeCallback;
99 typedef std::function< void() > SerializeCallback;
112 const DeserializedCallback& callback );
124 const SerializeCallback& callback );
128 SERVUS_API Serializable(
const Serializable& );
129 SERVUS_API Serializable& operator=(
const Serializable& );
130 #ifdef SERVUS_USE_CXX11
131 SERVUS_API Serializable( Serializable&& );
132 SERVUS_API Serializable& operator=( Serializable&& );
143 virtual bool _fromBinary(
const void* ,
const size_t )
144 {
throw std::runtime_error(
"Binary deserialization not implemented" );}
145 virtual Data _toBinary()
const
146 {
throw std::runtime_error(
"Binary serialization not implemented" ); }
148 virtual bool _fromJSON(
const std::string& )
149 {
throw std::runtime_error(
"JSON deserialization not implemented" ); }
150 virtual std::string _toJSON()
const
151 {
throw std::runtime_error(
"JSON serialization not implemented" ); }
160 #endif // SERVUS_SERIALIZABLE_H
size_t size
The size of the binary serialization.
Defines export visibility macros for library Servus.
std::string toJSON() const
std::function< void() > DeserializedCallback
Callbacks for change notifications.
void registerSerializeCallback(const SerializeCallback &callback)
Register a function to be called when the serializable object is about to be serialized.
std::shared_ptr< const void > ptr
ptr to the binary serialization
virtual std::string getTypeName() const =0
virtual uint128_t getTypeIdentifier() const
bool fromJSON(const std::string &json)
Update this serializable from its JSON representation.
bool fromBinary(const Data &data)
Update this serializable from its binary representation.
Interface for serializable objects.
Pointer + size wrapper for binary serialization.
A base type for 128 bit unsigned integer values.
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...).
Data toBinary() const
Get a binary representation of this object.