20 #ifndef SERVUS_SERIALIZABLE_H
21 #define SERVUS_SERIALIZABLE_H
24 #include <servus/types.h>
37 SERVUS_API
virtual ~Serializable();
45 std::shared_ptr< const void >
ptr;
56 virtual std::string
getSchema()
const {
return std::string(); }
62 SERVUS_API
bool fromBinary(
const Data& data );
63 SERVUS_API
bool fromBinary(
const void* data,
const size_t size );
79 SERVUS_API
bool fromJSON(
const std::string& json );
82 SERVUS_API std::string
toJSON()
const;
89 typedef std::function< void() > SerializeCallback;
115 SERVUS_API Serializable(
const Serializable& );
116 SERVUS_API Serializable& operator=(
const Serializable& );
117 #ifdef SERVUS_USE_CXX11
118 SERVUS_API Serializable( Serializable&& );
119 SERVUS_API Serializable& operator=( Serializable&& );
130 virtual bool _fromBinary(
const void* ,
const size_t )
131 {
throw std::runtime_error(
"Binary deserialization not implemented" );}
132 virtual Data _toBinary()
const
133 {
throw std::runtime_error(
"Binary serialization not implemented" ); }
135 virtual bool _fromJSON(
const std::string& )
136 {
throw std::runtime_error(
"JSON deserialization not implemented" ); }
137 virtual std::string _toJSON()
const
138 {
throw std::runtime_error(
"JSON serialization not implemented" ); }
147 #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.
std::shared_ptr< const void > ptr
ptr to the binary serialization
void registerDeserializedCallback(const DeserializedCallback &)
Register a function called after the object has been updated remotely (via a subscriber, a http server, loading from file...).
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.
void registerSerializeCallback(const SerializeCallback &)
Register a function to be called when the serializable object is about to be serialized.
Interface for serializable objects.
virtual std::string getSchema() const
Pointer + size wrapper for binary serialization.
A base type for 128 bit unsigned integer values.
Data toBinary() const
Get a binary representation of this object.