6 #ifndef NANOSOCKETS_ZMQ_MSG_VECTOR_HPP 7 #define NANOSOCKETS_ZMQ_MSG_VECTOR_HPP 12 #include <core/storage/serialization/oarchive.hpp> 13 #include <core/storage/serialization/iarchive.hpp> 14 #include <core/export.hpp> 41 class EXPORT zmq_msg_vector {
43 zmq_msg_vector():read_index(0) { }
44 zmq_msg_vector(
const zmq_msg_vector& other) {
48 zmq_msg_vector& operator=(
const zmq_msg_vector& other) {
49 clone_from(const_cast<zmq_msg_vector&>(other));
53 inline ~zmq_msg_vector() {
57 void clone_from(zmq_msg_vector& other) {
63 inline size_t size()
const {
68 inline const nn_msg_t* operator[](
size_t i)
const {
69 auto iter = msgs.begin();
75 inline nn_msg_t* operator[](
size_t i) {
76 auto iter = msgs.begin();
82 inline bool empty()
const {
90 inline nn_msg_t* insert_back() {
98 inline void insert_back(nn_msg_t& msg) {
105 inline nn_msg_t* insert_back(
const void* c,
size_t len) {
106 msgs.push_back(
nn_msg_t(reinterpret_cast<const char*>(c), len));
107 return &(msgs.back());
113 inline nn_msg_t* insert_back(
const std::string& s) {
115 return &(msgs.back());
123 inline nn_msg_t* insert_front() {
125 return &(msgs.front());
132 inline void insert_front(nn_msg_t& msg) {
139 inline nn_msg_t* insert_front(
const void* c,
size_t len) {
140 msgs.push_front(
nn_msg_t(reinterpret_cast<const char*>(c), len));
141 return &(msgs.front());
147 inline nn_msg_t* insert_front(
const std::string& s) {
149 return &(msgs.front());
158 inline nn_msg_t* read_next() {
159 if (read_index >= size())
return NULL;
160 nn_msg_t* ret = (*this)[read_index];
166 inline size_t get_read_index()
const {
171 inline size_t num_unread_msgs()
const {
172 return size() - get_read_index();
176 inline void reset_read_index() {
182 inline void clear() {
188 inline void pop_front() {
192 read_index -= (read_index > 0);
197 inline void pop_back() {
204 inline nn_msg_t* back() {
212 inline nn_msg_t* front() {
214 return &msgs.front();
225 inline void assert_pop_front(
const void* c,
size_t len) {
227 assert(msgs.front().length() == len);
229 assert(memcmp(msgs.front().data(), c, len) == 0);
231 pop_front_and_free();
234 inline void assert_pop_front(
const std::string& s) {
235 assert_pop_front(s.c_str(), s.length());
239 inline std::string extract_front() {
241 std::string ret = std::move(msgs.front());
242 pop_front_and_free();
246 inline void extract_front(
void* c,
size_t clen) {
248 assert(clen == msgs.front().length());
250 memcpy(c, msgs.front().data(), clen);
252 pop_front_and_free();
256 inline void pop_front_and_free() {
260 read_index -= (read_index > 0);
270 int send(
int socket,
int timeout);
277 int send(
int socket);
286 int recv(
int socket,
int timeout);
293 int recv(
int socket);
306 std::list<nn_msg_t> msgs;
317 int send_impl(
int socket,
int timeout);
325 int send_impl(
int socket);
335 int recv_impl(
int socket,
int timeout);
343 int recv_impl(
int socket);
The serialization input archive object which, provided with a reference to an istream, will read from the istream, providing deserialization capabilities.
The serialization output archive object which, provided with a reference to an ostream, will write to the ostream, providing serialization capabilities.