MRPT
2.0.1
|
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)
Definition at line 27 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... | |
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_t > | content |
The contents of the message (memory is automatically handled by the std::vector object) More... | |
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. 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().
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). 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.
void CMessage::getContentAsString | ( | std::string & | str | ) |
Gets the contents of the message as a string.
Definition at line 96 of file CMessage.cpp.
References content, and mrpt::system::os::memcpy().
Referenced by mrpt::hwdrivers::CServoeNeck::queryFirmwareVersion(), mrpt::hwdrivers::CBoardSonars::queryFirmwareVersion(), and mrpt::hwdrivers::CBoardENoses::queryFirmwareVersion().
|
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.
Definition at line 93 of file CMessage.h.
References ASSERT_, content, mrpt::opengl::internal::data, MRPT_END, and MRPT_START.
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::opengl::internal::data, mrpt::system::os::memcpy(), MRPT_END, and MRPT_START.
Referenced by thread_server().
void CMessage::setContentFromString | ( | const std::string & | str | ) |
Sets the contents of the message from a string.
Definition at line 87 of file CMessage.cpp.
References content, and mrpt::system::os::memcpy().
|
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.
Definition at line 80 of file CMessage.h.
References content, and mrpt::opengl::internal::data.
std::vector<uint8_t> mrpt::serialization::CMessage::content |
The contents of the message (memory is automatically handled by the std::vector object)
Definition at line 35 of file CMessage.h.
Referenced by deserializeIntoExistingObject(), deserializeIntoNewObject(), mrpt::hwdrivers::CServoeNeck::disableServo(), mrpt::hwdrivers::CServoeNeck::enableServo(), mrpt::hwdrivers::CRoboticHeadInterface::Get3SoundBuffer(), getContentAsString(), getContentAsStruct(), mrpt::hwdrivers::CRoboticHeadInterface::GetGain(), mrpt::hwdrivers::CBoardSonars::getObservation(), mrpt::hwdrivers::CEnoseModular::getObservation(), mrpt::hwdrivers::CBoardENoses::getObservation(), mrpt::hwdrivers::CServoeNeck::getRegisterValue(), mrpt::hwdrivers::CRoboticHeadInterface::GetSoundLocation(), mrpt::hwdrivers::CBoardSonars::programI2CAddress(), mrpt::serialization::CArchive::receiveMessage(), mrpt::hwdrivers::CBoardSonars::sendConfigCommands(), mrpt::serialization::CArchive::sendMessage(), serializeObject(), setContentFromString(), setContentFromStruct(), mrpt::hwdrivers::CRoboticHeadInterface::SetGain(), mrpt::hwdrivers::CServoeNeck::setRegisterValue(), mrpt::hwdrivers::CServoeNeck::setRegisterValueAndSpeed(), and thread_client().
uint32_t mrpt::serialization::CMessage::type |
An identifier of the message type (only the least-sig byte is typically sent)
Definition at line 32 of file CMessage.h.
Referenced by mrpt::hwdrivers::CServoeNeck::disableServo(), mrpt::hwdrivers::CServoeNeck::enableServo(), mrpt::hwdrivers::CRoboticHeadInterface::Get3SoundBuffer(), mrpt::hwdrivers::CRoboticHeadInterface::GetGain(), mrpt::hwdrivers::CBoardSonars::getObservation(), mrpt::hwdrivers::CServoeNeck::getRegisterValue(), mrpt::hwdrivers::CRoboticHeadInterface::GetSoundLocation(), mrpt::hwdrivers::CBoardSonars::programI2CAddress(), mrpt::hwdrivers::CServoeNeck::queryFirmwareVersion(), mrpt::hwdrivers::CBoardSonars::queryFirmwareVersion(), mrpt::hwdrivers::CBoardENoses::queryFirmwareVersion(), mrpt::serialization::CArchive::receiveMessage(), mrpt::hwdrivers::CBoardSonars::sendConfigCommands(), mrpt::serialization::CArchive::sendMessage(), mrpt::hwdrivers::CRoboticHeadInterface::SetGain(), mrpt::hwdrivers::CServoeNeck::setRegisterValue(), mrpt::hwdrivers::CServoeNeck::setRegisterValueAndSpeed(), thread_client(), and thread_server().
Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020 |