Avoid allocating temporary basic_json for cbor and msgpack object keys (#5328)

* avoid allocating temporary basic_json for CBOR and MessagePack object keys

Signed-off-by: alexprabhat99 <alexpbara@gmail.com>

* add size() to the custom object key test type

UBJSON and BJData access object keys through size() and c_str()
directly, so the key type now provides both and the comment says why.

Signed-off-by: alexprabhat99 <alexpbara@gmail.com>

* address review: drop key size()/c_str(), test keys below the depth limit

Nothing in the library calls size() or c_str() on an object key, so the
test key type only keeps data(), which JSON_DIAGNOSTICS needs.

The CBOR and MessagePack custom key tests now also nest objects deeper
than detail::recursion_depth_limit(), so keys written by
write_cbor_iterative and write_msgpack_iterative are covered as well.

Signed-off-by: alexprabhat99 <alexpbara@gmail.com>

---------

Signed-off-by: alexprabhat99 <alexpbara@gmail.com>
This commit is contained in:
Alex Prabhat Bara authored and GitHub committed 2026-10-09 13:22:07 +02:00
1 parent d33068da73
commit 69a0c1b82c
6 files changed
+393 -151

No files matched your search

+2 -1
View File
@@ -26,7 +26,8 @@ To store objects in C++, a type is defined by the template parameters described
`StringType`
: the type of the keys or names (e.g., `std::string`). The comparison function `std::less<StringType>` is used to
order elements inside the container.
order elements inside the container. `object_t::key_type` must be implicitly convertible to `string_t` (required by the
binary formats).
`AllocatorType`
: the allocator to use for objects (e.g., `std::allocator`)