Message
Message
#include <icy/symple/message.h>class MessageDefined in src/symple/include/icy/symple/message.h:27
Inherits:
Value,IPacketSubclassed by:Command,Event,Presence
Base Symple protocol message with addressing, status, data, and notes.
List of all members
| Name | Kind | Owner |
|---|---|---|
Message | function | Declared here |
Message | function | Declared here |
Message | function | Declared here |
operator= | function | Declared here |
~Message | function | Declared here |
clone | function | Declared here |
valid | function | Declared here |
clear | function | Declared here |
clearData | function | Declared here |
clearNotes | function | Declared here |
type | function | Declared here |
id | function | Declared here |
to | function | Declared here |
from | function | Declared here |
toUser | function | Declared here |
toId | function | Declared here |
fromUser | function | Declared here |
fromId | function | Declared here |
status | function | Declared here |
setType | function | Declared here |
setTo | function | Declared here |
setTo | function | Declared here |
setTo | function | Declared here |
setFrom | function | Declared here |
setFrom | function | Declared here |
setFrom | function | Declared here |
setStatus | function | Declared here |
notes | function | Declared here |
setNote | function | Declared here |
addNote | function | Declared here |
data | function | Declared here |
data | function | Declared here |
setData | function | Declared here |
setData | function | Declared here |
setData | function | Declared here |
setData | function | Declared here |
setData | function | Declared here |
removeData | function | Declared here |
hasData | function | Declared here |
read | function | Declared here |
read | function | Declared here |
write | function | Declared here |
isRequest | function | Declared here |
size | function | Declared here |
print | function | Declared here |
className | function | Declared here |
data | function | Declared here |
hasData | function | Declared here |
operator<< | friend | Inherited from IPacket |
opaque | variable | Inherited from IPacket |
info | variable | Inherited from IPacket |
flags | variable | Inherited from IPacket |
IPacket | function | Inherited from IPacket |
IPacket | function | Inherited from IPacket |
operator= | function | Inherited from IPacket |
clone | function | Inherited from IPacket |
~IPacket | function | Inherited from IPacket |
read | function | Inherited from IPacket |
write | function | Inherited from IPacket |
size | function | Inherited from IPacket |
hasData | function | Inherited from IPacket |
data | function | Inherited from IPacket |
constData | function | Inherited from IPacket |
className | function | Inherited from IPacket |
print | function | Inherited from IPacket |
Inherited from IPacket
| Kind | Name | Description |
|---|---|---|
friend | operator<< inline | Stream insertion operator; delegates to print(). |
variable | opaque | Optional type-safe context data. Use std::any_cast to retrieve. Lifetime of the stored value is tied to the packet's lifetime. |
variable | info | Optional extra information about the packet. |
variable | flags | Provides basic information about the packet. |
function | IPacket inline | |
function | IPacket inline | Copy constructor; clones the info object if present. |
function | operator= inline | Copy assignment; clones the info object if present. |
function | clone virtual const | Returns a heap-allocated deep copy of this packet. |
function | ~IPacket virtual | Defaulted destructor. |
function | read virtual | Read/parse to the packet from the given input buffer. The number of bytes read is returned. |
function | write virtual const | Copy/generate to the packet given output buffer. The number of bytes written can be obtained from the buffer. |
function | size virtual const inline | The size of the packet in bytes. |
function | hasData virtual const inline | Returns true if the packet has a non-null data pointer. |
function | data virtual const inline | The packet data pointer for buffered packets. |
function | constData virtual const inline | The const packet data pointer for buffered packets. |
function | className virtual const | Returns the class name of this packet type for logging and diagnostics. |
function | print virtual const inline | Prints a human-readable representation to the given stream. |
Public Methods
| 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 override | 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 override | Deserialises the message from a raw buffer. |
ssize_t | read virtual | Deserialises the message from a JSON string. |
void | write virtual const override | 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 override | Returns the serialised JSON size in bytes. |
void | print virtual const override | Pretty-prints the message JSON to the given stream. |
const char * | className virtual const inline override | 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
Message()Defined in src/symple/include/icy/symple/message.h:35
Constructs a new message with a random ID and type set to "message".
Message
Message(const json::Value & root)Defined in src/symple/include/icy/symple/message.h:39
Constructs a message from a JSON value; sets missing id/type fields.
Parameters
rootJSON object to initialise from.
Message
Message(const Message & root)Defined in src/symple/include/icy/symple/message.h:43
Copy constructor; preserves or generates id/type fields.
Parameters
rootSource message.
clone
virtual const override
virtual std::unique_ptr< IPacket > clone() const overrideDefined in src/symple/include/icy/symple/message.h:49
Returns a heap-allocated copy of this message.
Reimplements
valid
virtual const
virtual bool valid() constDefined in src/symple/include/icy/symple/message.h:52
Returns true if the message has both type and id fields.
Reimplemented by
clear
virtual
virtual void clear()Defined in src/symple/include/icy/symple/message.h:55
Clears all JSON fields from this message.
clearData
virtual
virtual void clearData()Defined in src/symple/include/icy/symple/message.h:58
Clears the data sub-object.
clearNotes
virtual
virtual void clearNotes()Defined in src/symple/include/icy/symple/message.h:61
Clears the notes array.
type
const
std::string type() constDefined in src/symple/include/icy/symple/message.h:64
Returns the message type string (defaults to "message").
id
const
std::string id() constDefined in src/symple/include/icy/symple/message.h:67
Returns the message ID string.
to
const
Address to() constDefined in src/symple/include/icy/symple/message.h:70
Returns the recipient address parsed from the to field.
from
const
Address from() constDefined in src/symple/include/icy/symple/message.h:73
Returns the sender address parsed from the from field.
toUser
const
std::string toUser() constDefined in src/symple/include/icy/symple/message.h:76
Returns the user component of the to address without constructing an Address.
toId
const
std::string toId() constDefined in src/symple/include/icy/symple/message.h:79
Returns the id component of the to address without constructing an Address.
fromUser
const
std::string fromUser() constDefined in src/symple/include/icy/symple/message.h:82
Returns the user component of the from address without constructing an Address.
fromId
const
std::string fromId() constDefined in src/symple/include/icy/symple/message.h:85
Returns the id component of the from address without constructing an Address.
status
const
int status() constDefined in src/symple/include/icy/symple/message.h:88
Returns the HTTP status code, or -1 if not set.
setType
void setType(std::string_view type)Defined in src/symple/include/icy/symple/message.h:92
Sets the message type field.
Parameters
typeType string (e.g. "message", "command").
setTo
void setTo(const Peer & to)Defined in src/symple/include/icy/symple/message.h:96
Sets the to field from a peer's address.
Parameters
toDestination peer.
setTo
void setTo(const Address & to)Defined in src/symple/include/icy/symple/message.h:100
Sets the to field from an address object.
Parameters
toDestination address.
setTo
void setTo(std::string_view to)Defined in src/symple/include/icy/symple/message.h:104
Sets the to field from an address string.
Parameters
toDestination address string.
setFrom
void setFrom(const Peer & from)Defined in src/symple/include/icy/symple/message.h:108
Sets the from field from a peer's address.
Parameters
fromSender peer.
setFrom
void setFrom(const Address & from)Defined in src/symple/include/icy/symple/message.h:112
Sets the from field from an address object.
Parameters
fromSender address.
setFrom
void setFrom(std::string_view from)Defined in src/symple/include/icy/symple/message.h:116
Sets the from field from an address string.
Parameters
fromSender address string.
setStatus
void setStatus(int code)Defined in src/symple/include/icy/symple/message.h:122
HTTP status codes are used to describe the message response. Throws std::invalid_argument if code is outside [101, 504].
Parameters
codeHTTP status code.
See also: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
notes
json::Value & notes()Defined in src/symple/include/icy/symple/message.h:125
Returns a reference to the notes JSON array.
setNote
void setNote(std::string_view type, std::string_view text)Defined in src/symple/include/icy/symple/message.h:130
Replaces all notes with a single note.
Parameters
typeNote severity:info,warn, orerror.textNote message text.
addNote
void addNote(std::string_view type, std::string_view text)Defined in src/symple/include/icy/symple/message.h:135
Appends a note to the notes array.
Parameters
typeNote severity:info,warn, orerror.textNote message text.
data
const
json::Value data(std::string_view name) constDefined in src/symple/include/icy/symple/message.h:139
Returns a copy of the named data field.
Parameters
nameField name withindata.
data
json::Value & data(std::string_view name)Defined in src/symple/include/icy/symple/message.h:143
Returns a reference to the named data field (creates it if absent).
Parameters
nameField name withindata.
setData
json::Value & setData(std::string_view name)Defined in src/symple/include/icy/symple/message.h:147
Creates or replaces a named data field; returns a reference to it.
Parameters
nameField name withindata.
setData
void setData(std::string_view name, const char * data)Defined in src/symple/include/icy/symple/message.h:152
Sets a named data field to a C-string value.
Parameters
nameField name withindata.dataString value to assign.
setData
void setData(std::string_view name, std::string_view data)Defined in src/symple/include/icy/symple/message.h:157
Sets a named data field to a string value.
Parameters
nameField name withindata.dataString value to assign.
setData
void setData(std::string_view name, const json::Value & data)Defined in src/symple/include/icy/symple/message.h:162
Sets a named data field to a JSON value.
Parameters
nameField name withindata.dataJSON value to assign.
setData
void setData(std::string_view name, int data)Defined in src/symple/include/icy/symple/message.h:167
Sets a named data field to an integer value.
Parameters
nameField name withindata.dataInteger value to assign.
removeData
void removeData(std::string_view name)Defined in src/symple/include/icy/symple/message.h:171
Removes a named field from the data sub-object.
Parameters
nameField name to remove.
hasData
bool hasData(std::string_view name)Defined in src/symple/include/icy/symple/message.h:175
Returns true if the named field exists in the data sub-object.
Parameters
nameField name to look up.
read
virtual override
virtual ssize_t read(const ConstBuffer & buf) overrideDefined in src/symple/include/icy/symple/message.h:180
Deserialises the message from a raw buffer.
Parameters
bufBuffer containing the JSON payload.
Returns
Number of bytes consumed.
Reimplements
read
virtual
virtual ssize_t read(const std::string & root)Defined in src/symple/include/icy/symple/message.h:185
Deserialises the message from a JSON string.
Parameters
rootJSON string to parse.
Returns
Number of characters consumed.
write
virtual const override
virtual void write(Buffer & buf) const overrideDefined in src/symple/include/icy/symple/message.h:189
Serialises the message as JSON into a buffer.
Parameters
bufBuffer to append to.
Reimplements
isRequest
const
bool isRequest() constDefined in src/symple/include/icy/symple/message.h:192
Returns true if no status code has been set (i.e. status() == -1).
size
virtual const override
virtual size_t size() const overrideDefined in src/symple/include/icy/symple/message.h:195
Returns the serialised JSON size in bytes.
Reimplements
virtual const override
virtual void print(std::ostream & os) const overrideDefined in src/symple/include/icy/symple/message.h:199
Pretty-prints the message JSON to the given stream.
Parameters
osOutput stream.
Reimplements
className
virtual const inline override
virtual inline const char * className() const overrideDefined in src/symple/include/icy/symple/message.h:201
Returns the class name of this packet type for logging and diagnostics.
Reimplements
data
virtual const inline
virtual inline char * data() constDefined in src/symple/include/icy/symple/message.h:31
The packet data pointer for buffered packets.
Reimplements
hasData
virtual const inline
virtual inline bool hasData() constDefined in src/symple/include/icy/symple/message.h:32
Returns true if the packet has a non-null data pointer.
