Skip to content

Commit

Permalink
🚧 support for UBJSON high-precision numbers #2286
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Jul 20, 2020
1 parent b1da58b commit 7cf2fe1
Show file tree
Hide file tree
Showing 3 changed files with 3,492 additions and 3,423 deletions.
30 changes: 30 additions & 0 deletions include/nlohmann/detail/input/binary_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <nlohmann/detail/exceptions.hpp>
#include <nlohmann/detail/input/input_adapters.hpp>
#include <nlohmann/detail/input/json_sax.hpp>
#include <nlohmann/detail/input/lexer.hpp>
#include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/meta/is_sax.hpp>
#include <nlohmann/detail/value_t.hpp>
Expand Down Expand Up @@ -2000,6 +2001,35 @@ class binary_reader
return get_number(input_format_t::ubjson, number) && sax->number_float(static_cast<number_float_t>(number), "");
}

case 'H':
{
std::size_t size{};
auto res = get_ubjson_size_value(size);

std::string s;
for (int i = 0; i < size; ++i)
{
get();
s.push_back(current);
}

auto ia = detail::input_adapter(std::forward<std::string>(s));
auto l = detail::lexer<BasicJsonType, decltype(ia)>(std::move(ia), false);
auto result = l.scan();

switch (result)
{
case detail::lexer_base<BasicJsonType>::token_type::value_integer:
return sax->number_integer(l.get_number_integer());
case detail::lexer_base<BasicJsonType>::token_type::value_unsigned:
return sax->number_unsigned(l.get_number_unsigned());
case detail::lexer_base<BasicJsonType>::token_type::value_float:
return sax->number_float(l.get_number_float(), std::move(s));
default:
return sax->parse_error(chars_read, s, parse_error::create(113, chars_read, exception_message(input_format_t::ubjson, "invalid number", "number")));
}
}

case 'C': // char
{
get();
Expand Down
Loading

0 comments on commit 7cf2fe1

Please sign in to comment.