CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
cmlabs::MessageProtocol Class Reference

Binary DataMessage protocol handler: size-prefixed serialised messages. More...

#include <NetworkProtocols.h>

Inheritance diagram for cmlabs::MessageProtocol:
[legend]
Collaboration diagram for cmlabs::MessageProtocol:
[legend]

Public Member Functions

 MessageProtocol ()
Public Member Functions inherited from cmlabs::NetworkProtocol
 NetworkProtocol ()

Static Public Member Functions

static bool CheckBufferForCompatibility (const char *buffer, uint32 length)
static bool InitialiseConversation (NetworkConnection *con)
 Perform the initial message-protocol greeting.
static bool SendMessage (NetworkConnection *con, DataMessage *msg, uint64 receiver=0)
 Serialise and send one message.
static DataMessageReceiveMessage (NetworkConnection *con, uint32 timeout)
 Read one full message frame.
Static Public Member Functions inherited from cmlabs::NetworkProtocol
static bool CheckBufferForCompatibility (const char *buffer, uint32 length)
 Sniff whether buffer looks like this protocol.
static bool InitialiseConversation (NetworkConnection *con)
 Perform any protocol-specific initial exchange on a new connection.

Additional Inherited Members

Public Attributes inherited from cmlabs::NetworkProtocol
uint8 protocol
 PROTOCOL_* id of this handler.

Detailed Description

Binary DataMessage protocol handler: size-prefixed serialised messages.

The native CMSDK inter-node protocol. A "frame" is simply the serialised DataMessage memory image: its first uint32 is the total size, followed by the DATAMESSAGEID object id — ReceiveMessage() peeks those 8 bytes, then reads exactly size bytes and hands the buffer to a DataMessage that adopts it (zero-copy). Used by NetworkChannel::MessageConnectionRun() and the Request* classes.

Note
The size field is not byte-order converted on the wire; both peers must share the same endianness (see the file-level byte-order notes). A blocking send/receive round-trip over an established connection:
DataMessage* out = new DataMessage();
out->setString("URI", "ping");
MessageProtocol::SendMessage(con, out); // con keeps nothing; we still own out
delete out;
DataMessage* in = MessageProtocol::ReceiveMessage(con, 3000); // we own in
if (in) { delete in; } // use it, then delete — caller owns the reply
The central Psyclone data container: a self-contained binary message with typed, named user entries.
bool setString(const char *key, const char *value)
setString(const char* key, const char* value)
static bool SendMessage(NetworkConnection *con, DataMessage *msg, uint64 receiver=0)
Serialise and send one message.
static DataMessage * ReceiveMessage(NetworkConnection *con, uint32 timeout)
Read one full message frame.

Definition at line 887 of file NetworkProtocols.h.

Constructor & Destructor Documentation

◆ MessageProtocol()

cmlabs::MessageProtocol::MessageProtocol ( )
inline

Definition at line 890 of file NetworkProtocols.h.

References cmlabs::NetworkProtocol::protocol, and PROTOCOL_MESSAGE.

Member Function Documentation

◆ CheckBufferForCompatibility()

bool cmlabs::MessageProtocol::CheckBufferForCompatibility ( const char * buffer,
uint32 length )
static
Returns
true when buffer starts with the DataMessage frame signature.

Definition at line 2307 of file NetworkProtocols.cpp.

References DATAMESSAGEID, and GetObjID.

Referenced by cmlabs::NetworkChannel::ConnectionAutodetectRun().

◆ InitialiseConversation()

bool cmlabs::MessageProtocol::InitialiseConversation ( NetworkConnection * con)
static

Perform the initial message-protocol greeting.

Parameters
conConnection.
Returns
true on success.

Definition at line 2313 of file NetworkProtocols.cpp.

◆ ReceiveMessage()

DataMessage * cmlabs::MessageProtocol::ReceiveMessage ( NetworkConnection * con,
uint32 timeout )
static

Read one full message frame.

Parameters
conConnection.
timeoutMax wait in ms.
Returns
New DataMessage owned by the caller, or NULL. Blocking.

Definition at line 2326 of file NetworkProtocols.cpp.

References DATAMESSAGEID, GetObjID, and cmlabs::NetworkConnection::receive().

Referenced by cmlabs::NetworkChannel::MessageConnectionRun().

◆ SendMessage()

bool cmlabs::MessageProtocol::SendMessage ( NetworkConnection * con,
DataMessage * msg,
uint64 receiver = 0 )
static

Serialise and send one message.

Parameters
conConnection.
msgMessage (caller keeps ownership).
receiverDestination endpoint for datagram transports (0 for TCP).
Returns
true if fully sent.

Definition at line 2317 of file NetworkProtocols.cpp.

References cmlabs::DataMessage::data, cmlabs::DataMessage::getSize(), and cmlabs::NetworkConnection::send().

Referenced by cmlabs::NetworkChannel::sendMessage(), and cmlabs::NetworkManager::sendUDPMessage().


The documentation for this class was generated from the following files: