What is a MsgPack 'zone'
Asked Answered
C

2

7

I have seen references to 'zone' in the MsgPack C headers, but can find no documentation on what it is or what it's for. What is it? Furthermore, where's the function-by-function documentation for the C API?

Cartan answered 16/10, 2012 at 18:37 Comment(3)
I suggest reading its own documentation in first place...Pernod
Are you pointing me to msgpack.org? If so, I have not been able to find any helpful description of zones there either. Google finds a few references, but nothing very helpful: google.com/…Cartan
nope. Visit the link, that's the readme of the GitHub project.Pernod
I
4

msgpack_zone is an internal structure used for memory management & lifecycle at unpacking time. I would say you will never have to interact with it if you use the standard, high-level interface for unpacking or the alternative streaming version.

To my knowledge, there is no detailed documentation: instead you should refer to the test suite that provides convenient code samples to achieve the common tasks, e.g. see pack_unpack_c.cc and streaming_c.cc.

Imtiaz answered 17/10, 2012 at 8:26 Comment(0)
B
0

From what I could gather, it is a move-only type that stores the actual data of a msgpack::object. It very well might intended to be an implementation detail, but it actually leaks into users' code sometimes. For example, any time you want to capture a msgpack::object in a lambda, you have to capture the msgpack::zone object as well. Sometimes you can't use move capture (e.g. asio handlers in some cases will only take copyable handlers, or your compiler doesn't support the feature). To work around this, you can:

msgpack::unpacked r;
while (pac_.next(&r)) {
   auto msg = result.get();
   io_->post([this, msg, z = std::shared_ptr<msgpack::zone>(r.zone().release())]() {
                // msg is valid here            
             }));
}
Bespeak answered 13/2, 2016 at 19:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.