msgpack / msgpack-c

MessagePack implementation for C and C++ / msgpack.org[C/C++]
Other
3.02k stars 878 forks source link

MSGPACK_DEFINE_MAP with base classes #693

Open KoHcoJlb opened 6 years ago

KoHcoJlb commented 6 years ago

Shouldn't it pack base class fields into the map root?

redboltz commented 6 years ago

Could you elaborate the question? In addition, if you post a complete and minimal code that describes the issue, it is very helpful. You can use Wandbox for this. See https://wandbox.org/permlink/xIejfhw3v2y2SkBK

Modify code, click "Run", then click "Share", you can get updated permalink on your address bar.

KoHcoJlb commented 6 years ago

In your code snippet why derived is serialized to {"base":{"i":10},"j":20} instead of {"i":10,"j":20}?

redboltz commented 6 years ago

msgpack-c class adaptor is mapped to MAP or ARRAY. It is a design choice.

It is not all reason for that, but the base class and derived class could have the same name variables. Here is the example: https://wandbox.org/permlink/fs6iOWPCmT0qSEpS