Added msgpack::type::variant and msgpack::type::variant_ref that is based on boost::variant.

You can convert to those types from any msgpack objects.
This commit is contained in:
Takatoshi Kondo
2015-08-10 00:21:43 +09:00
parent 722143c0de
commit cd9d6c5940
12 changed files with 1397 additions and 0 deletions

View File

@@ -166,6 +166,7 @@ IF (MSGPACK_ENABLE_CXX)
include/msgpack/adaptor/adaptor_base.hpp include/msgpack/adaptor/adaptor_base.hpp
include/msgpack/adaptor/bool.hpp include/msgpack/adaptor/bool.hpp
include/msgpack/adaptor/boost/fusion.hpp include/msgpack/adaptor/boost/fusion.hpp
include/msgpack/adaptor/boost/msgpack_variant.hpp
include/msgpack/adaptor/boost/optional.hpp include/msgpack/adaptor/boost/optional.hpp
include/msgpack/adaptor/boost/string_ref.hpp include/msgpack/adaptor/boost/string_ref.hpp
include/msgpack/adaptor/char_ptr.hpp include/msgpack/adaptor/char_ptr.hpp

View File

@@ -1,3 +1,4 @@
ADD_SUBDIRECTORY (c) ADD_SUBDIRECTORY (c)
ADD_SUBDIRECTORY (cpp03) ADD_SUBDIRECTORY (cpp03)
ADD_SUBDIRECTORY (cpp11) ADD_SUBDIRECTORY (cpp11)
ADD_SUBDIRECTORY (boost)

View File

@@ -0,0 +1,24 @@
IF (MSGPACK_BOOST)
LIST (APPEND exec_PROGRAMS
msgpack_variant_capitalize.cpp
msgpack_variant_mapbased.cpp
)
ENDIF ()
FOREACH (source_file ${exec_PROGRAMS})
GET_FILENAME_COMPONENT (source_file_we ${source_file} NAME_WE)
ADD_EXECUTABLE (
${source_file_we}
${source_file}
)
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS "-Wall -Wextra -Werror -Wno-mismatched-tags -g -O3")
ENDIF ()
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
STRING(REGEX REPLACE "/W[0-4]" "/W3 /WX" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
ELSE ()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /WX")
ENDIF ()
ENDIF ()
ENDFOREACH ()

View File

@@ -0,0 +1,102 @@
// MessagePack for C++ example
//
// Copyright (C) 2015 KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include <string>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cctype>
#include <msgpack.hpp>
struct user {
std::string name;
int age;
std::string address;
MSGPACK_DEFINE(name, age, address);
};
struct proc:boost::static_visitor<void> {
void operator()(std::string& v) const {
std::cout << " match std::string& v" << std::endl;
std::cout << " v: " << v << std::endl;
std::cout << " capitalize" << std::endl;
for (std::string::iterator it = v.begin(), end = v.end();
it != end;
++it) {
*it = std::toupper(*it);
}
}
void operator()(std::vector<msgpack::type::variant>& v) const {
std::cout << "match vector (msgpack::type::ARRAY)" << std::endl;
std::vector<msgpack::type::variant>::iterator it = v.begin();
std::vector<msgpack::type::variant>::const_iterator end = v.end();
for (; it != end; ++it) {
boost::apply_visitor(*this, *it);
}
}
template <typename T>
void operator()(T const&) const {
std::cout << " match others" << std::endl;
}
};
void print(std::string const& buf) {
for (std::string::const_iterator it = buf.begin(), end = buf.end();
it != end;
++it) {
std::cout
<< std::setw(2)
<< std::hex
<< std::setfill('0')
<< (static_cast<int>(*it) & 0xff)
<< ' ';
}
std::cout << std::dec << std::endl;
}
int main() {
std::stringstream ss1;
user u;
u.name = "Takatoshi Kondo";
u.age = 42;
u.address = "Tokyo, JAPAN";
std::cout << "Packing object." << std::endl;
msgpack::pack(ss1, u);
print(ss1.str());
msgpack::unpacked unp1 = msgpack::unpack(ss1.str().data(), ss1.str().size());
msgpack::object const& obj1 = unp1.get();
std::cout << "Unpacked msgpack object." << std::endl;
std::cout << obj1 << std::endl;
msgpack::type::variant v = obj1.as<msgpack::type::variant>();
std::cout << "Applying proc..." << std::endl;
boost::apply_visitor(proc(), v);
std::stringstream ss2;
std::cout << "Packing modified object." << std::endl;
msgpack::pack(ss2, v);
print(ss2.str());
msgpack::unpacked unp2 = msgpack::unpack(ss2.str().data(), ss2.str().size());
msgpack::object const& obj2 = unp2.get();
std::cout << "Modified msgpack object." << std::endl;
std::cout << obj2 << std::endl;
}

View File

@@ -0,0 +1,95 @@
// MessagePack for C++ example
//
// Copyright (C) 2015 KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include <string>
#include <sstream>
#include <iostream>
#include <msgpack.hpp>
struct user {
std::string name;
int age;
std::string address;
MSGPACK_DEFINE_MAP(name, age, address);
};
struct proc:boost::static_visitor<void> {
// msgpack::type::MAP is converted to std::multimap, not std::map.
void operator()(std::multimap<msgpack::type::variant_ref, msgpack::type::variant_ref>& v) const {
std::cout << "match map" << std::endl;
std::multimap<msgpack::type::variant_ref, msgpack::type::variant_ref>::iterator it = v.begin();
std::multimap<msgpack::type::variant_ref, msgpack::type::variant_ref>::iterator end = v.end();
while(it != end) {
boost::string_ref const& key = boost::get<boost::string_ref>(it->first);
if (key == "name") {
boost::string_ref const& value = boost::get<boost::string_ref>(it->second);
if (value == "Takatoshi Kondo") {
// You can add values to msgpack::type::variant_ref.
v.insert(
std::multimap<msgpack::type::variant_ref, msgpack::type::variant_ref>::value_type(
std::string("role"),
std::string("msgpack-c committer")
)
);
}
++it;
}
else if (key == "age") {
// You can remove key-value pair from msgpack::type::variant_ref
#if defined(MSGPACK_USE_CPP03)
v.erase(it++);
#else
it = v.erase(it);
#endif
}
else if (key == "address") {
// When you want to append string
// "Tokyo" -> "Tokyo, JAPAN"
// Use msgpack::type::variant instead of msgpack::type::varinat_ref
// or do as follows:
boost::string_ref const& value = boost::get<boost::string_ref>(it->second);
it->second = std::string(&value.front(), value.size()) + ", JAPAN";
++it;
}
}
}
template <typename T>
void operator()(T const&) const {
std::cout << " match others" << std::endl;
}
};
int main() {
std::stringstream ss;
user u;
u.name = "Takatoshi Kondo";
u.age = 42;
u.address = "Tokyo";
msgpack::pack(ss, u);
msgpack::unpacked unp = msgpack::unpack(ss.str().data(), ss.str().size());
msgpack::object const& obj = unp.get();
std::cout << "Unpacked msgpack object." << std::endl;
std::cout << obj << std::endl;
msgpack::type::variant_ref v = obj.as<msgpack::type::variant_ref>();
std::cout << "Applying proc..." << std::endl;
boost::apply_visitor(proc(), v);
msgpack::zone z;
std::cout << "Applied msgpack object." << std::endl;
std::cout << msgpack::object(v, z) << std::endl;
}

View File

@@ -0,0 +1,391 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2015 KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_BOOST_MSGPACK_VARIANT_HPP
#define MSGPACK_TYPE_BOOST_MSGPACK_VARIANT_HPP
#if defined(MSGPACK_USE_BOOST)
#include "msgpack/versioning.hpp"
#include "msgpack/adaptor/adaptor_base.hpp"
#include "msgpack/adaptor/check_container_size.hpp"
#include "msgpack/adaptor/boost/string_ref.hpp"
#include "msgpack/adaptor/nil.hpp"
#include "msgpack/adaptor/bool.hpp"
#include "msgpack/adaptor/int.hpp"
#include "msgpack/adaptor/float.hpp"
#include "msgpack/adaptor/string.hpp"
#include "msgpack/adaptor/vector_char.hpp"
#include "msgpack/adaptor/raw.hpp"
#include "msgpack/adaptor/ext.hpp"
#include "msgpack/adaptor/vector.hpp"
#include "msgpack/adaptor/map.hpp"
#include <boost/variant.hpp>
namespace msgpack {
/// @cond
MSGPACK_API_VERSION_NAMESPACE(v1) {
/// @endcond
namespace type {
typedef boost::make_recursive_variant<
nil, // NIL
bool, // BOOL
int64_t, // NEGATIVE_INTEGER
uint64_t, // POSITIVE_INTEGER
double, // FLOAT
std::string, // STR
#if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
boost::string_ref, // STR
#endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
std::vector<char>, // BIN
msgpack::type::raw_ref, // BIN
ext, // EXT
ext_ref, // EXT
std::vector<boost::recursive_variant_>, // ARRAY
std::map<boost::recursive_variant_, boost::recursive_variant_>, // MAP
std::multimap<boost::recursive_variant_, boost::recursive_variant_> // MAP
>::type variant;
namespace detail {
struct ref_tag {
#if defined(MSGPACK_USE_CPP03)
private:
ref_tag();
#else // defined(MSGPACK_USE_CPP03)
ref_tag() = delete;
#endif // defined(MSGPACK_USE_CPP03)
public:
MSGPACK_DEFINE();
};
inline bool operator<(ref_tag const& lhs, ref_tag const& rhs) {
return &lhs < &rhs;
}
inline bool operator==(ref_tag const& lhs, ref_tag const& rhs) {
return &lhs == &rhs;
}
} // namespace detail
typedef boost::make_recursive_variant<
nil, // NIL
bool, // BOOL
int64_t, // NEGATIVE_INTEGER
uint64_t, // POSITIVE_INTEGER
double, // FLOAT
std::string, // STR
#if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
boost::string_ref, // STR
#endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
std::vector<char>, // BIN
msgpack::type::raw_ref, // BIN
ext, // EXT
ext_ref, // EXT
std::vector<boost::recursive_variant_>, // ARRAY
std::map<boost::recursive_variant_, boost::recursive_variant_>, // MAP
std::multimap<boost::recursive_variant_, boost::recursive_variant_>, // MAP
detail::ref_tag
>::type variant_ref;
} // namespace type
namespace adaptor {
#if !defined (MSGPACK_USE_CPP03)
template <>
struct as<msgpack::type::variant> {
msgpack::type::variant operator()(msgpack::object const& o) const {
switch(o.type) {
case type::NIL:
return o.as<msgpack::type::nil>();
case type::BOOLEAN:
return o.as<bool>();
case type::POSITIVE_INTEGER:
return o.as<uint64_t>();
case type::NEGATIVE_INTEGER:
return o.as<int64_t>();
case type::FLOAT:
return o.as<double>();
case type::STR:
return o.as<std::string>();
case type::BIN:
return o.as<std::vector<char> >();
case type::EXT:
return o.as<msgpack::type::ext>();
case type::ARRAY:
return o.as<std::vector<msgpack::type::variant> >();
case type::MAP:
return o.as<std::multimap<msgpack::type::variant, msgpack::type::variant> >();
default:
break;
}
return msgpack::type::variant();
}
};
#endif // !defined (MSGPACK_USE_CPP03)
template <>
struct convert<msgpack::type::variant> {
msgpack::object const& operator()(
msgpack::object const& o,
msgpack::type::variant& v) const {
switch(o.type) {
case type::NIL:
v = o.as<msgpack::type::nil>();
break;
case type::BOOLEAN:
v = o.as<bool>();
break;
case type::POSITIVE_INTEGER:
v = o.as<uint64_t>();
break;
case type::NEGATIVE_INTEGER:
v = o.as<int64_t>();
break;
case type::FLOAT:
v = o.as<double>();
break;
case type::STR:
v = o.as<std::string>();
break;
case type::BIN:
v = o.as<std::vector<char> >();
break;
case type::EXT:
v = o.as<msgpack::type::ext>();
break;
case type::ARRAY:
v = o.as<std::vector<msgpack::type::variant> >();
break;
case type::MAP:
v = o.as<std::multimap<msgpack::type::variant, msgpack::type::variant> >();
break;
default:
break;
}
return o;
}
};
namespace detail {
template <typename Stream>
struct pack_imp:boost::static_visitor<void> {
template <typename T>
void operator()(T const& value) const {
pack<T>()(o_, value);
}
pack_imp(packer<Stream>& o):o_(o) {}
packer<Stream>& o_;
};
} // namespace detail
template <>
struct pack<msgpack::type::variant> {
template <typename Stream>
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const msgpack::type::variant& v) const {
boost::apply_visitor(detail::pack_imp<Stream>(o), v);
return o;
}
};
namespace detail {
struct object_imp:boost::static_visitor<void> {
void operator()(msgpack::type::nil const& v) const {
object<msgpack::type::nil>()(o_, v);
}
void operator()(bool const& v) const {
object<bool>()(o_, v);
}
void operator()(uint64_t const& v) const {
object<uint64_t>()(o_, v);
}
void operator()(int64_t const& v) const {
object<int64_t>()(o_, v);
}
void operator()(double const& v) const {
object<double>()(o_, v);
}
template <typename T>
void operator()(T const&) const {
throw msgpack::type_error();
}
object_imp(msgpack::object& o):o_(o) {}
msgpack::object& o_;
};
} // namespace detail
template <>
struct object<msgpack::type::variant> {
void operator()(msgpack::object& o, const msgpack::type::variant& v) const {
boost::apply_visitor(detail::object_imp(o), v);
}
};
namespace detail {
struct object_with_zone_imp:boost::static_visitor<void> {
template <typename T>
void operator()(T const& v) const {
object_with_zone<T>()(o_, v);
}
object_with_zone_imp(msgpack::object::with_zone& o):o_(o) {}
msgpack::object::with_zone& o_;
};
} // namespace detail
template <>
struct object_with_zone<msgpack::type::variant> {
void operator()(msgpack::object::with_zone& o, const msgpack::type::variant& v) const {
boost::apply_visitor(detail::object_with_zone_imp(o), v);
}
};
#if !defined (MSGPACK_USE_CPP03)
template <>
struct as<msgpack::type::variant_ref> {
msgpack::type::variant_ref operator()(msgpack::object const& o) const {
switch(o.type) {
case type::NIL:
return o.as<msgpack::type::nil>();
case type::BOOLEAN:
return o.as<bool>();
case type::POSITIVE_INTEGER:
return o.as<uint64_t>();
case type::NEGATIVE_INTEGER:
return o.as<int64_t>();
case type::FLOAT:
return o.as<double>();
case type::STR:
#if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
return o.as<boost::string_ref>();
#else // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
return o.as<std::string>();
#endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
case type::BIN:
return o.as<msgpack::type::raw_ref>();
case type::EXT:
return o.as<msgpack::type::ext_ref>();
case type::ARRAY:
return o.as<std::vector<msgpack::type::variant_ref> >();
case type::MAP:
return o.as<std::multimap<msgpack::type::variant_ref, msgpack::type::variant_ref> >();
default:
break;
}
return msgpack::type::variant_ref();
}
};
#endif // !defined (MSGPACK_USE_CPP03)
template <>
struct convert<msgpack::type::variant_ref> {
msgpack::object const& operator()(
msgpack::object const& o,
msgpack::type::variant_ref& v) const {
switch(o.type) {
case type::NIL:
v = o.as<msgpack::type::nil>();
break;
case type::BOOLEAN:
v = o.as<bool>();
break;
case type::POSITIVE_INTEGER:
v = o.as<uint64_t>();
break;
case type::NEGATIVE_INTEGER:
v = o.as<int64_t>();
break;
case type::FLOAT:
v = o.as<double>();
break;
case type::STR:
#if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
v = o.as<boost::string_ref>();
#else // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
v = o.as<std::string>();
#endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
break;
case type::BIN:
v = o.as<msgpack::type::raw_ref>();
break;
case type::EXT:
v = o.as<msgpack::type::ext_ref>();
break;
case type::ARRAY:
v = o.as<std::vector<msgpack::type::variant_ref> >();
break;
case type::MAP:
v = o.as<std::multimap<msgpack::type::variant_ref, msgpack::type::variant_ref> >();
break;
default:
break;
}
return o;
}
};
template <>
struct pack<msgpack::type::variant_ref> {
template <typename Stream>
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const msgpack::type::variant_ref& v) const {
boost::apply_visitor(detail::pack_imp<Stream>(o), v);
return o;
}
};
template <>
struct object<msgpack::type::variant_ref> {
void operator()(msgpack::object& o, const msgpack::type::variant_ref& v) const {
boost::apply_visitor(detail::object_imp(o), v);
}
};
template <>
struct object_with_zone<msgpack::type::variant_ref> {
void operator()(msgpack::object::with_zone& o, const msgpack::type::variant_ref& v) const {
boost::apply_visitor(detail::object_with_zone_imp(o), v);
}
};
} // namespace adaptor
/// @cond
} // MSGPACK_API_VERSION_NAMESPACE(v1)
/// @endcond
} // namespace msgpack
#endif // MSGPACK_USE_BOOST
#endif // MSGPACK_TYPE_BOOST_MSGPACK_VARIANT_HPP

View File

@@ -31,6 +31,14 @@ namespace type {
struct nil { }; struct nil { };
inline bool operator<(nil const& lhs, nil const& rhs) {
return &lhs < &rhs;
}
inline bool operator==(nil const& lhs, nil const& rhs) {
return &lhs == &rhs;
}
} // namespace type } // namespace type
namespace adaptor { namespace adaptor {

View File

@@ -41,6 +41,7 @@
#if defined(MSGPACK_USE_BOOST) #if defined(MSGPACK_USE_BOOST)
#include "adaptor/boost/fusion.hpp" #include "adaptor/boost/fusion.hpp"
#include "adaptor/boost/msgpack_variant.hpp"
#include "adaptor/boost/optional.hpp" #include "adaptor/boost/optional.hpp"
#include "adaptor/boost/string_ref.hpp" #include "adaptor/boost/string_ref.hpp"

View File

@@ -175,6 +175,7 @@ nobase_include_HEADERS += \
../include/msgpack/adaptor/adaptor_base.hpp \ ../include/msgpack/adaptor/adaptor_base.hpp \
../include/msgpack/adaptor/bool.hpp \ ../include/msgpack/adaptor/bool.hpp \
../include/msgpack/adaptor/boost/fusion.hpp \ ../include/msgpack/adaptor/boost/fusion.hpp \
../include/msgpack/adaptor/boost/msgpack_variant.hpp \
../include/msgpack/adaptor/boost/optional.hpp \ ../include/msgpack/adaptor/boost/optional.hpp \
../include/msgpack/adaptor/boost/string_ref.hpp \ ../include/msgpack/adaptor/boost/string_ref.hpp \
../include/msgpack/adaptor/char_ptr.hpp \ ../include/msgpack/adaptor/char_ptr.hpp \

View File

@@ -37,6 +37,7 @@ LIST (APPEND check_PROGRAMS
IF (MSGPACK_BOOST) IF (MSGPACK_BOOST)
LIST (APPEND check_PROGRAMS LIST (APPEND check_PROGRAMS
boost_fusion.cpp boost_fusion.cpp
boost_variant.cpp
boost_optional.cpp boost_optional.cpp
boost_string_ref.cpp boost_string_ref.cpp
) )

View File

@@ -30,6 +30,7 @@ check_PROGRAMS = \
check_PROGRAMS += \ check_PROGRAMS += \
boost_fusion \ boost_fusion \
boost_variant \
boost_optional \ boost_optional \
boost_string_ref boost_string_ref
@@ -77,6 +78,7 @@ shared_ptr_cpp11_SOURCES = shared_ptr_cpp11.cpp
unique_ptr_cpp11_SOURCES = unique_ptr_cpp11.cpp unique_ptr_cpp11_SOURCES = unique_ptr_cpp11.cpp
boost_fusion_SOURCES = boost_fusion.cpp boost_fusion_SOURCES = boost_fusion.cpp
boost_variant_SOURCES = boost_variant.cpp
boost_optional_SOURCES = boost_optional.cpp boost_optional_SOURCES = boost_optional.cpp
boost_string_ref_SOURCES = boost_string_ref.cpp boost_string_ref_SOURCES = boost_string_ref.cpp

770
test/boost_variant.cpp Normal file
View File

@@ -0,0 +1,770 @@
#include <msgpack.hpp>
#include <sstream>
#include <iterator>
#include <gtest/gtest.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#if defined(MSGPACK_USE_BOOST)
// nil
TEST(MSGPACK_BOOST, pack_convert_variant_nil)
{
std::stringstream ss;
msgpack::type::variant val1 = msgpack::type::nil();
msgpack::pack(ss, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, ss.str().data(), ss.str().size());
msgpack::type::variant val2 = ret.get().as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<msgpack::type::nil>(val2));
}
TEST(MSGPACK_BOOST, object_variant_nil)
{
msgpack::type::variant val1 = msgpack::type::nil();
msgpack::object obj(val1);
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<msgpack::type::nil>(val2));
}
TEST(MSGPACK_BOOST, object_with_zone_variant_nil)
{
msgpack::zone z;
msgpack::type::variant val1 = msgpack::type::nil();
msgpack::object obj(val1, z);
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<msgpack::type::nil>(val2));
}
// nil (default constructor)
TEST(MSGPACK_BOOST, pack_convert_variant_nil_default)
{
std::stringstream ss;
msgpack::type::variant val1;
msgpack::pack(ss, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, ss.str().data(), ss.str().size());
msgpack::type::variant val2 = ret.get().as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<msgpack::type::nil>(val2));
}
TEST(MSGPACK_BOOST, object_variant_nil_default)
{
msgpack::type::variant val1;
msgpack::object obj(val1);
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<msgpack::type::nil>(val2));
}
TEST(MSGPACK_BOOST, object_with_zone_variant_nil_default)
{
msgpack::zone z;
msgpack::type::variant val1;
msgpack::object obj(val1, z);
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<msgpack::type::nil>(val2));
}
// bool
TEST(MSGPACK_BOOST, pack_convert_variant_bool)
{
std::stringstream ss;
msgpack::type::variant val1 = true;
msgpack::pack(ss, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, ss.str().data(), ss.str().size());
msgpack::type::variant val2 = ret.get().as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<bool>(val2));
EXPECT_TRUE(val1 == val2);
}
TEST(MSGPACK_BOOST, object_variant_bool)
{
msgpack::type::variant val1 = true;
msgpack::object obj(val1);
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<bool>(val2));
EXPECT_TRUE(val1 == val2);
}
TEST(MSGPACK_BOOST, object_with_zone_variant_bool)
{
msgpack::zone z;
msgpack::type::variant val1 = true;
msgpack::object obj(val1, z);
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<bool>(val2));
EXPECT_TRUE(val1 == val2);
}
// positive integer
TEST(MSGPACK_BOOST, pack_convert_variant_positive_integer)
{
std::stringstream ss;
msgpack::type::variant val1 = uint64_t(123);
msgpack::pack(ss, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, ss.str().data(), ss.str().size());
msgpack::type::variant val2 = ret.get().as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<uint64_t>(val2));
EXPECT_TRUE(val1 == val2);
}
TEST(MSGPACK_BOOST, object_variant_positive_integer)
{
msgpack::type::variant val1 = uint64_t(123);
msgpack::object obj(val1);
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<uint64_t>(val2));
EXPECT_TRUE(val1 == val2);
}
TEST(MSGPACK_BOOST, object_with_zone_variant_positive_integer)
{
msgpack::zone z;
msgpack::type::variant val1 = uint64_t(123);
msgpack::object obj(val1, z);
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<uint64_t>(val2));
EXPECT_TRUE(val1 == val2);
}
// negative integer
TEST(MSGPACK_BOOST, pack_convert_variant_negative_integer)
{
std::stringstream ss;
msgpack::type::variant val1 = int64_t(-123);
msgpack::pack(ss, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, ss.str().data(), ss.str().size());
msgpack::type::variant val2 = ret.get().as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<int64_t>(val2));
EXPECT_TRUE(val1 == val2);
}
TEST(MSGPACK_BOOST, object_variant_negative_integer)
{
msgpack::type::variant val1 = int64_t(-123);
msgpack::object obj(val1);
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<int64_t>(val2));
EXPECT_TRUE(val1 == val2);
}
TEST(MSGPACK_BOOST, object_with_zone_variant_negative_integer)
{
msgpack::zone z;
msgpack::type::variant val1 = int64_t(-123);
msgpack::object obj(val1, z);
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<int64_t>(val2));
EXPECT_TRUE(val1 == val2);
}
// float
TEST(MSGPACK_BOOST, pack_convert_variant_float)
{
std::stringstream ss;
msgpack::type::variant val1 = 12.34;
msgpack::pack(ss, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, ss.str().data(), ss.str().size());
msgpack::type::variant val2 = ret.get().as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<double>(val2));
EXPECT_TRUE(val1 == val2);
}
TEST(MSGPACK_BOOST, object_variant_float)
{
msgpack::type::variant val1 = 12.34;
msgpack::object obj(val1);
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<double>(val2));
EXPECT_TRUE(val1 == val2);
}
TEST(MSGPACK_BOOST, object_with_zone_variant_float)
{
msgpack::zone z;
msgpack::type::variant val1 = 12.34;
msgpack::object obj(val1, z);
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<double>(val2));
EXPECT_TRUE(val1 == val2);
}
// str
TEST(MSGPACK_BOOST, pack_convert_variant_str)
{
std::stringstream ss;
msgpack::type::variant val1 = std::string("ABC");
msgpack::pack(ss, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, ss.str().data(), ss.str().size());
msgpack::type::variant val2 = ret.get().as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<std::string>(val2));
EXPECT_TRUE(val1 == val2);
}
TEST(MSGPACK_BOOST, object_with_zone_variant_str)
{
msgpack::zone z;
msgpack::type::variant val1 = std::string("ABC");
msgpack::object obj(val1, z);
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<std::string>(val2));
EXPECT_TRUE(val1 == val2);
}
// bin
TEST(MSGPACK_BOOST, pack_convert_variant_bin)
{
std::stringstream ss;
std::vector<char> v;
v.push_back('a');
v.push_back('b');
v.push_back('c');
msgpack::type::variant val1 = v;
msgpack::pack(ss, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, ss.str().data(), ss.str().size());
msgpack::type::variant val2 = ret.get().as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<std::vector<char> >(val2));
EXPECT_TRUE(val1 == val2);
}
TEST(MSGPACK_BOOST, object_with_zone_variant_bin)
{
msgpack::zone z;
std::vector<char> v;
v.push_back('a');
v.push_back('b');
v.push_back('c');
msgpack::type::variant val1 = v;
msgpack::object obj(val1, z);
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<std::vector<char> >(val2));
EXPECT_TRUE(val1 == val2);
}
// ext
TEST(MSGPACK_BOOST, pack_convert_variant_ext)
{
std::stringstream ss;
std::vector<char> v;
v.push_back('a');
v.push_back('b');
v.push_back('c');
msgpack::type::variant val1(msgpack::type::ext(42, v.data(), v.size()));
msgpack::pack(ss, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, ss.str().data(), ss.str().size());
msgpack::type::variant val2 = ret.get().as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<msgpack::type::ext>(val2));
EXPECT_TRUE(val1 == val2);
}
TEST(MSGPACK_BOOST, object_with_zone_variant_ext)
{
msgpack::zone z;
std::vector<char> v;
v.push_back('a');
v.push_back('b');
v.push_back('c');
msgpack::type::variant val1(msgpack::type::ext(42, v.data(), v.size()));
msgpack::object obj(val1, z);
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<msgpack::type::ext>(val2));
EXPECT_TRUE(val1 == val2);
}
// array
TEST(MSGPACK_BOOST, pack_convert_variant_array)
{
std::stringstream ss;
std::vector<msgpack::type::variant> v;
v.push_back(msgpack::type::variant(uint64_t(1)));
v.push_back(msgpack::type::variant(int64_t(-1)));
v.push_back(msgpack::type::variant(23.4));
v.push_back(msgpack::type::variant(std::string("ABC")));
msgpack::type::variant val1 = v;
msgpack::pack(ss, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, ss.str().data(), ss.str().size());
msgpack::type::variant val2 = ret.get().as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<std::vector<msgpack::type::variant> >(val2));
EXPECT_TRUE(val1 == val2);
}
TEST(MSGPACK_BOOST, object_with_zone_variant_array)
{
msgpack::zone z;
std::vector<msgpack::type::variant> v;
v.push_back(msgpack::type::variant(uint64_t(1)));
v.push_back(msgpack::type::variant(int64_t(-1)));
v.push_back(msgpack::type::variant(23.4));
v.push_back(msgpack::type::variant(std::string("ABC")));
msgpack::type::variant val1 = v;
msgpack::object obj(val1, z);
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<std::vector<msgpack::type::variant> >(val2));
EXPECT_TRUE(val1 == val2);
}
// multimap
TEST(MSGPACK_BOOST, pack_convert_variant_map)
{
std::stringstream ss;
typedef std::multimap<msgpack::type::variant, msgpack::type::variant> multimap_t;
multimap_t v;
v.insert(multimap_t::value_type(msgpack::type::variant(uint64_t(1)), msgpack::type::variant(int64_t(-1))));
v.insert(multimap_t::value_type(msgpack::type::variant(23.4), msgpack::type::variant(std::string("ABC"))));
msgpack::type::variant val1 = v;
msgpack::pack(ss, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, ss.str().data(), ss.str().size());
msgpack::type::variant val2 = ret.get().as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<multimap_t>(val2));
EXPECT_TRUE(val1 == val2);
}
TEST(MSGPACK_BOOST, object_with_zone_variant_map)
{
msgpack::zone z;
typedef std::multimap<msgpack::type::variant, msgpack::type::variant> multimap_t;
multimap_t v;
v.insert(multimap_t::value_type(msgpack::type::variant(uint64_t(1)), msgpack::type::variant(int64_t(-1))));
v.insert(multimap_t::value_type(msgpack::type::variant(23.4), msgpack::type::variant(std::string("ABC"))));
msgpack::type::variant val1 = v;
msgpack::object obj(val1, z);
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
EXPECT_NO_THROW(boost::get<multimap_t>(val2));
EXPECT_TRUE(val1 == val2);
}
// variant_ref
// nil
TEST(MSGPACK_BOOST, pack_convert_variant_ref_nil)
{
std::stringstream ss;
msgpack::type::variant_ref val1 = msgpack::type::nil();
msgpack::pack(ss, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, ss.str().data(), ss.str().size());
msgpack::type::variant_ref val2 = ret.get().as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<msgpack::type::nil>(val2));
}
TEST(MSGPACK_BOOST, object_variant_ref_nil)
{
msgpack::type::variant_ref val1 = msgpack::type::nil();
msgpack::object obj(val1);
msgpack::type::variant_ref val2 = obj.as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<msgpack::type::nil>(val2));
}
TEST(MSGPACK_BOOST, object_with_zone_variant_ref_nil)
{
msgpack::zone z;
msgpack::type::variant_ref val1 = msgpack::type::nil();
msgpack::object obj(val1, z);
msgpack::type::variant_ref val2 = obj.as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<msgpack::type::nil>(val2));
}
// nil (default constructor)
TEST(MSGPACK_BOOST, pack_convert_variant_ref_nil_default)
{
std::stringstream ss;
msgpack::type::variant_ref val1;
msgpack::pack(ss, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, ss.str().data(), ss.str().size());
msgpack::type::variant_ref val2 = ret.get().as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<msgpack::type::nil>(val2));
}
TEST(MSGPACK_BOOST, object_variant_ref_nil_default)
{
msgpack::type::variant_ref val1;
msgpack::object obj(val1);
msgpack::type::variant_ref val2 = obj.as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<msgpack::type::nil>(val2));
}
TEST(MSGPACK_BOOST, object_with_zone_variant_ref_nil_default)
{
msgpack::zone z;
msgpack::type::variant_ref val1;
msgpack::object obj(val1, z);
msgpack::type::variant_ref val2 = obj.as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<msgpack::type::nil>(val2));
}
// bool
TEST(MSGPACK_BOOST, pack_convert_variant_ref_bool)
{
std::stringstream ss;
msgpack::type::variant_ref val1 = true;
msgpack::pack(ss, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, ss.str().data(), ss.str().size());
msgpack::type::variant_ref val2 = ret.get().as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<bool>(val2));
EXPECT_TRUE(val1 == val2);
}
TEST(MSGPACK_BOOST, object_variant_ref_bool)
{
msgpack::type::variant_ref val1 = true;
msgpack::object obj(val1);
msgpack::type::variant_ref val2 = obj.as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<bool>(val2));
EXPECT_TRUE(val1 == val2);
}
TEST(MSGPACK_BOOST, object_with_zone_variant_ref_bool)
{
msgpack::zone z;
msgpack::type::variant_ref val1 = true;
msgpack::object obj(val1, z);
msgpack::type::variant_ref val2 = obj.as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<bool>(val2));
EXPECT_TRUE(val1 == val2);
}
// positive integer
TEST(MSGPACK_BOOST, pack_convert_variant_ref_positive_integer)
{
std::stringstream ss;
msgpack::type::variant_ref val1 = uint64_t(123);
msgpack::pack(ss, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, ss.str().data(), ss.str().size());
msgpack::type::variant_ref val2 = ret.get().as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<uint64_t>(val2));
EXPECT_TRUE(val1 == val2);
}
TEST(MSGPACK_BOOST, object_variant_ref_positive_integer)
{
msgpack::type::variant_ref val1 = uint64_t(123);
msgpack::object obj(val1);
msgpack::type::variant_ref val2 = obj.as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<uint64_t>(val2));
EXPECT_TRUE(val1 == val2);
}
TEST(MSGPACK_BOOST, object_with_zone_variant_ref_positive_integer)
{
msgpack::zone z;
msgpack::type::variant_ref val1 = uint64_t(123);
msgpack::object obj(val1, z);
msgpack::type::variant_ref val2 = obj.as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<uint64_t>(val2));
EXPECT_TRUE(val1 == val2);
}
// negative integer
TEST(MSGPACK_BOOST, pack_convert_variant_ref_negative_integer)
{
std::stringstream ss;
msgpack::type::variant_ref val1 = int64_t(-123);
msgpack::pack(ss, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, ss.str().data(), ss.str().size());
msgpack::type::variant_ref val2 = ret.get().as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<int64_t>(val2));
EXPECT_TRUE(val1 == val2);
}
TEST(MSGPACK_BOOST, object_variant_ref_negative_integer)
{
msgpack::type::variant_ref val1 = int64_t(-123);
msgpack::object obj(val1);
msgpack::type::variant_ref val2 = obj.as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<int64_t>(val2));
EXPECT_TRUE(val1 == val2);
}
TEST(MSGPACK_BOOST, object_with_zone_variant_ref_negative_integer)
{
msgpack::zone z;
msgpack::type::variant_ref val1 = int64_t(-123);
msgpack::object obj(val1, z);
msgpack::type::variant_ref val2 = obj.as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<int64_t>(val2));
EXPECT_TRUE(val1 == val2);
}
// float
TEST(MSGPACK_BOOST, pack_convert_variant_ref_float)
{
std::stringstream ss;
msgpack::type::variant_ref val1 = 12.34;
msgpack::pack(ss, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, ss.str().data(), ss.str().size());
msgpack::type::variant_ref val2 = ret.get().as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<double>(val2));
EXPECT_TRUE(val1 == val2);
}
TEST(MSGPACK_BOOST, object_variant_ref_float)
{
msgpack::type::variant_ref val1 = 12.34;
msgpack::object obj(val1);
msgpack::type::variant_ref val2 = obj.as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<double>(val2));
EXPECT_TRUE(val1 == val2);
}
TEST(MSGPACK_BOOST, object_with_zone_variant_ref_float)
{
msgpack::zone z;
msgpack::type::variant_ref val1 = 12.34;
msgpack::object obj(val1, z);
msgpack::type::variant_ref val2 = obj.as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<double>(val2));
EXPECT_TRUE(val1 == val2);
}
// str
TEST(MSGPACK_BOOST, pack_convert_variant_ref_str)
{
std::stringstream ss;
std::string s("ABC");
msgpack::type::variant_ref val1 = boost::string_ref(s);
msgpack::pack(ss, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, ss.str().data(), ss.str().size());
msgpack::type::variant_ref val2 = ret.get().as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<boost::string_ref>(val2));
EXPECT_TRUE(val1 == val2);
}
TEST(MSGPACK_BOOST, object_with_zone_variant_ref_str)
{
msgpack::zone z;
std::string s("ABC");
msgpack::type::variant_ref val1 = boost::string_ref(s);
msgpack::object obj(val1, z);
msgpack::type::variant_ref val2 = obj.as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<boost::string_ref>(val2));
EXPECT_TRUE(val1 == val2);
}
// bin
TEST(MSGPACK_BOOST, pack_convert_variant_ref_bin)
{
std::stringstream ss;
std::vector<char> v;
v.push_back('a');
v.push_back('b');
v.push_back('c');
msgpack::type::variant_ref val1 = msgpack::type::raw_ref(v.data(), v.size());
msgpack::pack(ss, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, ss.str().data(), ss.str().size());
msgpack::type::variant_ref val2 = ret.get().as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<msgpack::type::raw_ref>(val2));
EXPECT_TRUE(val1 == val2);
}
TEST(MSGPACK_BOOST, object_with_zone_variant_ref_bin)
{
msgpack::zone z;
std::vector<char> v;
v.push_back('a');
v.push_back('b');
v.push_back('c');
msgpack::type::variant_ref val1 = msgpack::type::raw_ref(v.data(), v.size());
msgpack::object obj(val1, z);
msgpack::type::variant_ref val2 = obj.as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<msgpack::type::raw_ref>(val2));
EXPECT_TRUE(val1 == val2);
}
// ext
TEST(MSGPACK_BOOST, pack_convert_variant_ref_ext)
{
std::stringstream ss;
std::vector<char> v;
v.push_back(static_cast<char>(42));
v.push_back('a');
v.push_back('b');
v.push_back('c');
msgpack::type::variant_ref val1(msgpack::type::ext_ref(v.data(), v.size()));
msgpack::pack(ss, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, ss.str().data(), ss.str().size());
msgpack::type::variant_ref val2 = ret.get().as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<msgpack::type::ext_ref>(val2));
EXPECT_TRUE(val1 == val2);
}
TEST(MSGPACK_BOOST, object_with_zone_variant_ref_ext)
{
msgpack::zone z;
std::vector<char> v;
v.push_back(static_cast<char>(42));
v.push_back('a');
v.push_back('b');
v.push_back('c');
msgpack::type::variant_ref val1(msgpack::type::ext_ref(v.data(), v.size()));
msgpack::object obj(val1, z);
msgpack::type::variant_ref val2 = obj.as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<msgpack::type::ext_ref>(val2));
EXPECT_TRUE(val1 == val2);
}
// array
TEST(MSGPACK_BOOST, pack_convert_variant_ref_array)
{
std::stringstream ss;
std::vector<msgpack::type::variant_ref> v;
v.push_back(msgpack::type::variant_ref(uint64_t(1)));
v.push_back(msgpack::type::variant_ref(int64_t(-1)));
v.push_back(msgpack::type::variant_ref(23.4));
std::string s("ABC");
v.push_back(msgpack::type::variant_ref(boost::string_ref(s)));
msgpack::type::variant_ref val1 = v;
msgpack::pack(ss, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, ss.str().data(), ss.str().size());
msgpack::type::variant_ref val2 = ret.get().as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<std::vector<msgpack::type::variant_ref> >(val2));
EXPECT_TRUE(val1 == val2);
}
TEST(MSGPACK_BOOST, object_with_zone_variant_ref_array)
{
msgpack::zone z;
std::vector<msgpack::type::variant_ref> v;
v.push_back(msgpack::type::variant_ref(uint64_t(1)));
v.push_back(msgpack::type::variant_ref(int64_t(-1)));
v.push_back(msgpack::type::variant_ref(23.4));
std::string s("ABC");
v.push_back(msgpack::type::variant_ref(boost::string_ref(s)));
msgpack::type::variant_ref val1 = v;
msgpack::object obj(val1, z);
msgpack::type::variant_ref val2 = obj.as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<std::vector<msgpack::type::variant_ref> >(val2));
EXPECT_TRUE(val1 == val2);
}
// multimap
TEST(MSGPACK_BOOST, pack_convert_variant_ref_map)
{
std::stringstream ss;
typedef std::multimap<msgpack::type::variant_ref, msgpack::type::variant_ref> multimap_t;
multimap_t v;
v.insert(multimap_t::value_type(msgpack::type::variant_ref(uint64_t(1)), msgpack::type::variant_ref(int64_t(-1))));
std::string s("ABC");
v.insert(multimap_t::value_type(msgpack::type::variant_ref(23.4), msgpack::type::variant_ref(boost::string_ref(s))));
msgpack::type::variant_ref val1 = v;
msgpack::pack(ss, val1);
msgpack::unpacked ret;
msgpack::unpack(ret, ss.str().data(), ss.str().size());
msgpack::type::variant_ref val2 = ret.get().as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<multimap_t>(val2));
EXPECT_TRUE(val1 == val2);
}
TEST(MSGPACK_BOOST, object_with_zone_variant_ref_map)
{
msgpack::zone z;
typedef std::multimap<msgpack::type::variant_ref, msgpack::type::variant_ref> multimap_t;
multimap_t v;
v.insert(multimap_t::value_type(msgpack::type::variant_ref(uint64_t(1)), msgpack::type::variant_ref(int64_t(-1))));
std::string s("ABC");
v.insert(multimap_t::value_type(msgpack::type::variant_ref(23.4), msgpack::type::variant_ref(boost::string_ref(s))));
msgpack::type::variant_ref val1 = v;
msgpack::object obj(val1, z);
msgpack::type::variant_ref val2 = obj.as<msgpack::type::variant_ref>();
EXPECT_NO_THROW(boost::get<multimap_t>(val2));
EXPECT_TRUE(val1 == val2);
}
#endif // defined(MSGPACK_USE_BOOST)