Skip to content
Takatoshi Kondo edited this page Apr 3, 2015 · 2 revisions

msgpack::object

What is msgpack::object

msgpack::object is a kind of variant type. The internal type of the msgpack::object is corresponding to the msgpack format.

If the type of msgpack::object is array or map, the object has children. So msgpack::object is a composite structure.

Object

When the type of msgpack::object is str, bin, or ext, the msgpack::object might have a reference of external memory.

ObjectMemory

When you use msgpack::unpacker, msgpack::unpacked manages all allocated memories. Treat msgpack::unpacked as a smart pointer.

When you use msgpack::unpack() function without unpack_referenc_func, msgpack::unpacked manages all allocated memories. If you give a custom unpack_referenc_func that returns true, you need to keep the lifetime of the data that you passed to msgpack::unpack() while the unpacked msgpack::unpacked exists.

Conversion

Conversion

When you unpack msgpack format data, you get msgpack::object from msgpack::unpacked. Then you get various types values from msgpack::object.

You can create an msgpack::object from a various type value using the following constructor.

    template <typename T>
    object(const T& v, zone& z);

You need pass a zone. When the object contains array and/or map, child objects are allocated in the zone. A value that has the type corresponding to str and bin, the contents of the value is copied to the zone without one exception. The exception is msgpack::type::raw_ref. When you call msgpack::object constructor with raw_ref as follows:

msgpack::object obj(msgpack::type::raw_ref(data, size), zone);

The data is NOT copied to the zone.