mirror of
https://github.com/zeromq/cppzmq.git
synced 2024-12-12 18:40:28 +01:00
Merge pull request #373 from gummif/gfa/tostring
Problem: message_t to string is hard
This commit is contained in:
commit
bd27f24960
@ -151,6 +151,18 @@ TEST_CASE("message equality non equal lhs empty", "[message]")
|
|||||||
CHECK(msg_a != msg_b);
|
CHECK(msg_a != msg_b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("message to string", "[message]")
|
||||||
|
{
|
||||||
|
const zmq::message_t a;
|
||||||
|
const zmq::message_t b("Foo", 3);
|
||||||
|
CHECK(a.to_string() == "");
|
||||||
|
CHECK(b.to_string() == "Foo");
|
||||||
|
#ifdef ZMQ_CPP17
|
||||||
|
CHECK(a.to_string_view() == "");
|
||||||
|
CHECK(b.to_string_view() == "Foo");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(ZMQ_BUILD_DRAFT_API) && ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 2, 0)
|
#if defined(ZMQ_BUILD_DRAFT_API) && ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 2, 0)
|
||||||
TEST_CASE("message routing id persists", "[message]")
|
TEST_CASE("message routing id persists", "[message]")
|
||||||
{
|
{
|
||||||
|
22
zmq.hpp
22
zmq.hpp
@ -552,9 +552,25 @@ class message_t
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** Dump content to string. Ascii chars are readable, the rest is printed as hex.
|
// interpret message content as a string
|
||||||
* Probably ridiculously slow.
|
std::string to_string() const
|
||||||
*/
|
{
|
||||||
|
return std::string(static_cast<const char*>(data()), size());
|
||||||
|
}
|
||||||
|
#ifdef ZMQ_CPP17
|
||||||
|
// interpret message content as a string
|
||||||
|
std::string_view to_string_view() const noexcept
|
||||||
|
{
|
||||||
|
return std::string_view(static_cast<const char*>(data()), size());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** Dump content to string for debugging.
|
||||||
|
* Ascii chars are readable, the rest is printed as hex.
|
||||||
|
* Probably ridiculously slow.
|
||||||
|
* Use to_string() or to_string_view() for
|
||||||
|
* interpreting the message as a string.
|
||||||
|
*/
|
||||||
std::string str() const
|
std::string str() const
|
||||||
{
|
{
|
||||||
// Partly mutuated from the same method in zmq::multipart_t
|
// Partly mutuated from the same method in zmq::multipart_t
|
||||||
|
Loading…
Reference in New Issue
Block a user