Amalgamate

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann committed 2026-09-25 20:15:05 +02:00
1 parent d3be1bd74d
commit f6d7eaf280
1 file changed
+22 -14
+22 -14
View File
@@ -15990,7 +15990,7 @@ class binary_reader
} }
const bool negative = second >= 0xC0; const bool negative = second >= 0xC0;
std::int64_t value = static_cast<std::int64_t>(negative ? (second & 0x3F) : second); auto value = static_cast<std::int64_t>(negative ? (second & 0x3F) : second);
std::int64_t offset = 0; std::int64_t offset = 0;
int extra_bytes = 0; int extra_bytes = 0;
@@ -21194,6 +21194,21 @@ class binary_writer
return to_char_type(std::is_same<FloatType, float>::value ? 0x8E : 0x8F); return to_char_type(std::is_same<FloatType, float>::value ? 0x8E : 0x8F);
} }
/// @return the type marker for a FloatType value in @a format (CBOR, MessagePack, or BON8)
template<typename FloatType>
static CharType get_compact_float_prefix(const detail::input_format_t format)
{
if (format == detail::input_format_t::cbor)
{
return get_cbor_float_prefix(FloatType{});
}
if (format == detail::input_format_t::bon8)
{
return get_bon8_float_prefix<FloatType>();
}
return get_msgpack_float_prefix(FloatType{});
}
//////////// ////////////
// UBJSON // // UBJSON //
//////////// ////////////
@@ -21971,6 +21986,7 @@ class binary_writer
*/ */
static void check_bon8_utf8(const string_t& s, const BasicJsonType& context) static void check_bon8_utf8(const string_t& s, const BasicJsonType& context)
{ {
static_cast<void>(context); // only used when exceptions are enabled
const auto* data = reinterpret_cast<const unsigned char*>(s.data()); const auto* data = reinterpret_cast<const unsigned char*>(s.data());
for (std::size_t i = 0; i < s.size();) for (std::size_t i = 0; i < s.size();)
{ {
@@ -22086,15 +22102,15 @@ class binary_writer
JSON_HEDLEY_DIAGNOSTIC_PUSH JSON_HEDLEY_DIAGNOSTIC_PUSH
JSON_HEDLEY_PRAGMA(GCC diagnostic ignored "-Wfloat-equal") JSON_HEDLEY_PRAGMA(GCC diagnostic ignored "-Wfloat-equal")
#endif #endif
if (n == -1.0) if (n == static_cast<number_float_t>(-1))
{ {
oa.write_character(to_char_type(0xFB)); oa.write_character(to_char_type(0xFB));
} }
else if (n == 0.0 && !std::signbit(n)) else if (n == static_cast<number_float_t>(0) && !std::signbit(n))
{ {
oa.write_character(to_char_type(0xFC)); oa.write_character(to_char_type(0xFC));
} }
else if (n == 1.0) else if (n == static_cast<number_float_t>(1))
{ {
oa.write_character(to_char_type(0xFD)); oa.write_character(to_char_type(0xFD));
} }
@@ -22245,20 +22261,12 @@ class binary_writer
static_cast<double>(n) <= static_cast<double>((std::numeric_limits<float>::max)()) && static_cast<double>(n) <= static_cast<double>((std::numeric_limits<float>::max)()) &&
static_cast<double>(static_cast<float>(n)) == static_cast<double>(n)))) static_cast<double>(static_cast<float>(n)) == static_cast<double>(n))))
{ {
oa.write_character(format == detail::input_format_t::cbor oa.write_character(get_compact_float_prefix<float>(format));
? get_cbor_float_prefix(static_cast<float>(n))
: format == detail::input_format_t::bon8
? get_bon8_float_prefix<float>()
: get_msgpack_float_prefix(static_cast<float>(n)));
write_number(static_cast<float>(n)); write_number(static_cast<float>(n));
} }
else else
{ {
oa.write_character(format == detail::input_format_t::cbor oa.write_character(get_compact_float_prefix<number_float_t>(format));
? get_cbor_float_prefix(n)
: format == detail::input_format_t::bon8
? get_bon8_float_prefix<number_float_t>()
: get_msgpack_float_prefix(n));
write_number(n); write_number(n);
} }
#ifdef __GNUC__ #ifdef __GNUC__