mirror of
https://github.com/nlohmann/json.git
synced 2026-09-30 03:30:31 +00:00
Select the BON8 float prefix by type
get_bon8_float_prefix only depends on the type of its argument, so make the type a template parameter instead of passing an unused value. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -1447,14 +1447,11 @@ class binary_writer
|
||||
return to_char_type(0xCB); // float 64
|
||||
}
|
||||
|
||||
static constexpr CharType get_bon8_float_prefix(float /*unused*/)
|
||||
/// @return the BON8 type marker for binary32 (float) or binary64 (double)
|
||||
template<typename FloatType>
|
||||
static constexpr CharType get_bon8_float_prefix()
|
||||
{
|
||||
return to_char_type(0x8E); // binary32
|
||||
}
|
||||
|
||||
static constexpr CharType get_bon8_float_prefix(double /*unused*/)
|
||||
{
|
||||
return to_char_type(0x8F); // binary64
|
||||
return to_char_type(std::is_same<FloatType, float>::value ? 0x8E : 0x8F);
|
||||
}
|
||||
|
||||
////////////
|
||||
@@ -2511,7 +2508,7 @@ class binary_writer
|
||||
oa.write_character(format == detail::input_format_t::cbor
|
||||
? get_cbor_float_prefix(static_cast<float>(n))
|
||||
: format == detail::input_format_t::bon8
|
||||
? get_bon8_float_prefix(static_cast<float>(n))
|
||||
? get_bon8_float_prefix<float>()
|
||||
: get_msgpack_float_prefix(static_cast<float>(n)));
|
||||
write_number(static_cast<float>(n));
|
||||
}
|
||||
@@ -2520,7 +2517,7 @@ class binary_writer
|
||||
oa.write_character(format == detail::input_format_t::cbor
|
||||
? get_cbor_float_prefix(n)
|
||||
: format == detail::input_format_t::bon8
|
||||
? get_bon8_float_prefix(n)
|
||||
? get_bon8_float_prefix<number_float_t>()
|
||||
: get_msgpack_float_prefix(n));
|
||||
write_number(n);
|
||||
}
|
||||
|
||||
@@ -21000,14 +21000,11 @@ class binary_writer
|
||||
return to_char_type(0xCB); // float 64
|
||||
}
|
||||
|
||||
static constexpr CharType get_bon8_float_prefix(float /*unused*/)
|
||||
/// @return the BON8 type marker for binary32 (float) or binary64 (double)
|
||||
template<typename FloatType>
|
||||
static constexpr CharType get_bon8_float_prefix()
|
||||
{
|
||||
return to_char_type(0x8E); // binary32
|
||||
}
|
||||
|
||||
static constexpr CharType get_bon8_float_prefix(double /*unused*/)
|
||||
{
|
||||
return to_char_type(0x8F); // binary64
|
||||
return to_char_type(std::is_same<FloatType, float>::value ? 0x8E : 0x8F);
|
||||
}
|
||||
|
||||
////////////
|
||||
@@ -22064,7 +22061,7 @@ class binary_writer
|
||||
oa.write_character(format == detail::input_format_t::cbor
|
||||
? get_cbor_float_prefix(static_cast<float>(n))
|
||||
: format == detail::input_format_t::bon8
|
||||
? get_bon8_float_prefix(static_cast<float>(n))
|
||||
? get_bon8_float_prefix<float>()
|
||||
: get_msgpack_float_prefix(static_cast<float>(n)));
|
||||
write_number(static_cast<float>(n));
|
||||
}
|
||||
@@ -22073,7 +22070,7 @@ class binary_writer
|
||||
oa.write_character(format == detail::input_format_t::cbor
|
||||
? get_cbor_float_prefix(n)
|
||||
: format == detail::input_format_t::bon8
|
||||
? get_bon8_float_prefix(n)
|
||||
? get_bon8_float_prefix<number_float_t>()
|
||||
: get_msgpack_float_prefix(n));
|
||||
write_number(n);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user