! @return whether array creation completed */
| 11554 | @return whether array creation completed |
| 11555 | */ |
| 11556 | bool get_ubjson_array() |
| 11557 | { |
| 11558 | std::pair<std::size_t, char_int_type> size_and_type; |
| 11559 | if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type))) |
| 11560 | { |
| 11561 | return false; |
| 11562 | } |
| 11563 | |
| 11564 | // 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): |
| 11565 | // {"_ArrayType_" : "typeid", "_ArraySize_" : [n1, n2, ...], "_ArrayData_" : [v1, v2, ...]} |
| 11566 | |
| 11567 | if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0) |
| 11568 | { |
| 11569 | 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 |
| 11570 | 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) |
| 11571 | { |
| 11572 | return p.first < t; |
| 11573 | }); |
| 11574 | string_t key = "_ArrayType_"; |
| 11575 | if (JSON_HEDLEY_UNLIKELY(it == bjd_types_map.end() || it->first != size_and_type.second)) |
| 11576 | { |
| 11577 | auto last_token = get_token_string(); |
| 11578 | return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, |
| 11579 | exception_message(input_format, "invalid byte: 0x" + last_token, "type"), nullptr)); |
| 11580 | } |
| 11581 | |
| 11582 | string_t type = it->second; // sax->string() takes a reference |
| 11583 | if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->string(type))) |
| 11584 | { |
| 11585 | return false; |
| 11586 | } |
| 11587 | |
| 11588 | if (size_and_type.second == 'C') |
| 11589 | { |
| 11590 | size_and_type.second = 'U'; |
| 11591 | } |
| 11592 | |
| 11593 | key = "_ArrayData_"; |
| 11594 | if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->start_array(size_and_type.first) )) |
| 11595 | { |
| 11596 | return false; |
| 11597 | } |
| 11598 | |
| 11599 | for (std::size_t i = 0; i < size_and_type.first; ++i) |
| 11600 | { |
| 11601 | if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second))) |
| 11602 | { |
| 11603 | return false; |
| 11604 | } |
| 11605 | } |
| 11606 | |
| 11607 | return (sax->end_array() && sax->end_object()); |
| 11608 | } |
| 11609 | |
| 11610 | if (size_and_type.first != npos) |
| 11611 | { |
| 11612 | if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first))) |
| 11613 | { |
nothing calls this directly
no test coverage detected