17 #ifndef ZMQPP_MESSAGE_HPP_ 18 #define ZMQPP_MESSAGE_HPP_ 23 #include <unordered_map> 61 template <
typename T,
typename ...Args>
65 add(part, std::forward<Args>(args)...);
69 size_t size(
size_t const part)
const;
70 std::string
get(
size_t const part)
const;
72 void get(int8_t& integer,
size_t const part)
const;
73 void get(int16_t& integer,
size_t const part)
const;
74 void get(int32_t& integer,
size_t const part)
const;
75 void get(int64_t& integer,
size_t const part)
const;
76 void get(
signal& sig,
size_t const part)
const;
78 void get(uint8_t& unsigned_integer,
size_t const part)
const;
79 void get(uint16_t& unsigned_integer,
size_t const part)
const;
80 void get(uint32_t& unsigned_integer,
size_t const part)
const;
81 void get(uint64_t& unsigned_integer,
size_t const part)
const;
83 void get(
float& floating_point,
size_t const part)
const;
84 void get(
double& double_precision,
size_t const part)
const;
85 void get(
bool& boolean,
size_t const part)
const;
87 void get(std::string& string,
size_t const part)
const;
91 template<
typename Type>
92 Type
get(
size_t const part)
const 99 template<
int part=0,
typename T,
typename ...Args>
100 void extract(T &nextpart, Args &...args)
const 102 assert(part < parts());
104 extract<part+1>(args...);
107 template<
int part=0,
typename T>
110 assert(part < parts());
117 template<
typename Type>
118 void get(Type*& value,
size_t const part)
const 120 value =
static_cast<Type*
>(raw_data(part));
125 template<
typename Type>
126 void get(Type** value,
size_t const part)
const 128 *value =
static_cast<Type*
>(raw_data(part));
132 void move(
void* part,
size_t const size, release_function
const& release);
135 template<
typename Object>
138 move(part,
sizeof(Object), &deleter_callback<Object>);
142 template<
typename Type,
typename ...Args>
143 void add(Type
const& part, Args &&...args)
146 add(std::forward<Args>(args)...);
149 template<
typename Type>
156 template<
typename Type>
157 void add_raw(Type *part,
size_t const data_size)
159 _parts.push_back(
frame( part, data_size ) );
165 template<
typename Type>
167 void add_const(Type *part,
size_t const data_size)
169 _parts.push_back(
frame( part, data_size,
nullptr,
nullptr ) );
197 template<
typename Type>
199 zmq_free_fn *ffn =
nullptr,
void *hint =
nullptr)
201 static_assert(!std::is_const<Type>::value,
202 "Data part must not be const. Use add_nocopy_const() instead (and read its documentation)");
203 _parts.push_back(
frame(part, data_size, ffn, hint));
232 template<
typename Type>
234 zmq_free_fn *ffn =
nullptr,
void *hint =
nullptr)
236 add_nocopy(
const_cast<typename std::remove_const<Type *>::type
>(part),
237 data_size, ffn, hint);
241 void reset_read_cursor();
243 template<
typename Type>
246 get(value, _read_cursor++);
251 message& operator<<(int8_t
const integer);
252 message& operator<<(int16_t
const integer);
253 message& operator<<(int32_t
const integer);
254 message& operator<<(int64_t
const integer);
257 message& operator<<(uint8_t
const unsigned_integer);
258 message& operator<<(uint16_t
const unsigned_integer);
259 message& operator<<(uint32_t
const unsigned_integer);
260 message& operator<<(uint64_t
const unsigned_integer);
262 message& operator<<(
float const floating_point);
263 message& operator<<(
double const double_precision);
264 message& operator<<(
bool const boolean);
266 message& operator<<(
char const* c_string);
267 message& operator<<(std::string
const&
string);
270 void push_front(
void const* part,
size_t const size);
273 void push_front(int8_t
const integer);
274 void push_front(int16_t
const integer);
275 void push_front(int32_t
const integer);
276 void push_front(int64_t
const integer);
277 void push_front(
signal const sig);
279 void push_front(uint8_t
const unsigned_integer);
280 void push_front(uint16_t
const unsigned_integer);
281 void push_front(uint32_t
const unsigned_integer);
282 void push_front(uint64_t
const unsigned_integer);
284 void push_front(
float const floating_point);
285 void push_front(
double const double_precision);
286 void push_front(
bool const boolean);
288 void push_front(
char const* c_string);
289 void push_front(std::string
const&
string);
293 void push_back(
void const* part,
size_t const data_size)
295 add_raw( part, data_size );
298 template<
typename Type>
306 void remove(
size_t const part);
314 void copy(
message const& source);
317 void sent(
size_t const part);
320 void const* raw_data(
size_t const part = 0)
const;
321 zmq_msg_t& raw_msg(
size_t const part = 0);
322 zmq_msg_t& raw_new_msg();
323 zmq_msg_t& raw_new_msg(
size_t const reserve_data_size);
331 bool is_signal()
const;
350 #if (ZMQ_VERSION_MAJOR == 4 && ZMQ_VERSION_MINOR >= 1) 357 bool get_property(
const std::string &property, std::string &out);
369 static void release_callback(
void* data,
void* hint);
371 template<
typename Object>
374 delete static_cast<Object*
>(data);
void add(Type const &part, Args &&...args)
Definition: message.hpp:143
void extract(T &nextpart, Args &...args) const
Definition: message.hpp:100
#define ZMQPP_DEPRECATED(reason)
Definition: compatibility.hpp:118
#define ZMQPP_EXPLICITLY_DELETED
Definition: compatibility.hpp:107
C++ wrapper around zmq.
Definition: actor.cpp:29
message & operator>>(Type &value)
Definition: message.hpp:244
size_t next() NOEXCEPT
Moves the read cursor to the next element.
Definition: message.hpp:347
message(T const &part, Args &&...args)
Definition: message.hpp:62
void add_nocopy(Type *part, size_t const data_size, zmq_free_fn *ffn=nullptr, void *hint=nullptr)
Add a no-copy frame.
Definition: message.hpp:198
std::vector< frame > parts_type
Definition: message.hpp:361
size_t remaining() const NOEXCEPT
Gets the remaining number of parts in the message.
Definition: message.hpp:341
void push_back(Type const part)
Definition: message.hpp:299
void move(Object *part)
Definition: message.hpp:136
void add_raw(Type *part, size_t const data_size)
Definition: message.hpp:157
#define NOEXCEPT
Definition: compatibility.hpp:122
void push_back(void const *part, size_t const data_size)
Definition: message.hpp:293
void add_nocopy_const(const Type *part, size_t const data_size, zmq_free_fn *ffn=nullptr, void *hint=nullptr)
Add a no-copy frame where pointed-to data are const.
Definition: message.hpp:233
size_t read_cursor() const NOEXCEPT
Gets the read cursor.
Definition: message.hpp:336
std::function< void(void *)> release_function
callback to release user allocated data.
Definition: message.hpp:56
size_t _read_cursor
Definition: message.hpp:363
void extract(T &nextpart) const
Definition: message.hpp:108
parts_type _parts
Definition: message.hpp:362
void add(Type const part)
Definition: message.hpp:150
a zmq message with optional multipart support
Definition: message.hpp:43
#define ZMQPP_EXPORT
Definition: compatibility.hpp:39
static void deleter_callback(void *data)
Definition: message.hpp:372
signal
Signal is a 8 bytes integer.
Definition: signal.hpp:24
an internal frame wrapper for a single zmq message
Definition: frame.hpp:33