#include <icy/symple/message.h>Inherits:
Value,IPacketSubclassed by:Command,Event,Presence
Base Symple protocol message with addressing, status, data, and notes.
| Return | Name | Description |
|---|---|---|
Message | Constructs a new message with a random ID and type set to "message". | |
Message | Constructs a message from a JSON value; sets missing id/type fields. | |
Message | Copy constructor; preserves or generates id/type fields. | |
std::unique_ptr< IPacket > | clone virtual const | Returns a heap-allocated copy of this message. |
bool | valid virtual const | Returns true if the message has both type and id fields. |
void | clear virtual | Clears all JSON fields from this message. |
void | clearData virtual | Clears the data sub-object. |
void | clearNotes virtual | Clears the notes array. |
std::string | type const | Returns the message type string (defaults to "message"). |
std::string | id const | Returns the message ID string. |
Address | to const | Returns the recipient address parsed from the to field. |
Address | from const | Returns the sender address parsed from the from field. |
std::string | toUser const | Returns the user component of the to address without constructing an Address. |
std::string | toId const | Returns the id component of the to address without constructing an Address. |
std::string | fromUser const | Returns the user component of the from address without constructing an Address. |
std::string | fromId const | Returns the id component of the from address without constructing an Address. |
int | status const | Returns the HTTP status code, or -1 if not set. |
void | setType | Sets the message type field. |
void | setTo | Sets the to field from a peer's address. |
void | setTo | Sets the to field from an address object. |
void | setTo | Sets the to field from an address string. |
void | setFrom | Sets the from field from a peer's address. |
void | setFrom | Sets the from field from an address object. |
void | setFrom | Sets the from field from an address string. |
void | setStatus | HTTP status codes are used to describe the message response. Throws std::invalid_argument if code is outside [101, 504]. |
json::Value & | notes | Returns a reference to the notes JSON array. |
void | setNote | Replaces all notes with a single note. |
void | addNote | Appends a note to the notes array. |
json::Value | data const | Returns a copy of the named data field. |
json::Value & | data | Returns a reference to the named data field (creates it if absent). |
json::Value & | setData | Creates or replaces a named data field; returns a reference to it. |
void | setData | Sets a named data field to a C-string value. |
void | setData | Sets a named data field to a string value. |
void | setData | Sets a named data field to a JSON value. |
void | setData | Sets a named data field to an integer value. |
void | removeData | Removes a named field from the data sub-object. |
bool | hasData | Returns true if the named field exists in the data sub-object. |
ssize_t | read virtual | Deserialises the message from a raw buffer. |
ssize_t | read virtual | Deserialises the message from a JSON string. |
void | write virtual const | Serialises the message as JSON into a buffer. |
bool | isRequest const | Returns true if no status code has been set (i.e. status() == -1). |
size_t | size virtual const | Returns the serialised JSON size in bytes. |
void | print virtual const | Pretty-prints the message JSON to the given stream. |
const char * | className virtual const inline | Returns the class name of this packet type for logging and diagnostics. |
char * | data virtual const inline | The packet data pointer for buffered packets. |
bool | hasData virtual const inline | Returns true if the packet has a non-null data pointer. |
Message()Constructs a new message with a random ID and type set to "message".
Message(const json::Value & root)Constructs a message from a JSON value; sets missing id/type fields.
root JSON object to initialise from.Message(const Message & root)Copy constructor; preserves or generates id/type fields.
root Source message.virtual const
virtual std::unique_ptr< IPacket > clone() constReturns a heap-allocated copy of this message.
virtual const
virtual bool valid() constReturns true if the message has both type and id fields.
virtual
virtual void clear()Clears all JSON fields from this message.
virtual
virtual void clearData()Clears the data sub-object.
virtual
virtual void clearNotes()Clears the notes array.
const
std::string type() constReturns the message type string (defaults to "message").
const
std::string id() constReturns the message ID string.
const
Address to() constReturns the recipient address parsed from the to field.
const
Address from() constReturns the sender address parsed from the from field.
const
std::string toUser() constReturns the user component of the to address without constructing an Address.
const
std::string toId() constReturns the id component of the to address without constructing an Address.
const
std::string fromUser() constReturns the user component of the from address without constructing an Address.
const
std::string fromId() constReturns the id component of the from address without constructing an Address.
const
int status() constReturns the HTTP status code, or -1 if not set.
void setType(std::string_view type)Sets the message type field.
type Type string (e.g. "message", "command").void setTo(const Peer & to)Sets the to field from a peer's address.
to Destination peer.void setTo(const Address & to)Sets the to field from an address object.
to Destination address.void setTo(std::string_view to)Sets the to field from an address string.
to Destination address string.void setFrom(const Peer & from)Sets the from field from a peer's address.
from Sender peer.void setFrom(const Address & from)Sets the from field from an address object.
from Sender address.void setFrom(std::string_view from)Sets the from field from an address string.
from Sender address string.void setStatus(int code)HTTP status codes are used to describe the message response. Throws std::invalid_argument if code is outside [101, 504].
code HTTP status code.See also: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
json::Value & notes()Returns a reference to the notes JSON array.
void setNote(std::string_view type, std::string_view text)Replaces all notes with a single note.
type Note severity: info, warn, or error.
text Note message text.
void addNote(std::string_view type, std::string_view text)Appends a note to the notes array.
type Note severity: info, warn, or error.
text Note message text.
const
json::Value data(std::string_view name) constReturns a copy of the named data field.
name Field name within data.json::Value & data(std::string_view name)Returns a reference to the named data field (creates it if absent).
name Field name within data.json::Value & setData(std::string_view name)Creates or replaces a named data field; returns a reference to it.
name Field name within data.void setData(std::string_view name, const char * data)Sets a named data field to a C-string value.
name Field name within data.
data String value to assign.
void setData(std::string_view name, std::string_view data)Sets a named data field to a string value.
name Field name within data.
data String value to assign.
void setData(std::string_view name, const json::Value & data)Sets a named data field to a JSON value.
name Field name within data.
data JSON value to assign.
void setData(std::string_view name, int data)Sets a named data field to an integer value.
name Field name within data.
data Integer value to assign.
void removeData(std::string_view name)Removes a named field from the data sub-object.
name Field name to remove.bool hasData(std::string_view name)Returns true if the named field exists in the data sub-object.
name Field name to look up.virtual
virtual ssize_t read(const ConstBuffer & buf)Deserialises the message from a raw buffer.
buf Buffer containing the JSON payload.Number of bytes consumed.
virtual
virtual ssize_t read(const std::string & root)Deserialises the message from a JSON string.
root JSON string to parse.Number of characters consumed.
virtual const
virtual void write(Buffer & buf) constSerialises the message as JSON into a buffer.
buf Buffer to append to.const
bool isRequest() constReturns true if no status code has been set (i.e. status() == -1).
virtual const
virtual size_t size() constReturns the serialised JSON size in bytes.
virtual const
virtual void print(std::ostream & os) constPretty-prints the message JSON to the given stream.
os Output stream.virtual const inline
virtual inline const char * className() constReturns the class name of this packet type for logging and diagnostics.
virtual const inline
virtual inline char * data() constThe packet data pointer for buffered packets.
virtual const inline
virtual inline bool hasData() constReturns true if the packet has a non-null data pointer.