Skip to content

Commit c341dc1

Browse files
committed
Rebuild with string_view argument, like the constructor
1 parent c66fc60 commit c341dc1

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

Diff for: tests/message.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,37 @@ TEST_CASE("message equality non equal lhs empty", "[message]")
179179
CHECK(msg_a != msg_b);
180180
}
181181

182+
TEST_CASE("message rebuild with size", "[message]")
183+
{
184+
const zmq::message_t msg();
185+
msg.rebuild(5)
186+
CHECK(msg.size() == 5);
187+
}
188+
189+
#if defined(ZMQ_CPP11) && !defined(ZMQ_CPP11_PARTIAL)
190+
TEST_CASE("message rebuild with strings", "[message]")
191+
{
192+
SECTION("string")
193+
{
194+
const std::string hi(data);
195+
zmq::message_t hi_msg();
196+
hi_msg.rebuild(hi)
197+
CHECK(2u == hi_msg.size());
198+
CHECK(0 == memcmp(data, hi_msg.data(), 2));
199+
}
200+
#if CPPZMQ_HAS_STRING_VIEW
201+
SECTION("string_view")
202+
{
203+
const std::string_view hi(data);
204+
zmq::message_t hi_msg();
205+
hi_msg.rebuild(hi)
206+
CHECK(2u == hi_msg.size());
207+
CHECK(0 == memcmp(data, hi_msg.data(), 2));
208+
}
209+
#endif
210+
}
211+
#endif
212+
182213
TEST_CASE("message to string", "[message]")
183214
{
184215
const zmq::message_t a;

Diff for: zmq.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,13 @@ class message_t
544544
rebuild(str.data(), str.size());
545545
}
546546

547+
#if CPPZMQ_HAS_STRING_VIEW
548+
void rebuild(std::string_view str)
549+
{
550+
rebuild(str.data(), str.size());
551+
}
552+
#endif
553+
547554
void rebuild(void *data_, size_t size_, free_fn *ffn_, void *hint_ = ZMQ_NULLPTR)
548555
{
549556
int rc = zmq_msg_close(&msg);

0 commit comments

Comments
 (0)