What is the MsgPack zone?

I saw links to the “zone” in the MsgPack C headers, but I can’t find documentation about what it is or what it is for. What is it? Also, where is the function documentation for the C API?

+6
source share
2 answers

msgpack_zone is an internal structure used for memory management and life cycle during unpacking. I would say that you will never have to interact with it if you use the standard high-level interface for unpacking or alternative streaming .

To my knowledge, there is no detailed documentation: instead, you should turn to a test suite that provides convenient code examples to achieve common tasks, for example. see pack_unpack_c.cc and streaming_c.cc .

+3
source

From what I could assemble, this is a move-only type in which the actual msgpack::object data is msgpack::object . This is very good, perhaps intended to detail the implementation, but sometimes it sometimes flows into the user code. For example, at any time when you want to capture msgpack::object in lambda, you should also capture msgpack::zone object. Sometimes you cannot use move capture (for example, asio handlers in some cases will only accept handlers with the ability to copy, or your compiler does not support this function). To get 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 })); } 
0
source

Source: https://habr.com/ru/post/927871/


All Articles