Main MRPT website > C++ reference for MRPT 1.9.9
List of all members | Public Member Functions | Public Attributes
mrpt::serialization::CMessage Class Reference

Detailed Description

A class that contain generic messages, that can be sent and received from a "CClientTCPSocket" object.

A message consists of a "header" (or type), and a "body" (or content). Apart from arbitrary data, specific methods are provided for easing the serialization of MRPT's "CSerializable" objects. This class is also used for passing data to hardware interfaces (see mrpt::comms::CSerialPort)

See also
CClientTCPSocket

Definition at line 29 of file CMessage.h.

#include <mrpt/serialization/CMessage.h>

Public Member Functions

void serializeObject (const CSerializable *obj)
 A method for serializing a MRPT's object into the content. More...
 
void deserializeIntoExistingObject (CSerializable *obj)
 A method that parse the data in the message into an existing object. More...
 
void deserializeIntoNewObject (CSerializable::Ptr &obj)
 A method that parse the data in the message into a new object of (a priori) unknown class. More...
 
void setContentFromString (const std::string &str)
 Sets the contents of the message from a string. More...
 
void getContentAsString (std::string &str)
 Gets the contents of the message as a string. More...
 
void setContentFromPointer (void *ptr)
 Sets the contents of the message from a "void*" (the pointer itself becomes the message) - This is intended for inter-thread comms only. More...
 
voidgetContentAsPointer () const
 Gets the contents of the message as a "void*" (the pointer itself is the message) - This is intended for inter-thread comms only. More...
 
template<class T >
void setContentFromStruct (const T &data)
 Sets the contents of the message from an arbitary structure - This is intended for inter-thread comms only, the message will be not cross-platform. More...
 
template<class T >
void getContentAsStruct (T &data) const
 Gets the contents of the message as an arbitary structure - This is intended for inter-thread comms only, the message will be not cross-platform. More...
 

Public Attributes

uint32_t type
 An identifier of the message type (only the least-sig byte is typically sent) More...
 
std::vector< uint8_tcontent
 The contents of the message (memory is automatically handled by the std::vector object) More...
 

Member Function Documentation

◆ deserializeIntoExistingObject()

void CMessage::deserializeIntoExistingObject ( CSerializable obj)

A method that parse the data in the message into an existing object.

Note that the class of the object must be known and must match the one of the serialized object. \except std::exception On corrupt data, unknown serialized objects, unknown serialized object version, non-matching classes,...

Definition at line 44 of file CMessage.cpp.

References content, MRPT_END, and MRPT_START.

Referenced by thread_client().

◆ deserializeIntoNewObject()

void CMessage::deserializeIntoNewObject ( CSerializable::Ptr obj)

A method that parse the data in the message into a new object of (a priori) unknown class.

The pointer will contain on return a copy of the reconstructed object. Deleting this object when no longer required is the responsability of the user. Note that previous contents of the pointer will be ignored (it should be nullptr). \except std::exception On corrupt data, unknown serialized objects, unknown serialized object version,...

Definition at line 63 of file CMessage.cpp.

References content, MRPT_END, and MRPT_START.

◆ getContentAsPointer()

void * CMessage::getContentAsPointer ( ) const

Gets the contents of the message as a "void*" (the pointer itself is the message) - This is intended for inter-thread comms only.

See also
setContentFromPointer

Definition at line 115 of file CMessage.cpp.

References ASSERT_, content, MRPT_END, and MRPT_START.

◆ getContentAsString()

void CMessage::getContentAsString ( std::string str)

◆ getContentAsStruct()

template<class T >
void mrpt::serialization::CMessage::getContentAsStruct ( T &  data) const
inline

Gets the contents of the message as an arbitary structure - This is intended for inter-thread comms only, the message will be not cross-platform.

See also
setContentFromStruct

Definition at line 107 of file CMessage.h.

References ASSERT_, content, MRPT_END, and MRPT_START.

◆ serializeObject()

void CMessage::serializeObject ( const CSerializable obj)

A method for serializing a MRPT's object into the content.

Any modification to data in "content" after this will corrupt the object serialization. Member "type" is unmodified in this method.

Definition at line 21 of file CMessage.cpp.

References content, mrpt::system::os::memcpy(), MRPT_END, and MRPT_START.

Referenced by thread_server().

◆ setContentFromPointer()

void CMessage::setContentFromPointer ( void ptr)

Sets the contents of the message from a "void*" (the pointer itself becomes the message) - This is intended for inter-thread comms only.

See also
getContentAsPointer

Definition at line 105 of file CMessage.cpp.

References content.

◆ setContentFromString()

void CMessage::setContentFromString ( const std::string str)

Sets the contents of the message from a string.

See also
getContentAsString

Definition at line 87 of file CMessage.cpp.

References content, and mrpt::system::os::memcpy().

◆ setContentFromStruct()

template<class T >
void mrpt::serialization::CMessage::setContentFromStruct ( const T &  data)
inline

Sets the contents of the message from an arbitary structure - This is intended for inter-thread comms only, the message will be not cross-platform.

See also
getContentAsStruct

Definition at line 94 of file CMessage.h.

References content.

Member Data Documentation

◆ content

std::vector<uint8_t> mrpt::serialization::CMessage::content

◆ type

uint32_t mrpt::serialization::CMessage::type



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST