Added EXT support.

Removed obsolete unpack functions.
Updated examples that no longer use obsolete functions.
Added reference checking function to unpacked. ( unpacked::referenced() )
Added std:: namespace.
Added reference or copy choice function and default behavior:
  When you use unpacker, default behavior is:
    STR, BIN, EXT types are always held by reference.
  When you don't use unpacker, default behavior is:
    STR, BIN, EXT types are always held by copy.
    The memory is allocated from zone.
  You can customize the behavior passing your custom judging function to unpack() or unpacker's constructor.
This commit is contained in:
Takatoshi Kondo
2014-08-06 16:18:37 +09:00
parent ce21ab0ebf
commit 1f5d6b9cac
12 changed files with 519 additions and 400 deletions

View File

@@ -30,9 +30,9 @@ int main(void)
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, oc);
msgpack::zone zone;
msgpack::object obj;
msgpack::unpack(sbuf.data(), sbuf.size(), NULL, &zone, &obj);
msgpack::unpacked result;
msgpack::unpack(result, sbuf.data(), sbuf.size());
msgpack::object obj = result.get();
obj.convert(&nc);
@@ -46,9 +46,9 @@ int main(void)
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, nc);
msgpack::zone zone;
msgpack::object obj;
msgpack::unpack(sbuf.data(), sbuf.size(), NULL, &zone, &obj);
msgpack::unpacked result;
msgpack::unpack(result, sbuf.data(), sbuf.size());
msgpack::object obj = result.get();
obj.convert(&oc);

View File

@@ -46,12 +46,12 @@ int main(void)
{
std::string buffer(stream.str());
msgpack::zone mempool;
msgpack::object o =
msgpack::unpack(buffer.data(), buffer.size(), mempool);
msgpack::unpacked result;
msgpack::unpack(result, buffer.data(), buffer.size());
msgpack::object o = result.get();
myprotocol::Get req;
msgpack::convert(req, o);
o.convert(req);
std::cout << "received: " << o << std::endl;
}
@@ -74,12 +74,13 @@ int main(void)
{
std::string buffer(stream.str());
msgpack::zone mempool;
msgpack::object o =
msgpack::unpack(buffer.data(), buffer.size(), mempool);
msgpack::unpacked result;
msgpack::unpack(result, buffer.data(), buffer.size());
msgpack::object o = result.get();
myprotocol::MultiGet req;
msgpack::convert(req, o);
o.convert(req);
std::cout << "received: " << o << std::endl;
}
}

View File

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

View File

@@ -28,23 +28,11 @@ void test_map_pack_unpack() {
buffer.seekg(0);
std::string str(buffer.str());
// deserialized object is valid during the msgpack::zone instance alive.
msgpack::zone mempool;
msgpack::object deserialized;
std::cout << "Start unpacking..." << std::endl;
{
boost::timer::cpu_timer timer;
msgpack::unpack(str.data(), str.size(), NULL, &mempool, &deserialized);
std::string result = timer.format();
std::cout << result << std::endl;
}
std::cout << "Unpack finished..." << std::endl;
msgpack::unpacked unpacked;
std::cout << "Start unpacking...by void unpack(unpacked* result, const char* data, size_t len, size_t* offset = NULL)" << std::endl;
std::cout << "Start unpacking...by void unpack(unpacked& result, const char* data, size_t len)" << std::endl;
{
boost::timer::cpu_timer timer;
msgpack::unpack(&unpacked, str.data(), str.size());
msgpack::unpack(unpacked, str.data(), str.size());
std::string result = timer.format();
std::cout << result << std::endl;
}
@@ -53,7 +41,7 @@ void test_map_pack_unpack() {
std::cout << "Start converting..." << std::endl;
{
boost::timer::cpu_timer timer;
deserialized.convert(&m2);
unpacked.get().convert(&m2);
std::string result = timer.format();
std::cout << result << std::endl;
}

View File

@@ -51,23 +51,11 @@ void test_array_of_array() {
buffer.seekg(0);
std::string str(buffer.str());
// deserialized object is valid during the msgpack::zone instance alive.
msgpack::zone mempool;
msgpack::object deserialized;
std::cout << "Start unpacking..." << std::endl;
{
boost::timer::cpu_timer timer;
msgpack::unpack(str.data(), str.size(), NULL, &mempool, &deserialized);
std::string result = timer.format();
std::cout << result << std::endl;
}
std::cout << "Unpack finished..." << std::endl;
msgpack::unpacked unpacked;
std::cout << "Start unpacking...by void unpack(unpacked* result, const char* data, size_t len, size_t* offset = NULL)" << std::endl;
std::cout << "Start unpacking...by void unpack(unpacked& result, const char* data, size_t len)" << std::endl;
{
boost::timer::cpu_timer timer;
msgpack::unpack(&unpacked, str.data(), str.size());
msgpack::unpack(unpacked, str.data(), str.size());
std::string result = timer.format();
std::cout << result << std::endl;
}
@@ -76,7 +64,7 @@ void test_array_of_array() {
std::cout << "Start converting..." << std::endl;
{
boost::timer::cpu_timer timer;
deserialized.convert(&v2);
unpacked.get().convert(&v2);
std::string result = timer.format();
std::cout << result << std::endl;
}