Serialization functions for ZMQ (v3 or above) (in #include <mrpt/serialization/serialization_zmq.h>)¶
// namespaces namespace mrpt::serialization::internal; // global functions template <typename ZMQ_SOCKET_TYPE> void mrpt::serialization::mrpt_send_to_zmq( ZMQ_SOCKET_TYPE zmq_socket, const mrpt::serialization::CSerializable& obj, const size_t max_packet_len = 0 ); template <typename ZMQ_SOCKET_TYPE, typename VECTOR_MSG_T> bool mrpt::serialization::mrpt_recv_from_zmq_buf( ZMQ_SOCKET_TYPE zmq_socket, VECTOR_MSG_T& out_lst_msgs, mrpt::io::CMemoryStream& target_buf, bool dont_wait, size_t* rx_obj_length_in_bytes ); template <typename ZMQ_SOCKET_TYPE> mrpt::serialization::CSerializable::Ptr mrpt::serialization::mrpt_recv_from_zmq( ZMQ_SOCKET_TYPE zmq_socket, bool dont_wait = false, size_t* rx_obj_length_in_bytes = nullptr ); template <typename ZMQ_SOCKET_TYPE> bool mrpt::serialization::mrpt_recv_from_zmq_into( ZMQ_SOCKET_TYPE zmq_socket, mrpt::serialization::CSerializable& target_object, bool dont_wait = false, size_t* rx_obj_length_in_bytes = nullptr );
Global Functions¶
template <typename ZMQ_SOCKET_TYPE> void mrpt::serialization::mrpt_send_to_zmq( ZMQ_SOCKET_TYPE zmq_socket, const mrpt::serialization::CSerializable& obj, const size_t max_packet_len = 0 )
Send an MRPT object to a ZMQ socket.
Including <mrpt/serialization/serialization_zmq.h>
requires libzmq to be available in your system and linked to your user code. This function can be used even if MRPT was built without ZMQ support, thanks to the use of templates.
See examples of usage in https://github.com/MRPT/mrpt/tree/master/doc/mrpt-zeromq-example
Parameters:
obj |
The object to be serialized and sent to the socket. |
zmq_socket |
The zmq socket object. |
max_packet_len |
The object will be split into a series of ZMQ “message parts” of this maximum length (in bytes). Default=0, which means do not split in parts. |
std::exception |
If the object finds any critical error during serialization or on ZMQ errors. |
template <typename ZMQ_SOCKET_TYPE, typename VECTOR_MSG_T> bool mrpt::serialization::mrpt_recv_from_zmq_buf( ZMQ_SOCKET_TYPE zmq_socket, VECTOR_MSG_T& out_lst_msgs, mrpt::io::CMemoryStream& target_buf, bool dont_wait, size_t* rx_obj_length_in_bytes )
Users may normally call mrpt_recv_from_zmq() and mrpt_recv_from_zmq_into().
This function just stores the received data into a memory buffer without parsing it into an MRPT object.
Returns:
false on any error
template <typename ZMQ_SOCKET_TYPE> mrpt::serialization::CSerializable::Ptr mrpt::serialization::mrpt_recv_from_zmq( ZMQ_SOCKET_TYPE zmq_socket, bool dont_wait = false, size_t* rx_obj_length_in_bytes = nullptr )
Receives an MRPT object from a ZMQ socket, determining the type of the object on-the-fly.
Including <mrpt/serialization/serialization_zmq.h>
requires libzmq to be available in your system and linked to your user code. This function can be used even if MRPT was built without ZMQ support, thanks to the use of templates.
See examples of usage in https://github.com/MRPT/mrpt/tree/master/doc/mrpt-zeromq-example
Parameters:
zmq_socket |
The zmq socket object. |
dont_wait |
If true, will fail if there is no data ready to be read. If false (default) this function will block until data arrives. |
rx_obj_length_in_bytes |
If non-nullptr, the object length will be stored here. |
std::exception |
If the object finds any critical error during de-serialization. |
Returns:
An empty smart pointer if there was any error. The received object if all went OK.
See also:
template <typename ZMQ_SOCKET_TYPE> bool mrpt::serialization::mrpt_recv_from_zmq_into( ZMQ_SOCKET_TYPE zmq_socket, mrpt::serialization::CSerializable& target_object, bool dont_wait = false, size_t* rx_obj_length_in_bytes = nullptr )
Like mrpt_recv_from_zmq() but without dynamically allocating the received object, more efficient to use if the type of the received object is known in advance.
See examples of usage in https://github.com/MRPT/mrpt/tree/master/doc/mrpt-zeromq-example
Parameters:
target_object |
The received object will be stored here. An exception will be raised upon type mismatch. |
Returns:
true if all was OK, false on any ZMQ error.
See also:
mrpt_recv_from_zmq() for details on the rest of parameters.