Replaced msgpack::unpacked with msgpack::object_handle.

msgpack::unpacked is a typedef of the msgpack::object_handle.
I recommend using msgpack::object_handle. It can be used not only
holding unpacked msgpack objects but also msgpack::objects that are
created by any types.

Replaced unpack() APIs in test codes and examples. They used to use old
APIs.
This commit is contained in:
Takatoshi Kondo
2016-03-21 15:22:50 +09:00
parent 85164687f3
commit 1bfcf55469
43 changed files with 2357 additions and 2359 deletions

View File

@@ -84,9 +84,9 @@ int main() {
print(ss.str());
msgpack::unpacked unp;
msgpack::unpack(unp, ss.str().data(), ss.str().size());
msgpack::object obj = unp.get();
msgpack::object_handle oh =
msgpack::unpack(ss.str().data(), ss.str().size());
msgpack::object obj = oh.get();
std::cout << obj << std::endl;
assert(obj.as<my_class>() == my);
}

View File

@@ -59,9 +59,9 @@ int main() {
print(ss.str());
msgpack::unpacked unp;
msgpack::unpack(unp, ss.str().data(), ss.str().size());
msgpack::object obj = unp.get();
msgpack::object_handle oh =
msgpack::unpack(ss.str().data(), ss.str().size());
msgpack::object obj = oh.get();
std::cout << obj << std::endl;
assert(obj.as<my_class>() == my);
}

View File

@@ -102,9 +102,9 @@ int main() {
print(ss.str());
msgpack::unpacked unp;
msgpack::unpack(unp, ss.str().data(), ss.str().size());
msgpack::object obj = unp.get();
msgpack::object_handle oh =
msgpack::unpack(ss.str().data(), ss.str().size());
msgpack::object obj = oh.get();
std::cout << obj << std::endl;
assert(obj.as<my_class>() == my);
}

View File

@@ -40,9 +40,9 @@ int main(void)
std::stringstream sbuf;
msgpack::pack(sbuf, oc);
msgpack::unpacked result;
msgpack::unpack(result, sbuf.str().data(), sbuf.str().size());
msgpack::object obj = result.get();
msgpack::object_handle oh =
msgpack::unpack(sbuf.str().data(), sbuf.str().size());
msgpack::object obj = oh.get();
obj.convert(nc);
@@ -56,9 +56,9 @@ int main(void)
std::stringstream sbuf;
msgpack::pack(sbuf, nc);
msgpack::unpacked result;
msgpack::unpack(result, sbuf.str().data(), sbuf.str().size());
msgpack::object obj = result.get();
msgpack::object_handle oh =
msgpack::unpack(sbuf.str().data(), sbuf.str().size());
msgpack::object obj = oh.get();
obj.convert(oc);

View File

@@ -30,20 +30,20 @@ int main(void)
my_enum e3 = elem3;
msgpack::pack(sbuf, e3);
msgpack::unpacked result;
msgpack::object_handle oh;
std::size_t off = 0;
msgpack::unpack(result, sbuf.str().data(), sbuf.str().size(), off);
std::cout << result.get().as<my_enum>() << std::endl;
assert(result.get().as<my_enum>() == elem1);
msgpack::unpack(oh, sbuf.str().data(), sbuf.str().size(), off);
std::cout << oh.get().as<my_enum>() << std::endl;
assert(oh.get().as<my_enum>() == elem1);
msgpack::unpack(result, sbuf.str().data(), sbuf.str().size(), off);
std::cout << result.get().as<my_enum>() << std::endl;
assert(result.get().as<my_enum>() == elem2);
msgpack::unpack(oh, sbuf.str().data(), sbuf.str().size(), off);
std::cout << oh.get().as<my_enum>() << std::endl;
assert(oh.get().as<my_enum>() == elem2);
msgpack::unpack(result, sbuf.str().data(), sbuf.str().size(), off);
std::cout << result.get().as<my_enum>() << std::endl;
assert(result.get().as<my_enum>() == elem3);
msgpack::unpack(oh, sbuf.str().data(), sbuf.str().size(), off);
std::cout << oh.get().as<my_enum>() << std::endl;
assert(oh.get().as<my_enum>() == elem3);
}
{ // create object without zone
msgpack::object obj(elem2);

View File

@@ -71,9 +71,9 @@ int main() {
print(ss.str());
msgpack::unpacked unp = msgpack::unpack(ss.str().data(), ss.str().size());
msgpack::object_handle oh = msgpack::unpack(ss.str().data(), ss.str().size());
msgpack::object obj = unp.get();
msgpack::object obj = oh.get();
std::cout << obj << std::endl;
v2 newv = obj.as<v2>();

View File

@@ -57,9 +57,9 @@ int main(void)
{
std::string buffer(stream.str());
msgpack::unpacked result;
msgpack::unpack(result, buffer.data(), buffer.size());
msgpack::object o = result.get();
msgpack::object_handle oh =
msgpack::unpack(buffer.data(), buffer.size());
msgpack::object o = oh.get();
myprotocol::Get req;
o.convert(req);
@@ -85,9 +85,9 @@ int main(void)
{
std::string buffer(stream.str());
msgpack::unpacked result;
msgpack::unpack(result, buffer.data(), buffer.size());
msgpack::object o = result.get();
msgpack::object_handle oh =
msgpack::unpack(buffer.data(), buffer.size());
msgpack::object o = oh.get();
myprotocol::MultiGet req;

View File

@@ -44,9 +44,9 @@ int main(void)
{
std::string buffer(stream.str());
msgpack::unpacked result;
msgpack::unpack(result, buffer.data(), buffer.size());
msgpack::object o = result.get();
msgpack::object_handle oh =
msgpack::unpack(buffer.data(), buffer.size());
msgpack::object o = oh.get();
myprotocol::Get req;
o.convert(req);
@@ -72,9 +72,9 @@ int main(void)
{
std::string buffer(stream.str());
msgpack::unpacked result;
msgpack::unpack(result, buffer.data(), buffer.size());
msgpack::object o = result.get();
msgpack::object_handle oh =
msgpack::unpack(buffer.data(), buffer.size());
msgpack::object o = oh.get();
myprotocol::MultiGet req;

View File

@@ -27,12 +27,10 @@ int main(void)
// deserialize the buffer into msgpack::object instance.
std::string str(buffer.str());
msgpack::unpacked result;
msgpack::object_handle oh = msgpack::unpack(str.data(), str.size());
msgpack::unpack(result, str.data(), str.size());
// deserialized object is valid during the msgpack::unpacked instance alive.
msgpack::object deserialized = result.get();
// deserialized object is valid during the msgpack::object_handle instance alive.
msgpack::object deserialized = oh.get();
// msgpack::object supports ostream.
std::cout << deserialized << std::endl;

View File

@@ -37,11 +37,11 @@ void test_map_pack_unpack() {
buffer.seekg(0);
std::string str(buffer.str());
msgpack::unpacked unpacked;
std::cout << "Start unpacking...by void unpack(unpacked& result, const char* data, size_t len)" << std::endl;
msgpack::object_handle oh;
std::cout << "Start unpacking...by void unpack(object_handle& oh, const char* data, size_t len)" << std::endl;
{
boost::timer::cpu_timer timer;
msgpack::unpack(unpacked, str.data(), str.size());
msgpack::unpack(oh, str.data(), str.size());
std::string result = timer.format();
std::cout << result << std::endl;
}
@@ -50,7 +50,7 @@ void test_map_pack_unpack() {
std::cout << "Start converting..." << std::endl;
{
boost::timer::cpu_timer timer;
unpacked.get().convert(m2);
oh.get().convert(m2);
std::string result = timer.format();
std::cout << result << std::endl;
}

View File

@@ -60,11 +60,11 @@ void test_array_of_array() {
buffer.seekg(0);
std::string str(buffer.str());
msgpack::unpacked unpacked;
std::cout << "Start unpacking...by void unpack(unpacked& result, const char* data, size_t len)" << std::endl;
msgpack::object_handle oh;
std::cout << "Start unpacking...by void unpack(object_handle& oh, const char* data, size_t len)" << std::endl;
{
boost::timer::cpu_timer timer;
msgpack::unpack(unpacked, str.data(), str.size());
msgpack::unpack(oh, str.data(), str.size());
std::string result = timer.format();
std::cout << result << std::endl;
}
@@ -73,7 +73,7 @@ void test_array_of_array() {
std::cout << "Start converting..." << std::endl;
{
boost::timer::cpu_timer timer;
unpacked.get().convert(v2);
oh.get().convert(v2);
std::string result = timer.format();
std::cout << result << std::endl;
}

View File

@@ -43,10 +43,10 @@ public:
m_pac.buffer_consumed(count);
msgpack::unpacked result;
while (m_pac.next(&result)) {
msgpack::object msg = result.get();
unique_zone& life = result.zone();
msgpack::object_handle oh;
while (m_pac.next(&oh)) {
msgpack::object msg = oh.get();
unique_zone& life = oh.zone();
process_message(msg, life);
}