msgpack-c icon indicating copy to clipboard operation
msgpack-c copied to clipboard

unpacking the same way as packing

Open DexterMagnific opened this issue 6 years ago • 1 comments

Dear developer,

Is there a way to retrieve the "fields" of the unpacked object one by one as this done for packing ?

I know the "type" of the packed object, so after unpacking, i'd like simply to do something like:

int err;
int x = msgpack_unpack_int(pk, &err);

Currently, I must explore the self describing msg_pack object for type entry and value (much like I parse a JSON file).

Another question: if I send a series of packed objects through the network, is the library able to retrieve the packed objects one by one (is it able to detect packed object boundaries) ?

Thanks

DexterMagnific avatar Jun 18 '19 14:06 DexterMagnific

I don't understand the first question very much. But I guess that covert or as can do that. See https://github.com/msgpack/msgpack-c/wiki/v2_0_cpp_object#conversion

It's C++ version feature. In C, you need to convert step by step.

Another question: if I send a series of packed objects through the network, is the library able to retrieve the packed objects one by one (is it able to detect packed object boundaries) ?

Yes, you can use offset parameter that is in/out parameter, It indicates the start point of the buffer and after unpacking, updated as consumed point.

See https://github.com/msgpack/msgpack-c/blob/0a65c443a260e835e36b4d94b00468d9df1551a2/example/cpp11/container.cpp

redboltz avatar Jun 18 '19 15:06 redboltz