! @return whether array creation completed */
| 12274 | @return whether array creation completed |
| 12275 | */ |
| 12276 | bool get_ubjson_array() |
| 12277 | { |
| 12278 | std::pair<std::size_t, char_int_type> size_and_type; |
| 12279 | if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type))) |
| 12280 | { |
| 12281 | return false; |
| 12282 | } |
| 12283 | |
| 12284 | // if bit-8 of size_and_type.second is set to 1, encode bjdata ndarray as an object in JData annotated array format (https://github.com/NeuroJSON/jdata): |
| 12285 | // {"_ArrayType_" : "typeid", "_ArraySize_" : [n1, n2, ...], "_ArrayData_" : [v1, v2, ...]} |
| 12286 | |
| 12287 | if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0) |
| 12288 | { |
| 12289 | size_and_type.second &= ~(static_cast<char_int_type>(1) << 8); // use bit 8 to indicate ndarray, here we remove the bit to restore the type marker |
| 12290 | auto it = std::lower_bound(bjd_types_map.begin(), bjd_types_map.end(), size_and_type.second, [](const bjd_type & p, char_int_type t) |
| 12291 | { |
| 12292 | return p.first < t; |
| 12293 | }); |
| 12294 | string_t key = "_ArrayType_"; |
| 12295 | if (JSON_HEDLEY_UNLIKELY(it == bjd_types_map.end() || it->first != size_and_type.second)) |
| 12296 | { |
| 12297 | auto last_token = get_token_string(); |
| 12298 | return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, |
| 12299 | exception_message(input_format, "invalid byte: 0x" + last_token, "type"), nullptr)); |
| 12300 | } |
| 12301 | |
| 12302 | string_t type = it->second; // sax->string() takes a reference |
| 12303 | if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->string(type))) |
| 12304 | { |
| 12305 | return false; |
| 12306 | } |
| 12307 | |
| 12308 | if (size_and_type.second == 'C' || size_and_type.second == 'B') |
| 12309 | { |
| 12310 | size_and_type.second = 'U'; |
| 12311 | } |
| 12312 | |
| 12313 | key = "_ArrayData_"; |
| 12314 | if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->start_array(size_and_type.first) )) |
| 12315 | { |
| 12316 | return false; |
| 12317 | } |
| 12318 | |
| 12319 | for (std::size_t i = 0; i < size_and_type.first; ++i) |
| 12320 | { |
| 12321 | if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second))) |
| 12322 | { |
| 12323 | return false; |
| 12324 | } |
| 12325 | } |
| 12326 | |
| 12327 | return (sax->end_array() && sax->end_object()); |
| 12328 | } |
| 12329 | |
| 12330 | // If BJData type marker is 'B' decode as binary |
| 12331 | if (input_format == input_format_t::bjdata && size_and_type.first != npos && size_and_type.second == 'B') |
| 12332 | { |
| 12333 | binary_t result; |
nothing calls this directly
no test coverage detected