I am using boost recursive variant to store the variant data which I want to encode using msgpack for which I need to get the raw data to pass into encode() function (see below).
I tried three different options in encode() function below but doesn't work. What are the alternates?
typedef std::vector<boost::recursive_variant_> vector_rvariant_t;
typedef std::map<std::string, boost::recursive_variant_> map_rvariant_t;
typedef boost::make_recursive_variant <bool, boost::uint8_t, boost::uint32_t,
boost::int32_t, double, std::string, boost::uuids::uuid,
vector_rvariant_t, map_rvariant_t > ::type rvariant_type;
/**
Wrapper class for boost::make_recuverise_variant<>::type
*/
class rvariant {
public:
// encode the _data to msgpack buffer
//NEED HELP for this function.
void encode(msgpack::sbuf& sbuf) {
// msgpack::pack(sbuf, (*type_)data_);
// msgpack::pack(sbuf, boost::get<typeid(data_)>(data_));
// msgpack::pack(sbuf, boost::get<*type_>(data_));
}
// constructor
explicit template <typename T> rvariant(const T& data) {
data_ = data;
type_ = (std::type_info*)&typeid(data);
}
// operator=
template <typename T> rvariant& operator=(const T& data) {
data_ = data;
type_ = (std::type_info*)&typeid(data);
return *this;
}
// get the data
template<typename T> T get() {
return boost::get< T >(data_);
}
private:
rvariant_type data_;
std::type_info* type_;
};