Loading...
Searching...
No Matches
Message Class Reference

`#include <avogadro/rpc/message.h>`

## Public Types

enum | MessageType { Request = 0x1 , Notification = 0x2 , Response = 0x4 , Error = 0x8 , Raw = 0x10 , Invalid = 0x20 }

## Public Member Functions

| Message (Connection *conn=nullptr, EndpointIdType endpoint_=EndpointIdType())
| Message (MessageType type_, Connection *conn=nullptr, EndpointIdType endpoint_=EndpointIdType())
| Message (const QJsonObject &rawJson, Connection *conn=nullptr, EndpointIdType endpoint_=EndpointIdType())
| Message (const Message &other)
Message & | operator= (const Message &other)
MessageType | type () const
QString | method () const
void | setMethod (const QString &m)
QJsonValue | params () const
QJsonValue & | paramsRef ()
void | setParams (const QJsonArray &p)
void | setParams (const QJsonObject &p)
QJsonValue | result () const
QJsonValue & | resultRef ()
void | setResult (const QJsonValue &r)
int | errorCode () const
void | setErrorCode (int e)
QString | errorMessage () const
void | setErrorMessage (const QString &e)
QJsonValue | errorData () const
QJsonValue & | errorDataRef ()
void | setErrorData (const QJsonValue &e)
MessageIdType | id () const
Connection * | connection () const
void | setConnection (Connection *c)
EndpointIdType | endpoint () const
void | setEndpoint (const EndpointIdType &e)
QJsonObject | toJsonObject () const
PacketType | toJson () const
bool | send ()
Message | generateResponse () const
Message | generateErrorResponse () const
bool | parse ()
bool | parse (Message &errorMessage_)

## Protected Member Functions

void | setId (const MessageIdType &i)

## Detailed Description

The Message class encapsulates a single JSON-RPC transmission.

The Message class provides an interface to construct, interpret, and manipulate JSON-RPC messages.

There are four types of valid JSON-RPC messages: Requests, notifications, responses, and errors. The type() method can be used to determine a given Message's MessageType.

## Member Enumeration Documentation

## MessageType

enum MessageType

Flags representing different types of JSON-RPC messages.

Enumerator
Request | A JSON-RPC request, with id, method, and params attributes.
Notification | A JSON-RPC notification, with method and params attributes.
Response | A JSON-RPC response, with id, method, and result attributes.
Error | A JSON-RPC error, with id, method, and errorCode, errorMessage, and errorData attributes.
Raw | This MessageType indicates that this Message holds a raw QJsonObject that has not been interpreted. Call parse() to convert this Message into an appropriate type.
Invalid | This Message is invalid.

## Constructor & Destructor Documentation

## Message() [1/4]

Message | ( | Connection * | conn = nullptr,
|  | EndpointIdType | endpoint_ = EndpointIdType() )

Construct an Invalid Message using the conn and endpoint_.

## Message() [2/4]

Message | ( | Message::MessageType | type_,
|  | Connection * | conn = nullptr,
|  | EndpointIdType | endpoint_ = EndpointIdType() )

Construct an empty Message with the specified type that uses the conn and endpoint_.

## Message() [3/4]

Message | ( | const QJsonObject & | rawJson,
|  | Connection * | conn = nullptr,
|  | EndpointIdType | endpoint_ = EndpointIdType() )

Construct a Raw Message with the specified type that uses the conn and endpoint_. The rawJson QJsonObject will be cached to be parsed by parse() later.

## Message() [4/4]

Message | ( | const Message & | other | ) |

Copy constructor.

## Member Function Documentation

## operator=()

Message & operator= | ( | const Message & | other | ) |

Assignment operator.

## type()

Message::MessageType type | ( |  | ) | const

Returns
  The MessageType of this Message.

## method()

QString method | ( |  | ) | const

The name of the method used in the remote procedure call.

Note
  This function is only valid for Request, Notification, Response, and Error messages.

## params()

QJsonValue params | ( |  | ) | const

The parameters used in the remote procedure call.

Note
  This function is only valid for Request and Notification messages.

## result()

QJsonValue result | ( |  | ) | const

The result object used in a remote procedure call response.

Note
  This function is only valid for Response messages.

## errorCode()

int errorCode | ( |  | ) | const

The integral error code used in a remote procedure call error response.

Note
  This function is only valid for Error messages.

## errorMessage()

QString errorMessage | ( |  | ) | const

The error message string used in a remote procedure call error response.

Note
  This function is only valid for Error messages.

## errorData()

QJsonValue errorData | ( |  | ) | const

The data object used in a remote procedure call error response.

Note
  This function is only valid for Error messages.

## id()

MessageIdType id | ( |  | ) | const

The message id used in a remote procedure call.

Note
  This function is only valid for Request, Response, and Error messages.

## connection()

Connection * connection | ( |  | ) | const

The connection associated with the remote procedure call.

## endpoint()

EndpointIdType endpoint | ( |  | ) | const

The connection endpoint associated with the remote procedure call.

## toJsonObject()

QJsonObject toJsonObject | ( |  | ) | const

Returns
  A QJsonObject representation of the remote procedure call.

## toJson()

PacketType toJson | ( |  | ) | const

Returns
  A string representation of the remote procedure call.

## send()

bool send | ( |  | ) |

Send the message to the associated connection and endpoint.

Returns
  True on success, false on failure.

Note
  If this message is a Request, a unique id will be assigned prior to sending. Use the id() method to retrieve the assigned id.

## generateResponse()

Message generateResponse | ( |  | ) | const

Create a new Response message in reply to a Request. The connection, endpoint, id, and method will be copied from this Message.

Note
  This function is only valid for Request messages.

## generateErrorResponse()

Message generateErrorResponse | ( |  | ) | const

Create a new Error message in reply to a Request. The connection, endpoint, id, and method will be copied from this Message.

Note
  This function is only valid for Request, Raw, and Invalid messages.

## parse()

bool parse | ( |  | ) |

Interpret the raw QJsonObject passed to the constructor.

Returns
  True on success, false on failure.

Note
  This function is only valid for Raw messages.