Skip to content

Commit d39ebcf

Browse files
committed
Add docs to warn about keeping a reference to the object_handle
1 parent 4df2bf7 commit d39ebcf

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

barretenberg/cpp/src/barretenberg/serialize/msgpack.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,21 @@ e.g. unpacking
9090
```
9191
msgpack::unpack((const char*)encoded_data, encoded_data_size).get().convert(*value);
9292
```
93+
94+
Note that `msgpack::unpack` returns a `msgpack::object_handle` which controls the lifetime
95+
of the `msgpack::object` returned by `msgpack::object_handle::get`, so if you need access
96+
to the object itself, do break up the above to keep a reference to the handle, for example:
97+
98+
```
99+
msgpack::object_handle oh = msgpack::unpack((const char*)encoded_data, encoded_data_size);
100+
msgpack::object o = oh.get();
101+
try {
102+
o.convert(*value);
103+
} catch (const msgpack::type_error&) {
104+
std::cerr << "failed to unpack: " << o << std::endl;
105+
throw;
106+
}
107+
```
93108
*/
94109
#include "msgpack_impl/concepts.hpp"
95110
#include "msgpack_impl/name_value_pair_macro.hpp"

0 commit comments

Comments
 (0)