mirror of
https://github.com/zeromq/cppzmq.git
synced 2025-05-20 13:05:34 +02:00
Consistently indented some preprocessor directives.
Added a str() method and companion operator<<(std::ostream) similar to multipart_t. Added some comments to mark the end of preprocessor instructions / class def / namespace def.
This commit is contained in:
parent
f945a7d032
commit
0d1c20e2ea
56
zmq.hpp
56
zmq.hpp
@ -42,13 +42,17 @@
|
||||
|
||||
#include <zmq.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#include <algorithm>
|
||||
#include <exception>
|
||||
#include <vector>
|
||||
#include <iomanip>
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
#ifdef ZMQ_CPP11
|
||||
#include <chrono>
|
||||
@ -378,6 +382,42 @@ namespace zmq
|
||||
return value;
|
||||
}
|
||||
#endif
|
||||
/** Dump content to string. Ascii chars are readable, the rest is printed as hex.
|
||||
* Probably ridiculously slow.
|
||||
*/
|
||||
inline std::string str() const
|
||||
{
|
||||
// Partly mutuated from the same method in zmq::multipart_t
|
||||
std::stringstream os;
|
||||
|
||||
const unsigned char* msg_data = this->data<unsigned char>();
|
||||
unsigned char byte;
|
||||
size_t size = this->size();
|
||||
int is_ascii[2] = {0, 0};
|
||||
|
||||
os << "zmq::message_t [size " << std::dec << std::setw(3) << std::setfill('0') << size << "] (";
|
||||
// Totally arbitrary
|
||||
if (size >= 1000) {
|
||||
os << "... too big to print)";
|
||||
} else {
|
||||
while (size--) {
|
||||
byte = *msg_data++;
|
||||
|
||||
is_ascii[1] = (byte >= 33 && byte < 127);
|
||||
if (is_ascii[1] != is_ascii[0])
|
||||
os << " "; // Separate text/non text
|
||||
|
||||
if (is_ascii[1]) {
|
||||
os << byte;
|
||||
} else {
|
||||
os << std::hex << std::uppercase << std::setw(2) << std::setfill('0') << static_cast<short>(byte);
|
||||
}
|
||||
is_ascii[0] = is_ascii[1];
|
||||
}
|
||||
os << ")";
|
||||
}
|
||||
return os.str();
|
||||
}
|
||||
|
||||
private:
|
||||
// The underlying message
|
||||
@ -995,9 +1035,15 @@ namespace zmq
|
||||
private:
|
||||
void *poller_ptr;
|
||||
std::vector<zmq_poller_event_t> poller_events;
|
||||
};
|
||||
}; // class poller_t
|
||||
#endif // defined(ZMQ_BUILD_DRAFT_API) && defined(ZMQ_CPP11) && defined(ZMQ_HAVE_POLLER)
|
||||
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& os, const message_t& msg)
|
||||
{
|
||||
return os << msg.str();
|
||||
}
|
||||
|
||||
#endif
|
||||
} // namespace zmq
|
||||
|
||||
#endif // __ZMQ_HPP_INCLUDED__
|
||||
|
Loading…
x
Reference in New Issue
Block a user