20 #ifndef SERVUS_SERIALIZABLE_H 21 #define SERVUS_SERIALIZABLE_H 24 #include <servus/types.h> 36 SERVUS_API
virtual ~Serializable();
47 std::shared_ptr<const void>
ptr;
58 virtual std::string
getSchema()
const {
return std::string(); }
80 SERVUS_API
bool fromJSON(
const std::string& json);
83 SERVUS_API std::string
toJSON()
const;
90 typedef std::function<void()> SerializeCallback;
116 SERVUS_API Serializable(
const Serializable&);
117 SERVUS_API Serializable& operator=(
const Serializable&);
118 SERVUS_API Serializable(Serializable&&);
119 SERVUS_API Serializable& operator=(Serializable&&);
129 virtual bool _fromBinary(
const void* ,
const size_t )
131 throw std::runtime_error(
"Binary deserialization not implemented");
133 virtual Data _toBinary()
const 135 throw std::runtime_error(
"Binary serialization not implemented");
138 virtual bool _fromJSON(
const std::string& )
140 throw std::runtime_error(
"JSON deserialization not implemented");
142 virtual std::string _toJSON()
const 144 throw std::runtime_error(
"JSON serialization not implemented");
153 #endif // SERVUS_SERIALIZABLE_H size_t size
The size of the binary serialization.
Defines export visibility macros for library Servus.
std::string toJSON() const
void registerDeserializedCallback(const DeserializedCallback &)
Register a function called after the object has been updated remotely (via a subscriber, a http server, loading from file...).
std::function< void()> DeserializedCallback
Callbacks for change notifications.
virtual uint128_t getTypeIdentifier() const
std::shared_ptr< const void > ptr
ptr to the binary serialization
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.
virtual std::string getTypeName() const =0