29 [[nodiscard]]
virtual std::string
serialize()
const = 0;
47 static std::shared_ptr<MessageObject>
create();
56 static std::shared_ptr<MessageObject>
from(
const std::string& obj);
66 virtual std::shared_ptr<MessageObject>
set_field(
const std::string& key,
const std::string& value) = 0;
76 virtual std::shared_ptr<MessageObject>
set_field(
const std::string& key,
long value) = 0;
83 virtual std::shared_ptr<MessageObject>
set_field(
const std::string& key,
double value) = 0;
91 const std::string& key,
92 std::shared_ptr<MessageObject> value
107 virtual bool is_long(
const std::string& key) = 0;
130 virtual std::string
get_string(
const std::string& key)
const = 0;
139 virtual long get_long(
const std::string& key)
const = 0;
157 virtual std::shared_ptr<MessageObject>
get_object(
const std::string& key)
const = 0;
186 explicit Message(
const std::string& msg,
const std::string& source = std::string());
194 explicit Message(
const std::shared_ptr<MessageObject>& msg,
const std::string& source = std::string());
267 std::string m_version;
268 std::string m_source;
270 std::string m_payload;
A key-value object that is serializable.
Definition message.h:38
virtual std::shared_ptr< MessageObject > set_field(const std::string &key, std::shared_ptr< MessageObject > value)=0
Set an object field.
virtual bool is_long(const std::string &key)=0
Check if a field is a long.
virtual std::shared_ptr< MessageObject > set_field(const std::string &key, const std::string &value)=0
Set a string field.
virtual bool is_double(const std::string &key)=0
Check if a field is a double.
virtual long get_long(const std::string &key) const =0
Get the long value stored with key.
static std::shared_ptr< MessageObject > from(const std::string &obj)
Creates a new message object from a serialized object string.
static std::shared_ptr< MessageObject > create()
Creates a new message object.
virtual double get_double(const std::string &key) const =0
Get the double value stored with key.
virtual bool is_string(const std::string &key)=0
Check if a field is a string.
virtual std::string get_string(const std::string &key) const =0
Get the string value stored with key.
virtual std::shared_ptr< MessageObject > set_field(const std::string &key, double value)=0
Set a double field.
virtual std::shared_ptr< MessageObject > set_field(const std::string &key, long value)=0
Set a long field.
virtual bool is_object(const std::string &key)=0
Check if a field is an object.
virtual std::shared_ptr< MessageObject > get_object(const std::string &key) const =0
Get the object value stored with key.
A message that is sent across the message bus.
Definition message.h:167
std::string get_version() const
Get the version of the message.
MessageType
The types that messages can hold.
Definition message.h:173
void set_source(const std::string &source)
Set the source of the message.
std::string get_payload() const
Get the payload of the message.
void set_payload(const std::string &payload)
Set the payload of the message.
Message(const std::shared_ptr< MessageObject > &msg, const std::string &source=std::string())
Message constructor for object messages.
MessageType get_type() const
Get the type of the message.
void set_type(MessageType type)
Set the type of the message.
std::string get_source() const
Get the source of the message.
std::string serialize() const override
Serialize the message.
void set_version(const std::string &version)
Set the version of the message protocol.
bool is_object() const
Check if the message is an object type.
Message(const std::string &msg, const std::string &source=std::string())
Message constructor for text messages.
An object that is serializable.
Definition message.h:20
virtual std::string serialize() const =0
Serialize the object.