mirror of
https://github.com/nlohmann/json
synced 2024-11-22 12:00:05 +00:00
♻️ fix CBOR and BSON
This commit is contained in:
parent
046df035fa
commit
b7db1d68d9
@ -282,8 +282,26 @@ class binary_writer
|
|||||||
{
|
{
|
||||||
if (j.m_value.binary->has_subtype())
|
if (j.m_value.binary->has_subtype())
|
||||||
{
|
{
|
||||||
write_number(static_cast<std::uint8_t>(0xd8));
|
if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint8_t>::max)())
|
||||||
write_number(j.m_value.binary->subtype());
|
{
|
||||||
|
write_number(static_cast<std::uint8_t>(0xd8));
|
||||||
|
write_number(static_cast<std::uint8_t>(j.m_value.binary->subtype()));
|
||||||
|
}
|
||||||
|
else if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint16_t>::max)())
|
||||||
|
{
|
||||||
|
write_number(static_cast<std::uint8_t>(0xd9));
|
||||||
|
write_number(static_cast<std::uint16_t>(j.m_value.binary->subtype()));
|
||||||
|
}
|
||||||
|
else if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint32_t>::max)())
|
||||||
|
{
|
||||||
|
write_number(static_cast<std::uint8_t>(0xda));
|
||||||
|
write_number(static_cast<std::uint32_t>(j.m_value.binary->subtype()));
|
||||||
|
}
|
||||||
|
else if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint64_t>::max)())
|
||||||
|
{
|
||||||
|
write_number(static_cast<std::uint8_t>(0xdb));
|
||||||
|
write_number(static_cast<std::uint64_t>(j.m_value.binary->subtype()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// step 1: write control byte and the binary array size
|
// step 1: write control byte and the binary array size
|
||||||
@ -1096,7 +1114,7 @@ class binary_writer
|
|||||||
write_bson_entry_header(name, 0x05);
|
write_bson_entry_header(name, 0x05);
|
||||||
|
|
||||||
write_number<std::int32_t, true>(static_cast<std::int32_t>(value.size()));
|
write_number<std::int32_t, true>(static_cast<std::int32_t>(value.size()));
|
||||||
write_number(value.has_subtype() ? value.subtype() : std::uint8_t(0x00));
|
write_number(value.has_subtype() ? static_cast<std::uint8_t>(value.subtype()) : std::uint8_t(0x00));
|
||||||
|
|
||||||
oa->write_characters(reinterpret_cast<const CharType*>(value.data()), value.size());
|
oa->write_characters(reinterpret_cast<const CharType*>(value.data()), value.size());
|
||||||
}
|
}
|
||||||
|
@ -1817,7 +1817,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
@since version 3.8.0
|
@since version 3.8.0
|
||||||
*/
|
*/
|
||||||
JSON_HEDLEY_WARN_UNUSED_RESULT
|
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||||
static basic_json binary(const typename binary_t::container_type& init, std::uint8_t subtype)
|
static basic_json binary(const typename binary_t::container_type& init, typename binary_t::subtype_type subtype)
|
||||||
{
|
{
|
||||||
auto res = basic_json();
|
auto res = basic_json();
|
||||||
res.m_type = value_t::binary;
|
res.m_type = value_t::binary;
|
||||||
@ -1835,9 +1835,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @copydoc binary(const typename binary_t::container_type&, std::uint8_t)
|
/// @copydoc binary(const typename binary_t::container_type&, typename binary_t::subtype_type)
|
||||||
JSON_HEDLEY_WARN_UNUSED_RESULT
|
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||||
static basic_json binary(typename binary_t::container_type&& init, std::uint8_t subtype)
|
static basic_json binary(typename binary_t::container_type&& init, typename binary_t::subtype_type subtype)
|
||||||
{
|
{
|
||||||
auto res = basic_json();
|
auto res = basic_json();
|
||||||
res.m_type = value_t::binary;
|
res.m_type = value_t::binary;
|
||||||
|
@ -13585,8 +13585,26 @@ class binary_writer
|
|||||||
{
|
{
|
||||||
if (j.m_value.binary->has_subtype())
|
if (j.m_value.binary->has_subtype())
|
||||||
{
|
{
|
||||||
write_number(static_cast<std::uint8_t>(0xd8));
|
if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint8_t>::max)())
|
||||||
write_number(j.m_value.binary->subtype());
|
{
|
||||||
|
write_number(static_cast<std::uint8_t>(0xd8));
|
||||||
|
write_number(static_cast<std::uint8_t>(j.m_value.binary->subtype()));
|
||||||
|
}
|
||||||
|
else if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint16_t>::max)())
|
||||||
|
{
|
||||||
|
write_number(static_cast<std::uint8_t>(0xd9));
|
||||||
|
write_number(static_cast<std::uint16_t>(j.m_value.binary->subtype()));
|
||||||
|
}
|
||||||
|
else if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint32_t>::max)())
|
||||||
|
{
|
||||||
|
write_number(static_cast<std::uint8_t>(0xda));
|
||||||
|
write_number(static_cast<std::uint32_t>(j.m_value.binary->subtype()));
|
||||||
|
}
|
||||||
|
else if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint64_t>::max)())
|
||||||
|
{
|
||||||
|
write_number(static_cast<std::uint8_t>(0xdb));
|
||||||
|
write_number(static_cast<std::uint64_t>(j.m_value.binary->subtype()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// step 1: write control byte and the binary array size
|
// step 1: write control byte and the binary array size
|
||||||
@ -14399,7 +14417,7 @@ class binary_writer
|
|||||||
write_bson_entry_header(name, 0x05);
|
write_bson_entry_header(name, 0x05);
|
||||||
|
|
||||||
write_number<std::int32_t, true>(static_cast<std::int32_t>(value.size()));
|
write_number<std::int32_t, true>(static_cast<std::int32_t>(value.size()));
|
||||||
write_number(value.has_subtype() ? value.subtype() : std::uint8_t(0x00));
|
write_number(value.has_subtype() ? static_cast<std::uint8_t>(value.subtype()) : std::uint8_t(0x00));
|
||||||
|
|
||||||
oa->write_characters(reinterpret_cast<const CharType*>(value.data()), value.size());
|
oa->write_characters(reinterpret_cast<const CharType*>(value.data()), value.size());
|
||||||
}
|
}
|
||||||
@ -18911,7 +18929,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
@since version 3.8.0
|
@since version 3.8.0
|
||||||
*/
|
*/
|
||||||
JSON_HEDLEY_WARN_UNUSED_RESULT
|
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||||
static basic_json binary(const typename binary_t::container_type& init, std::uint8_t subtype)
|
static basic_json binary(const typename binary_t::container_type& init, typename binary_t::subtype_type subtype)
|
||||||
{
|
{
|
||||||
auto res = basic_json();
|
auto res = basic_json();
|
||||||
res.m_type = value_t::binary;
|
res.m_type = value_t::binary;
|
||||||
@ -18929,9 +18947,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @copydoc binary(const typename binary_t::container_type&, std::uint8_t)
|
/// @copydoc binary(const typename binary_t::container_type&, typename binary_t::subtype_type)
|
||||||
JSON_HEDLEY_WARN_UNUSED_RESULT
|
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||||
static basic_json binary(typename binary_t::container_type&& init, std::uint8_t subtype)
|
static basic_json binary(typename binary_t::container_type&& init, typename binary_t::subtype_type subtype)
|
||||||
{
|
{
|
||||||
auto res = basic_json();
|
auto res = basic_json();
|
||||||
res.m_type = value_t::binary;
|
res.m_type = value_t::binary;
|
||||||
|
Loading…
Reference in New Issue
Block a user