I want to pack my C++ class structure with msgpack
using some polymorphous mechanism to apply code packing base classes only once.
Currently, I am packing the data twice, in the base class and in the subclass.
This is my current status:
class Base {
public:
template <typename Packer>
void msgpack_pack(Packer& pk) const
{
pk.pack_map(1);
pk.pack("key");
pk.pack("value");
}
};
class Subclass : public Base {
public:
template <typename Packer>
void msgpack_pack(Packer& pk) const
{
pk.pack_map(2);
// code repetition
pk.pack("key");
pk.pack("value");
//////////////////
pk.pack("child_key");
pk.pack("child_value");
}
};
I want to get rid of the lines in between "code repetition" but I am currently now aware of how to achieve this. Would be nice if someone had an idea.