mirror of
https://github.com/nlohmann/json.git
synced 2026-07-05 18:15:10 +00:00
♻️ fix CBOR and BSON
This commit is contained in:
@@ -282,8 +282,26 @@ class binary_writer
|
||||
{
|
||||
if (j.m_value.binary->has_subtype())
|
||||
{
|
||||
write_number(static_cast<std::uint8_t>(0xd8));
|
||||
write_number(j.m_value.binary->subtype());
|
||||
if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint8_t>::max)())
|
||||
{
|
||||
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
|
||||
@@ -1096,7 +1114,7 @@ class binary_writer
|
||||
write_bson_entry_header(name, 0x05);
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user