! @brief Read a BSON element list (as specified in the BSON-spec) The same binary layout is used for objects and arrays, hence it must be indicated with the argument @a is_array which one is expected (true --> array, false --> object). @param[in] is_array Determines if the element list being read is to be treated as an object (@a is_array == false), or as an array (@a is_array =
| 9424 | @return whether a valid BSON-object/array was passed to the SAX parser |
| 9425 | */ |
| 9426 | bool parse_bson_element_list(const bool is_array) |
| 9427 | { |
| 9428 | string_t key; |
| 9429 | |
| 9430 | while (auto element_type = get()) |
| 9431 | { |
| 9432 | if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson, "element list"))) |
| 9433 | { |
| 9434 | return false; |
| 9435 | } |
| 9436 | |
| 9437 | const std::size_t element_type_parse_position = chars_read; |
| 9438 | if (JSON_HEDLEY_UNLIKELY(!get_bson_cstr(key))) |
| 9439 | { |
| 9440 | return false; |
| 9441 | } |
| 9442 | |
| 9443 | if (!is_array && !sax->key(key)) |
| 9444 | { |
| 9445 | return false; |
| 9446 | } |
| 9447 | |
| 9448 | if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_internal(element_type, element_type_parse_position))) |
| 9449 | { |
| 9450 | return false; |
| 9451 | } |
| 9452 | |
| 9453 | // get_bson_cstr only appends |
| 9454 | key.clear(); |
| 9455 | } |
| 9456 | |
| 9457 | return true; |
| 9458 | } |
| 9459 | |
| 9460 | /*! |
| 9461 | @brief Reads an array from the BSON input and passes it to the SAX-parser. |