Closed patrickjane closed 2 years ago
I'm not sure what is the problem point, but I guess that the following information could help you.
MySubType is packed as [x,y]
and MyType is packed as [a,b,[x,y]]
, not [a,b,x,y]
.
Well, I tried to give a pretty detailed example and question.
The question is, how do I manually pack ThirdPartyType
into [a,b,[x,y]]
so it can be unpacked successfully?
I have tried
o.pack_array(2);
o.pack_uint16(v.getA());
o.pack_uint16(v.getB());
o.pack_array(2);
o.pack_uint16(v.getX());
o.pack_uint16(v.getY());
But it did not seem to work.
o.pack_array(3); // not 2
o.pack_uint16(v.getA());
o.pack_uint16(v.getB());
o.pack_array(2);
o.pack_uint16(v.getX());
o.pack_uint16(v.getY());
The first number of array should be 3 not 2 becaulse it has the third member [x, y]
.
Alright thanks, this worked.
Hello,
I have just started working with MsgPack (C++). I have a library which gives me some kind of data structures, where I am unable to use the intrusive approach, so I need to specialize
pack
(I only need the packing-part).However, what I would like to achieve, is that the binary format which is created using the specialized
pack
implementation can be unpacked again using otherstructs
which are using the intrusive approach. But I can't seem to get this to work. Specifically, I don't understand the concept ofMSGPACK_DEFINE
andMSGPACK_DEFINE_ARRAY
/MSGPACK_DEFINE_MAP
. I assume that when I useMSGPACK_DEFINE
, my custom struckt members are packed as array, so in my non-intrusive counterpart I would need to usepack_array
, but it stops working as soon as there are complex members.Let me clarify with an example:
And for the non-custom types (supplied by the 3rd party library) I use:
Now when I pack an instance of
ThirdPartyType
and try to unpack into aMyType
, the deserialization works, and membersa
andb
are set correctly.If I try to use a complex member in
MyType
, it won't work correctly anymore:And for the non-custom types (supplied by the 3rd party library) I use:
Now I don't get any exception, but
x
andy
are not set inother
.How do I need to
pack
inThirdPartyType
in order to be able to successfully unpack using the intrusive approach forMyType
(andMySubType
) ?