Home
Symple module

Message

Base Symple protocol message with addressing, status, data, and notes.

Message

#include <icy/symple/message.h>
class Message

Defined in src/symple/include/icy/symple/message.h:27

Inherits: Value, IPacket Subclassed by: Command, Event, Presence

Base Symple protocol message with addressing, status, data, and notes.

List of all members

NameKindOwner
MessagefunctionDeclared here
MessagefunctionDeclared here
MessagefunctionDeclared here
operator=functionDeclared here
~MessagefunctionDeclared here
clonefunctionDeclared here
validfunctionDeclared here
clearfunctionDeclared here
clearDatafunctionDeclared here
clearNotesfunctionDeclared here
typefunctionDeclared here
idfunctionDeclared here
tofunctionDeclared here
fromfunctionDeclared here
toUserfunctionDeclared here
toIdfunctionDeclared here
fromUserfunctionDeclared here
fromIdfunctionDeclared here
statusfunctionDeclared here
setTypefunctionDeclared here
setTofunctionDeclared here
setTofunctionDeclared here
setTofunctionDeclared here
setFromfunctionDeclared here
setFromfunctionDeclared here
setFromfunctionDeclared here
setStatusfunctionDeclared here
notesfunctionDeclared here
setNotefunctionDeclared here
addNotefunctionDeclared here
datafunctionDeclared here
datafunctionDeclared here
setDatafunctionDeclared here
setDatafunctionDeclared here
setDatafunctionDeclared here
setDatafunctionDeclared here
setDatafunctionDeclared here
removeDatafunctionDeclared here
hasDatafunctionDeclared here
readfunctionDeclared here
readfunctionDeclared here
writefunctionDeclared here
isRequestfunctionDeclared here
sizefunctionDeclared here
printfunctionDeclared here
classNamefunctionDeclared here
datafunctionDeclared here
hasDatafunctionDeclared here
operator<<friendInherited from IPacket
opaquevariableInherited from IPacket
infovariableInherited from IPacket
flagsvariableInherited from IPacket
IPacketfunctionInherited from IPacket
IPacketfunctionInherited from IPacket
operator=functionInherited from IPacket
clonefunctionInherited from IPacket
~IPacketfunctionInherited from IPacket
readfunctionInherited from IPacket
writefunctionInherited from IPacket
sizefunctionInherited from IPacket
hasDatafunctionInherited from IPacket
datafunctionInherited from IPacket
constDatafunctionInherited from IPacket
classNamefunctionInherited from IPacket
printfunctionInherited from IPacket

Inherited from IPacket

KindNameDescription
friendoperator<< inlineStream insertion operator; delegates to print().
variableopaqueOptional type-safe context data. Use std::any_cast to retrieve. Lifetime of the stored value is tied to the packet's lifetime.
variableinfoOptional extra information about the packet.
variableflagsProvides basic information about the packet.
functionIPacket inline
functionIPacket inlineCopy constructor; clones the info object if present.
functionoperator= inlineCopy assignment; clones the info object if present.
functionclone virtual constReturns a heap-allocated deep copy of this packet.
function~IPacket virtualDefaulted destructor.
functionread virtualRead/parse to the packet from the given input buffer. The number of bytes read is returned.
functionwrite virtual constCopy/generate to the packet given output buffer. The number of bytes written can be obtained from the buffer.
functionsize virtual const inlineThe size of the packet in bytes.
functionhasData virtual const inlineReturns true if the packet has a non-null data pointer.
functiondata virtual const inlineThe packet data pointer for buffered packets.
functionconstData virtual const inlineThe const packet data pointer for buffered packets.
functionclassName virtual constReturns the class name of this packet type for logging and diagnostics.
functionprint virtual const inlinePrints a human-readable representation to the given stream.

Public Methods

ReturnNameDescription
MessageConstructs a new message with a random ID and type set to "message".
MessageConstructs a message from a JSON value; sets missing id/type fields.
MessageCopy constructor; preserves or generates id/type fields.
std::unique_ptr< IPacket >clone virtual const overrideReturns a heap-allocated copy of this message.
boolvalid virtual constReturns true if the message has both type and id fields.
voidclear virtualClears all JSON fields from this message.
voidclearData virtualClears the data sub-object.
voidclearNotes virtualClears the notes array.
std::stringtype constReturns the message type string (defaults to "message").
std::stringid constReturns the message ID string.
Addressto constReturns the recipient address parsed from the to field.
Addressfrom constReturns the sender address parsed from the from field.
std::stringtoUser constReturns the user component of the to address without constructing an Address.
std::stringtoId constReturns the id component of the to address without constructing an Address.
std::stringfromUser constReturns the user component of the from address without constructing an Address.
std::stringfromId constReturns the id component of the from address without constructing an Address.
intstatus constReturns the HTTP status code, or -1 if not set.
voidsetTypeSets the message type field.
voidsetToSets the to field from a peer's address.
voidsetToSets the to field from an address object.
voidsetToSets the to field from an address string.
voidsetFromSets the from field from a peer's address.
voidsetFromSets the from field from an address object.
voidsetFromSets the from field from an address string.
voidsetStatusHTTP status codes are used to describe the message response. Throws std::invalid_argument if code is outside [101, 504].
json::Value &notesReturns a reference to the notes JSON array.
voidsetNoteReplaces all notes with a single note.
voidaddNoteAppends a note to the notes array.
json::Valuedata constReturns a copy of the named data field.
json::Value &dataReturns a reference to the named data field (creates it if absent).
json::Value &setDataCreates or replaces a named data field; returns a reference to it.
voidsetDataSets a named data field to a C-string value.
voidsetDataSets a named data field to a string value.
voidsetDataSets a named data field to a JSON value.
voidsetDataSets a named data field to an integer value.
voidremoveDataRemoves a named field from the data sub-object.
boolhasDataReturns true if the named field exists in the data sub-object.
ssize_tread virtual overrideDeserialises the message from a raw buffer.
ssize_tread virtualDeserialises the message from a JSON string.
voidwrite virtual const overrideSerialises the message as JSON into a buffer.
boolisRequest constReturns true if no status code has been set (i.e. status() == -1).
size_tsize virtual const overrideReturns the serialised JSON size in bytes.
voidprint virtual const overridePretty-prints the message JSON to the given stream.
const char *className virtual const inline overrideReturns the class name of this packet type for logging and diagnostics.
char *data virtual const inlineThe packet data pointer for buffered packets.
boolhasData virtual const inlineReturns 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

  • root JSON 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

  • root Source message.

clone

virtual const override

virtual std::unique_ptr< IPacket > clone() const override

Defined in src/symple/include/icy/symple/message.h:49

Returns a heap-allocated copy of this message.

Reimplements

valid

virtual const

virtual bool valid() const

Defined 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() const

Defined in src/symple/include/icy/symple/message.h:64

Returns the message type string (defaults to "message").


id

const

std::string id() const

Defined in src/symple/include/icy/symple/message.h:67

Returns the message ID string.


to

const

Address to() const

Defined in src/symple/include/icy/symple/message.h:70

Returns the recipient address parsed from the to field.


from

const

Address from() const

Defined in src/symple/include/icy/symple/message.h:73

Returns the sender address parsed from the from field.


toUser

const

std::string toUser() const

Defined 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() const

Defined 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() const

Defined 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() const

Defined 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() const

Defined 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

  • type Type 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

  • to Destination 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

  • to Destination 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

  • to Destination 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

  • from Sender 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

  • from Sender 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

  • from Sender 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

  • code HTTP 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

  • type Note severity: info, warn, or error.

  • text Note 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

  • type Note severity: info, warn, or error.

  • text Note message text.


data

const

json::Value data(std::string_view name) const

Defined in src/symple/include/icy/symple/message.h:139

Returns a copy of the named data field.

Parameters

  • name Field name within data.

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

  • name Field name within data.

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

  • name Field name within data.

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

  • name Field name within data.

  • data String 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

  • name Field name within data.

  • data String 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

  • name Field name within data.

  • data JSON 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

  • name Field name within data.

  • data Integer 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

  • name Field 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

  • name Field name to look up.

read

virtual override

virtual ssize_t read(const ConstBuffer & buf) override

Defined in src/symple/include/icy/symple/message.h:180

Deserialises the message from a raw buffer.

Parameters

  • buf Buffer 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

  • root JSON string to parse.

Returns

Number of characters consumed.


write

virtual const override

virtual void write(Buffer & buf) const override

Defined in src/symple/include/icy/symple/message.h:189

Serialises the message as JSON into a buffer.

Parameters

  • buf Buffer to append to.
Reimplements

isRequest

const

bool isRequest() const

Defined 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 override

Defined in src/symple/include/icy/symple/message.h:195

Returns the serialised JSON size in bytes.

Reimplements

print

virtual const override

virtual void print(std::ostream & os) const override

Defined in src/symple/include/icy/symple/message.h:199

Pretty-prints the message JSON to the given stream.

Parameters

  • os Output stream.
Reimplements

className

virtual const inline override

virtual inline const char * className() const override

Defined 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() const

Defined 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() const

Defined in src/symple/include/icy/symple/message.h:32

Returns true if the packet has a non-null data pointer.

Reimplements