TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ parse_bson_element_internal()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>
bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::parse_bson_element_internal ( const char_int_type  element_type,
const std::size_t  element_type_parse_position 
)
inlineprivate

Read a BSON document element of the given element_type.

Parameters
[in]element_typeThe BSON element type, c.f. http://bsonspec.org/spec.html
[in]element_type_parse_positionThe position in the input stream, where the element_type was read.
Warning
Not all BSON element types are supported yet. An unsupported element_type will give rise to a parse_error.114: Unsupported BSON record type 0x...
Returns
whether a valid BSON-object/array was passed to the SAX parser

Definition at line 8647 of file json.hpp.

8649 {
8650 switch (element_type)
8651 {
8652 case 0x01: // double
8653 {
8654 double number{};
8655 return get_number<double, true>(input_format_t::bson, number) && sax->number_float(static_cast<number_float_t>(number), "");
8656 }
8657
8658 case 0x02: // string
8659 {
8660 std::int32_t len{};
8661 string_t value;
8662 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_string(len, value) && sax->string(value);
8663 }
8664
8665 case 0x03: // object
8666 {
8667 return parse_bson_internal();
8668 }
8669
8670 case 0x04: // array
8671 {
8672 return parse_bson_array();
8673 }
8674
8675 case 0x05: // binary
8676 {
8677 std::int32_t len{};
8678 binary_t value;
8679 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_binary(len, value) && sax->binary(value);
8680 }
8681
8682 case 0x08: // boolean
8683 {
8684 return sax->boolean(get() != 0);
8685 }
8686
8687 case 0x0A: // null
8688 {
8689 return sax->null();
8690 }
8691
8692 case 0x10: // int32
8693 {
8694 std::int32_t value{};
8695 return get_number<std::int32_t, true>(input_format_t::bson, value) && sax->number_integer(value);
8696 }
8697
8698 case 0x12: // int64
8699 {
8700 std::int64_t value{};
8701 return get_number<std::int64_t, true>(input_format_t::bson, value) && sax->number_integer(value);
8702 }
8703
8704 default: // anything else not supported (yet)
8705 {
8706 std::array<char, 3> cr{{}};
8707 (std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(element_type)); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
8708 return sax->parse_error(element_type_parse_position, std::string(cr.data()), parse_error::create(114, element_type_parse_position, "Unsupported BSON record type 0x" + std::string(cr.data()), BasicJsonType()));
8709 }
8710 }
8711 }
bool get_bson_string(const NumberType len, string_t &result)
Parses a zero-terminated string of length len from the BSON input.
Definition: json.hpp:8601
bool parse_bson_array()
Reads an array from the BSON input and passes it to the SAX-parser.
Definition: json.hpp:8764
bool get_bson_binary(const NumberType len, binary_t &result)
Parses a byte array input of length len from the BSON input.
Definition: json.hpp:8622
json_sax_t * sax
the SAX parser
Definition: json.hpp:10987
bool parse_bson_internal()
Reads in a BSON-object and passes it to the SAX-parser.
Definition: json.hpp:8542
char_int_type get()
get next character from the input
Definition: json.hpp:10769
static parse_error create(int id_, const position_t &pos, const std::string &what_arg, const BasicJsonType &context)
create a parse error exception
Definition: json.hpp:2800
@ value
the parser finished reading a JSON value