msgpack / msgpack-c

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

unpacking the same way as packing #788

Open DexterMagnific opened 5 years ago

DexterMagnific commented 5 years ago

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

redboltz commented 5 years ago

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