-
Notifications
You must be signed in to change notification settings - Fork 875
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to only pack or unpack certain fields? #1019
Comments
https://github.com/msgpack/msgpack-c/wiki/v2_0_cpp_object#conversion
packYou can pack the only specific member variables but you need to call pack APIs directly. See unpackYou can't unpack only specific element using msgpack::unpack() function. If you really want to only specific element from MessagePack formatted byte stream, then you can use visitor APIs. convertIf msgpack::object contains MAP like |
Here's the way to somehow ignore certain fields: struct C
{
int a;
int b;
int c;
MSGPACK_DEFINE_MAP(a, b, c);
};
msgpack::sbuffer buff;
msgpack::packer<msgpack::sbuffer> packer(buff);
struct C_fieldless
{
int a;
msgpack::object b, c; // the fields that are ignored
MSGPACK_DEFINE_MAP(a, b, c);
};
msgpack::object_handle handle;
msgpack::unpack(handle, buff.data(), buff.size());
auto fieldless = handle.as<C_fieldsless>(); |
Is there anyway to control which fields are packed or unpacked on a call by call basis?
Can I do something like this?
The text was updated successfully, but these errors were encountered: