Skip to content

Commit 582fe38

Browse files
committed
Merge branch 'fix_issue_167'
2 parents 45eb2ad + 6443738 commit 582fe38

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

include/msgpack/adaptor/char_ptr.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ inline void operator<< (object& o, const char* v)
5353
o.via.str.size = static_cast<uint32_t>(size);
5454
}
5555

56+
template <typename Stream>
57+
inline packer<Stream>& operator<< (packer<Stream>& o, char* v)
58+
{
59+
return msgpack::operator<<(o, static_cast<const char*>(v));
60+
}
61+
62+
inline void operator<< (object::with_zone& o, char* v)
63+
{
64+
msgpack::operator<<(o, static_cast<const char*>(v));
65+
}
66+
67+
inline void operator<< (object& o, char* v)
68+
{
69+
msgpack::operator<<(o, static_cast<const char*>(v));
70+
}
71+
5672
} // MSGPACK_API_VERSION_NAMESPACE(v1)
5773

5874
} // namespace msgpack

include/msgpack/adaptor/char_ptr_fwd.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ packer<Stream>& operator<< (packer<Stream>& o, const char* v);
3131
void operator<< (object::with_zone& o, const char* v);
3232
void operator<< (object& o, const char* v);
3333

34+
template <typename Stream>
35+
packer<Stream>& operator<< (packer<Stream>& o, char* v);
36+
void operator<< (object::with_zone& o, char* v);
37+
void operator<< (object& o, char* v);
38+
3439
} // MSGPACK_API_VERSION_NAMESPACE(v1)
3540

3641
} // namespace msgpack

test/msgpack_basic.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,3 +497,23 @@ TEST(MSGPACK_STL, simple_buffer_cstring)
497497
EXPECT_EQ(val1, val2);
498498
}
499499
}
500+
501+
TEST(MSGPACK_STL, simple_buffer_non_const_cstring)
502+
{
503+
for (unsigned int k = 0; k < kLoop; k++) {
504+
string val1;
505+
for (unsigned int i = 0; i < kElements; i++)
506+
val1 += 'a' + rand() % 26;
507+
msgpack::sbuffer sbuf;
508+
char* s = new char[val1.size() + 1];
509+
std::strcpy(s, val1.c_str());
510+
msgpack::pack(sbuf, s);
511+
delete [] s;
512+
msgpack::unpacked ret;
513+
msgpack::unpack(ret, sbuf.data(), sbuf.size());
514+
EXPECT_EQ(ret.get().type, msgpack::type::STR);
515+
string val2 = ret.get().as<string>();
516+
EXPECT_EQ(val1.size(), val2.size());
517+
EXPECT_EQ(val1, val2);
518+
}
519+
}

0 commit comments

Comments
 (0)