When I parse from the buffer, I have to know,what the exact class type(myclass) of the buffer is. So I cant handle all the buffer parse in an uniform way. I have to distinguish every class type(can I?).
My questions is "how can i handle all the buffer parse in an uniform way,and dont need to care what the exact class type is." Is there any solution? Thanks for your help!
class myclass {
private:
std::string m_str;
std::vector<int> m_vec;
public:
MSGPACK_DEFINE(m_str, m_vec);
};
int main(void) {
std::vector<myclass> vec;
// add some elements into vec...
// you can serialize myclass directly
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, vec);
msgpack::unpacked msg;
msgpack::unpack(&msg, sbuf.data(), sbuf.size());
msgpack::object obj = msg.get();
// you can convert object to myclass directly
std::vector<myclass> rvec;
obj.convert(&rvec);
}
I expecte it works like this
class base
{
.....
};
class A:public base
{
....
};
class B:public base
{
....
};
base* parse(msgpack::sbuffer sbuf)
{
...
}
int main(void)
{
A a;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, a);
base* a1 = parse(sbuf);
....
B b;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, b);
base* b1 = parse(sbuf);
....
}