55 return *
reinterpret_cast<char*
>(&num) == 1;
66template<
typename BasicJsonType,
typename InputAdapterType,
typename SAX = json_sax_dom_parser<BasicJsonType>>
69 using number_integer_t =
typename BasicJsonType::number_integer_t;
70 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
71 using number_float_t =
typename BasicJsonType::number_float_t;
72 using string_t =
typename BasicJsonType::string_t;
73 using binary_t =
typename BasicJsonType::binary_t;
74 using json_sax_t = SAX;
75 using char_type =
typename InputAdapterType::char_type;
76 using char_int_type =
typename std::char_traits<char_type>::int_type;
107 const
bool strict = true,
116 result = parse_bson_internal();
120 result = parse_cbor_internal(
true, tag_handler);
124 result = parse_msgpack_internal();
129 result = parse_ubjson_internal();
151 return sax->parse_error(chars_read, get_token_string(),
parse_error::create(110, chars_read,
152 exception_message(input_format,
concat(
"expected end of input; last byte: 0x", get_token_string()),
"value"),
nullptr));
168 bool parse_bson_internal()
170 std::int32_t document_size{};
183 return sax->end_object();
193 bool get_bson_cstr(string_t& result)
195 auto out = std::back_inserter(result);
207 *out++ =
static_cast<typename string_t::value_type
>(current);
222 template<
typename NumberType>
223 bool get_bson_string(
const NumberType len, string_t& result)
227 auto last_token = get_token_string();
232 return get_string(
input_format_t::bson, len -
static_cast<NumberType
>(1), result) && get() != std::char_traits<char_type>::eof();
244 template<
typename NumberType>
245 bool get_bson_binary(
const NumberType len, binary_t& result)
249 auto last_token = get_token_string();
255 std::uint8_t subtype{};
257 result.set_subtype(subtype);
272 bool parse_bson_element_internal(
const char_int_type element_type,
273 const std::size_t element_type_parse_position)
275 switch (element_type)
280 return get_number<double, true>(
input_format_t::bson, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
287 return get_number<std::int32_t, true>(
input_format_t::bson, len) && get_bson_string(len, value) && sax->string(value);
292 return parse_bson_internal();
297 return parse_bson_array();
304 return get_number<std::int32_t, true>(
input_format_t::bson, len) && get_bson_binary(len, value) && sax->binary(value);
309 return sax->boolean(get() != 0);
319 std::int32_t
value{};
320 return get_number<std::int32_t, true>(
input_format_t::bson, value) && sax->number_integer(value);
325 std::int64_t
value{};
326 return get_number<std::int64_t, true>(
input_format_t::bson, value) && sax->number_integer(value);
331 std::array<char, 3> cr{{}};
332 static_cast<void>((std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(element_type)));
333 std::string cr_str{cr.data()};
334 return sax->parse_error(element_type_parse_position, cr_str,
352 bool parse_bson_element_list(
const bool is_array)
356 while (
auto element_type = get())
363 const std::size_t element_type_parse_position = chars_read;
369 if (!is_array && !sax->key(key))
374 if (
JSON_HEDLEY_UNLIKELY(!parse_bson_element_internal(element_type, element_type_parse_position)))
390 bool parse_bson_array()
392 std::int32_t document_size{};
405 return sax->end_array();
420 bool parse_cbor_internal(
const bool get_char,
423 switch (get_char ? get() : current)
426 case std::char_traits<char_type>::eof():
454 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
458 std::uint8_t number{};
464 std::uint16_t number{};
470 std::uint32_t number{};
476 std::uint64_t number{};
505 return sax->number_integer(
static_cast<std::int8_t
>(0x20 - 1 - current));
509 std::uint8_t number{};
510 return get_number(
input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
515 std::uint16_t number{};
516 return get_number(
input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
521 std::uint32_t number{};
522 return get_number(
input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
527 std::uint64_t number{};
528 return get_number(
input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1)
529 -
static_cast<number_integer_t
>(number));
564 return get_cbor_binary(
b) && sax->binary(
b);
599 return get_cbor_string(s) && sax->string(s);
627 return get_cbor_array(
628 conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
633 return get_number(
input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
639 return get_number(
input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
645 return get_number(
input_format_t::cbor, len) && get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler);
651 return get_number(
input_format_t::cbor, len) && get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler);
655 return get_cbor_array(
static_cast<std::size_t
>(-1), tag_handler);
682 return get_cbor_object(conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
687 return get_number(
input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
693 return get_number(
input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
699 return get_number(
input_format_t::cbor, len) && get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler);
705 return get_number(
input_format_t::cbor, len) && get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler);
709 return get_cbor_object(
static_cast<std::size_t
>(-1), tag_handler);
735 auto last_token = get_token_string();
747 std::uint8_t subtype_to_ignore{};
753 std::uint16_t subtype_to_ignore{};
759 std::uint32_t subtype_to_ignore{};
765 std::uint64_t subtype_to_ignore{};
772 return parse_cbor_internal(
true, tag_handler);
783 std::uint8_t subtype{};
785 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
790 std::uint16_t subtype{};
792 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
797 std::uint32_t subtype{};
799 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
804 std::uint64_t subtype{};
806 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
810 return parse_cbor_internal(
true, tag_handler);
813 return get_cbor_binary(
b) && sax->binary(
b);
823 return sax->boolean(
false);
826 return sax->boolean(
true);
833 const auto byte1_raw = get();
838 const auto byte2_raw = get();
844 const auto byte1 =
static_cast<unsigned char>(byte1_raw);
845 const auto byte2 =
static_cast<unsigned char>(byte2_raw);
855 const auto half =
static_cast<unsigned int>((byte1 << 8u) + byte2);
856 const double val = [&half]
858 const int exp = (half >> 10u) & 0x1Fu;
859 const unsigned int mant = half & 0x3FFu;
865 return std::ldexp(mant, -24);
868 ? std::numeric_limits<double>::infinity()
869 :
std::numeric_limits<double>::quiet_NaN();
871 return std::ldexp(mant + 1024, exp - 25);
874 return sax->number_float((half & 0x8000u) != 0
875 ?
static_cast<number_float_t
>(-val)
876 :
static_cast<number_float_t
>(val),
"");
882 return get_number(
input_format_t::cbor, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
888 return get_number(
input_format_t::cbor, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
893 auto last_token = get_token_string();
911 bool get_cbor_string(string_t& result)
975 while (get() != 0xFF)
978 if (!get_cbor_string(chunk))
982 result.append(chunk);
989 auto last_token = get_token_string();
991 exception_message(
input_format_t::cbor,
concat(
"expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x", last_token),
"string"),
nullptr));
1007 bool get_cbor_binary(binary_t& result)
1054 std::uint16_t len{};
1061 std::uint32_t len{};
1068 std::uint64_t len{};
1075 while (get() != 0xFF)
1078 if (!get_cbor_binary(chunk))
1082 result.insert(result.end(), chunk.begin(), chunk.end());
1089 auto last_token = get_token_string();
1091 exception_message(
input_format_t::cbor,
concat(
"expected length specification (0x40-0x5B) or indefinite binary array type (0x5F); last byte: 0x", last_token),
"binary"),
nullptr));
1102 bool get_cbor_array(
const std::size_t len,
1110 if (len !=
static_cast<std::size_t
>(-1))
1112 for (std::size_t i = 0; i < len; ++i)
1122 while (get() != 0xFF)
1131 return sax->end_array();
1140 bool get_cbor_object(
const std::size_t len,
1151 if (len !=
static_cast<std::size_t
>(-1))
1153 for (std::size_t i = 0; i < len; ++i)
1170 while (get() != 0xFF)
1186 return sax->end_object();
1196 bool parse_msgpack_internal()
1201 case std::char_traits<char_type>::eof():
1333 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
1352 return get_msgpack_object(conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x0Fu));
1371 return get_msgpack_array(conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x0Fu));
1411 return get_msgpack_string(s) && sax->string(s);
1418 return sax->boolean(
false);
1421 return sax->boolean(
true);
1436 return get_msgpack_binary(
b) && sax->binary(
b);
1442 return get_number(
input_format_t::msgpack, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
1448 return get_number(
input_format_t::msgpack, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
1453 std::uint8_t number{};
1459 std::uint16_t number{};
1465 std::uint32_t number{};
1471 std::uint64_t number{};
1477 std::int8_t number{};
1483 std::int16_t number{};
1489 std::int32_t number{};
1495 std::int64_t number{};
1501 std::uint16_t len{};
1507 std::uint32_t len{};
1508 return get_number(
input_format_t::msgpack, len) && get_msgpack_array(conditional_static_cast<std::size_t>(len));
1513 std::uint16_t len{};
1519 std::uint32_t len{};
1520 return get_number(
input_format_t::msgpack, len) && get_msgpack_object(conditional_static_cast<std::size_t>(len));
1556 return sax->number_integer(
static_cast<std::int8_t
>(current));
1560 auto last_token = get_token_string();
1577 bool get_msgpack_string(string_t& result)
1631 std::uint16_t len{};
1637 std::uint32_t len{};
1643 auto last_token = get_token_string();
1645 exception_message(
input_format_t::msgpack,
concat(
"expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x", last_token),
"string"),
nullptr));
1660 bool get_msgpack_binary(binary_t& result)
1663 auto assign_and_return_true = [&result](std::int8_t subtype)
1665 result.set_subtype(
static_cast<std::uint8_t
>(subtype));
1680 std::uint16_t len{};
1687 std::uint32_t len{};
1695 std::int8_t subtype{};
1699 assign_and_return_true(subtype);
1704 std::uint16_t len{};
1705 std::int8_t subtype{};
1709 assign_and_return_true(subtype);
1714 std::uint32_t len{};
1715 std::int8_t subtype{};
1719 assign_and_return_true(subtype);
1724 std::int8_t subtype{};
1727 assign_and_return_true(subtype);
1732 std::int8_t subtype{};
1735 assign_and_return_true(subtype);
1740 std::int8_t subtype{};
1743 assign_and_return_true(subtype);
1748 std::int8_t subtype{};
1751 assign_and_return_true(subtype);
1756 std::int8_t subtype{};
1759 assign_and_return_true(subtype);
1771 bool get_msgpack_array(
const std::size_t len)
1778 for (std::size_t i = 0; i < len; ++i)
1786 return sax->end_array();
1793 bool get_msgpack_object(
const std::size_t len)
1801 for (std::size_t i = 0; i < len; ++i)
1816 return sax->end_object();
1830 bool parse_ubjson_internal(
const bool get_char =
true)
1832 return get_ubjson_value(get_char ? get_ignore_noop() : current);
1849 bool get_ubjson_string(string_t& result,
const bool get_char =
true)
1866 return get_number(input_format, len) && get_string(input_format, len, result);
1872 return get_number(input_format, len) && get_string(input_format, len, result);
1878 return get_number(input_format, len) && get_string(input_format, len, result);
1884 return get_number(input_format, len) && get_string(input_format, len, result);
1890 return get_number(input_format, len) && get_string(input_format, len, result);
1899 std::uint16_t len{};
1900 return get_number(input_format, len) && get_string(input_format, len, result);
1909 std::uint32_t len{};
1910 return get_number(input_format, len) && get_string(input_format, len, result);
1919 std::uint64_t len{};
1920 return get_number(input_format, len) && get_string(input_format, len, result);
1926 auto last_token = get_token_string();
1927 std::string message;
1931 message =
"expected length type specification (U, i, I, l, L); last byte: 0x" + last_token;
1935 message =
"expected length type specification (U, i, u, I, m, l, M, L); last byte: 0x" + last_token;
1937 return sax->parse_error(chars_read, last_token,
parse_error::create(113, chars_read, exception_message(input_format, message,
"string"),
nullptr));
1944 bool get_ubjson_ndarray_size(std::vector<size_t>& dim)
1946 std::pair<std::size_t, char_int_type> size_and_type;
1948 bool no_ndarray =
true;
1955 if (size_and_type.first != npos)
1957 if (size_and_type.second != 0)
1959 if (size_and_type.second !=
'N')
1961 for (std::size_t i = 0; i < size_and_type.first; ++i)
1967 dim.push_back(dimlen);
1973 for (std::size_t i = 0; i < size_and_type.first; ++i)
1979 dim.push_back(dimlen);
1985 while (current !=
']')
1991 dim.push_back(dimlen);
2009 bool get_ubjson_size_value(std::size_t& result,
bool& is_ndarray, char_int_type prefix = 0)
2013 prefix = get_ignore_noop();
2020 std::uint8_t number{};
2025 result =
static_cast<std::size_t
>(number);
2031 std::int8_t number{};
2038 return sax->parse_error(chars_read, get_token_string(),
parse_error::create(113, chars_read,
2039 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
2041 result =
static_cast<std::size_t
>(number);
2047 std::int16_t number{};
2054 return sax->parse_error(chars_read, get_token_string(),
parse_error::create(113, chars_read,
2055 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
2057 result =
static_cast<std::size_t
>(number);
2063 std::int32_t number{};
2070 return sax->parse_error(chars_read, get_token_string(),
parse_error::create(113, chars_read,
2071 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
2073 result =
static_cast<std::size_t
>(number);
2079 std::int64_t number{};
2086 return sax->parse_error(chars_read, get_token_string(),
parse_error::create(113, chars_read,
2087 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
2089 if (!value_in_range_of<std::size_t>(number))
2092 exception_message(input_format,
"integer value overflow",
"size"),
nullptr));
2094 result =
static_cast<std::size_t
>(number);
2104 std::uint16_t number{};
2109 result =
static_cast<std::size_t
>(number);
2119 std::uint32_t number{};
2124 result = conditional_static_cast<std::size_t>(number);
2134 std::uint64_t number{};
2139 if (!value_in_range_of<std::size_t>(number))
2142 exception_message(input_format,
"integer value overflow",
"size"),
nullptr));
2144 result = detail::conditional_static_cast<std::size_t>(number);
2156 return sax->parse_error(chars_read, get_token_string(),
parse_error::create(113, chars_read, exception_message(input_format,
"ndarray dimentional vector is not allowed",
"size"),
nullptr));
2158 std::vector<size_t> dim;
2163 if (dim.size() == 1 || (dim.size() == 2 && dim.at(0) == 1))
2165 result = dim.at(dim.size() - 1);
2179 string_t
key =
"_ArraySize_";
2180 if (
JSON_HEDLEY_UNLIKELY(!sax->start_object(3) || !sax->key(key) || !sax->start_array(dim.size())))
2188 if (result == 0 || result == npos)
2190 return sax->parse_error(chars_read, get_token_string(),
out_of_range::create(408, exception_message(input_format,
"excessive ndarray size caused overflow",
"size"),
nullptr));
2198 return sax->end_array();
2207 auto last_token = get_token_string();
2208 std::string message;
2212 message =
"expected length type specification (U, i, I, l, L) after '#'; last byte: 0x" + last_token;
2216 message =
"expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0x" + last_token;
2218 return sax->parse_error(chars_read, last_token,
parse_error::create(113, chars_read, exception_message(input_format, message,
"size"),
nullptr));
2232 bool get_ubjson_size_type(std::pair<std::size_t, char_int_type>& result,
bool inside_ndarray =
false)
2234 result.first = npos;
2236 bool is_ndarray =
false;
2242 result.second = get();
2244 &&
JSON_HEDLEY_UNLIKELY(std::binary_search(bjd_optimized_type_markers.begin(), bjd_optimized_type_markers.end(), result.second)))
2246 auto last_token = get_token_string();
2248 exception_message(input_format,
concat(
"marker 0x", last_token,
" is not a permitted optimized array type"),
"type"),
nullptr));
2263 auto last_token = get_token_string();
2265 exception_message(input_format,
concat(
"expected '#' after type information; last byte: 0x", last_token),
"size"),
nullptr));
2268 bool is_error = get_ubjson_size_value(result.first, is_ndarray);
2273 return sax->parse_error(chars_read, get_token_string(),
parse_error::create(112, chars_read,
2274 exception_message(input_format,
"ndarray can not be recursive",
"size"),
nullptr));
2276 result.second |= (1 << 8);
2283 bool is_error = get_ubjson_size_value(result.first, is_ndarray);
2286 return sax->parse_error(chars_read, get_token_string(),
parse_error::create(112, chars_read,
2287 exception_message(input_format,
"ndarray requires both type and size",
"size"),
nullptr));
2299 bool get_ubjson_value(
const char_int_type prefix)
2303 case std::char_traits<char_type>::eof():
2304 return unexpect_eof(input_format,
"value");
2307 return sax->boolean(
true);
2309 return sax->boolean(
false);
2316 std::uint8_t number{};
2317 return get_number(input_format, number) && sax->number_unsigned(number);
2322 std::int8_t number{};
2323 return get_number(input_format, number) && sax->number_integer(number);
2328 std::int16_t number{};
2329 return get_number(input_format, number) && sax->number_integer(number);
2334 std::int32_t number{};
2335 return get_number(input_format, number) && sax->number_integer(number);
2340 std::int64_t number{};
2341 return get_number(input_format, number) && sax->number_integer(number);
2350 std::uint16_t number{};
2351 return get_number(input_format, number) && sax->number_unsigned(number);
2360 std::uint32_t number{};
2361 return get_number(input_format, number) && sax->number_unsigned(number);
2370 std::uint64_t number{};
2371 return get_number(input_format, number) && sax->number_unsigned(number);
2380 const auto byte1_raw = get();
2385 const auto byte2_raw = get();
2391 const auto byte1 =
static_cast<unsigned char>(byte1_raw);
2392 const auto byte2 =
static_cast<unsigned char>(byte2_raw);
2402 const auto half =
static_cast<unsigned int>((byte2 << 8u) + byte1);
2403 const double val = [&half]
2405 const int exp = (half >> 10u) & 0x1Fu;
2406 const unsigned int mant = half & 0x3FFu;
2412 return std::ldexp(mant, -24);
2415 ? std::numeric_limits<double>::infinity()
2416 :
std::numeric_limits<double>::quiet_NaN();
2418 return std::ldexp(mant + 1024, exp - 25);
2421 return sax->number_float((half & 0x8000u) != 0
2422 ?
static_cast<number_float_t
>(-val)
2423 :
static_cast<number_float_t
>(val),
"");
2429 return get_number(input_format, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
2435 return get_number(input_format, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
2440 return get_ubjson_high_precision_number();
2452 auto last_token = get_token_string();
2454 exception_message(input_format,
concat(
"byte after 'C' must be in range 0x00..0x7F; last byte: 0x", last_token),
"char"),
nullptr));
2456 string_t s(1,
static_cast<typename string_t::value_type
>(current));
2457 return sax->string(s);
2463 return get_ubjson_string(s) && sax->string(s);
2467 return get_ubjson_array();
2470 return get_ubjson_object();
2475 auto last_token = get_token_string();
2476 return sax->parse_error(chars_read, last_token,
parse_error::create(112, chars_read, exception_message(input_format,
"invalid byte: 0x" + last_token,
"value"),
nullptr));
2482 bool get_ubjson_array()
2484 std::pair<std::size_t, char_int_type> size_and_type;
2493 if (input_format ==
input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0)
2495 size_and_type.second &= ~(
static_cast<char_int_type
>(1) << 8);
2496 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)
2500 string_t
key =
"_ArrayType_";
2503 auto last_token = get_token_string();
2505 exception_message(input_format,
"invalid byte: 0x" + last_token,
"type"),
nullptr));
2508 string_t
type = it->second;
2514 if (size_and_type.second ==
'C')
2516 size_and_type.second =
'U';
2519 key =
"_ArrayData_";
2525 for (std::size_t i = 0; i < size_and_type.first; ++i)
2533 return (sax->end_array() && sax->end_object());
2536 if (size_and_type.first != npos)
2543 if (size_and_type.second != 0)
2545 if (size_and_type.second !=
'N')
2547 for (std::size_t i = 0; i < size_and_type.first; ++i)
2558 for (std::size_t i = 0; i < size_and_type.first; ++i)
2574 while (current !=
']')
2584 return sax->end_array();
2590 bool get_ubjson_object()
2592 std::pair<std::size_t, char_int_type> size_and_type;
2599 if (input_format ==
input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0)
2601 auto last_token = get_token_string();
2603 exception_message(input_format,
"BJData object does not support ND-array size in optimized format",
"object"),
nullptr));
2607 if (size_and_type.first != npos)
2614 if (size_and_type.second != 0)
2616 for (std::size_t i = 0; i < size_and_type.first; ++i)
2631 for (std::size_t i = 0; i < size_and_type.first; ++i)
2652 while (current !=
'}')
2667 return sax->end_object();
2673 bool get_ubjson_high_precision_number()
2677 bool no_ndarray =
true;
2678 auto res = get_ubjson_size_value(size, no_ndarray);
2685 std::vector<char> number_vector;
2686 for (std::size_t i = 0; i < size; ++i)
2693 number_vector.push_back(
static_cast<char>(current));
2699 const auto result_number = number_lexer.scan();
2700 const auto number_string = number_lexer.get_token_string();
2701 const auto result_remainder = number_lexer.scan();
2708 exception_message(input_format,
concat(
"invalid number text: ", number_lexer.get_token_string()),
"high-precision number"),
nullptr));
2711 switch (result_number)
2713 case token_type::value_integer:
2714 return sax->number_integer(number_lexer.get_number_integer());
2715 case token_type::value_unsigned:
2716 return sax->number_unsigned(number_lexer.get_number_unsigned());
2717 case token_type::value_float:
2718 return sax->number_float(number_lexer.get_number_float(), std::move(number_string));
2719 case token_type::uninitialized:
2720 case token_type::literal_true:
2721 case token_type::literal_false:
2722 case token_type::literal_null:
2723 case token_type::value_string:
2724 case token_type::begin_array:
2725 case token_type::begin_object:
2726 case token_type::end_array:
2727 case token_type::end_object:
2728 case token_type::name_separator:
2729 case token_type::value_separator:
2730 case token_type::parse_error:
2731 case token_type::end_of_input:
2732 case token_type::literal_or_value:
2735 exception_message(input_format,
concat(
"invalid number text: ", number_lexer.get_token_string()),
"high-precision number"),
nullptr));
2755 return current = ia.get_character();
2761 char_int_type get_ignore_noop()
2767 while (current ==
'N');
2787 template<
typename NumberType,
bool InputIsLittleEndian = false>
2791 std::array<std::uint8_t,
sizeof(NumberType)> vec{};
2792 for (std::size_t i = 0; i <
sizeof(NumberType); ++i)
2803 vec[
sizeof(NumberType) - i - 1] =
static_cast<std::uint8_t
>(current);
2807 vec[i] =
static_cast<std::uint8_t
>(current);
2812 std::memcpy(&result, vec.data(),
sizeof(NumberType));
2830 template<
typename NumberType>
2832 const NumberType len,
2835 bool success =
true;
2836 for (NumberType i = 0; i < len; i++)
2844 result.push_back(
static_cast<typename string_t::value_type
>(current));
2863 template<
typename NumberType>
2865 const NumberType len,
2868 bool success =
true;
2869 for (NumberType i = 0; i < len; i++)
2877 result.push_back(
static_cast<std::uint8_t
>(current));
2892 return sax->parse_error(chars_read,
"<end of file>",
2901 std::string get_token_string()
const
2903 std::array<char, 3> cr{{}};
2904 static_cast<void>((std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(current)));
2905 return std::string{cr.data()};
2915 const std::string&
detail,
2916 const std::string& context)
const
2918 std::string error_msg =
"syntax error while parsing ";
2923 error_msg +=
"CBOR";
2927 error_msg +=
"MessagePack";
2931 error_msg +=
"UBJSON";
2935 error_msg +=
"BSON";
2939 error_msg +=
"BJData";
2954 InputAdapterType ia;
2957 char_int_type current = std::char_traits<char_type>::eof();
2960 std::size_t chars_read = 0;
2969 json_sax_t* sax =
nullptr;
2972#define JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_ \
2973 make_array<char_int_type>('F', 'H', 'N', 'S', 'T', 'Z', '[', '{')
2975#define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ \
2976 make_array<bjd_type>( \
2977 bjd_type{'C', "char"}, \
2978 bjd_type{'D', "double"}, \
2979 bjd_type{'I', "int16"}, \
2980 bjd_type{'L', "int64"}, \
2981 bjd_type{'M', "uint64"}, \
2982 bjd_type{'U', "uint8"}, \
2983 bjd_type{'d', "single"}, \
2984 bjd_type{'i', "int8"}, \
2985 bjd_type{'l', "int32"}, \
2986 bjd_type{'m', "uint32"}, \
2987 bjd_type{'u', "uint16"})
2995 using bjd_type = std::pair<char_int_type, string_t>;
3000#undef JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_
3001#undef JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_
3004#ifndef JSON_HAS_CPP_17
3005 template<
typename BasicJsonType,
typename InputAdapterType,
typename SAX>
3006 constexpr std::size_t binary_reader<BasicJsonType, InputAdapterType, SAX>::npos;
#define WPI_JSON_NAMESPACE_END
Definition: abi_macros.h:59
#define WPI_JSON_NAMESPACE_BEGIN
Definition: abi_macros.h:53
#define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_
Definition: binary_reader.h:2975
#define JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_
Definition: binary_reader.h:2972
deserialization of CBOR, MessagePack, and UBJSON values
Definition: binary_reader.h:68
binary_reader(const binary_reader &)=delete
binary_reader(binary_reader &&)=default
binary_reader(InputAdapterType &&adapter, const input_format_t format=input_format_t::json) noexcept
create a binary reader
Definition: binary_reader.h:84
binary_reader & operator=(const binary_reader &)=delete
bool sax_parse(const input_format_t format, json_sax_t *sax_, const bool strict=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error)
Definition: binary_reader.h:105
binary_reader & operator=(binary_reader &&)=default
token_type
token types for the parser
Definition: lexer.h:39
lexical analysis
Definition: lexer.h:112
static out_of_range create(int id_, const std::string &what_arg, BasicJsonContext context)
Definition: exceptions.h:226
static parse_error create(int id_, const position_t &pos, const std::string &what_arg, BasicJsonContext context)
create a parse error exception
Definition: exceptions.h:147
dimensionless::scalar_t exp(const ScalarUnit x) noexcept
Compute exponential function.
Definition: math.h:332
#define JSON_HEDLEY_NON_NULL(...)
Definition: hedley.h:1288
#define JSON_HEDLEY_UNLIKELY(expr)
Definition: hedley.h:1396
#define JSON_INLINE_VARIABLE
Definition: macro_scope.h:139
#define JSON_PRIVATE_UNLESS_TESTED
Definition: macro_scope.h:199
#define JSON_ASSERT(x)
Definition: macro_scope.h:192
detail namespace with internal helper functions
Definition: xchar.h:20
input_format_t
the supported input formats
Definition: input_adapters.h:34
OutStringType concat(Args &&... args)
Definition: string_concat.h:137
@ value
the parser finished reading a JSON value
@ key
the parser read a key of a value in an object
cbor_tag_handler_t
how to treat CBOR tags
Definition: binary_reader.h:40
@ store
store tags as binary type
@ error
throw a parse_error exception in case of a tag
static bool little_endianness(int num=1) noexcept
determine system byte order
Definition: binary_reader.h:53
iterator_input_adapter_factory< IteratorType >::adapter_type input_adapter(IteratorType first, IteratorType last)
Definition: input_adapters.h:382
@ strict
throw a type_error exception in case of invalid UTF-8
type
Definition: core.h:556
std::string to_string(const T &t)
Definition: base.h:92
auto format(wformat_string< T... > fmt, T &&... args) -> std::wstring
Definition: xchar.h:108