Skip to content

Commit

Permalink
BJData Fixes (#4588)
Browse files Browse the repository at this point in the history
  • Loading branch information
nebkat authored Jan 7, 2025
1 parent 0cb1241 commit 48e7b4c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
5 changes: 3 additions & 2 deletions docs/mkdocs/docs/api/basic_json/to_bjdata.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ The exact mapping and its limitations is described on a [dedicated page](../../f
`use_type` (in)
: whether to add type annotations to container types (must be combined with `#!cpp use_size = true`); optional,
`#!cpp false` by default.
`version` (in)
: which version of BJData to use (see [draft 3](../../features/binary_formats/bjdata.md#draft-3-binary-format)); optional,
`#!cpp false` by default.
: which version of BJData to use (see [draft 3](../../features/binary_formats/bjdata.md#draft-3-binary-format));
optional, `#!cpp bjdata_version_t::draft2` by default.
## Return value
Expand Down
8 changes: 4 additions & 4 deletions include/nlohmann/detail/output/binary_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ class binary_writer
const bool use_type, const bool add_prefix = true,
const bool use_bjdata = false, const bjdata_version_t bjdata_version = bjdata_version_t::draft2)
{
const bool bjdata_draft3 = bjdata_version == bjdata_version_t::draft3;
const bool bjdata_draft3 = use_bjdata && bjdata_version == bjdata_version_t::draft3;

switch (j.type())
{
Expand Down Expand Up @@ -857,11 +857,11 @@ class binary_writer
oa->write_character(to_char_type('['));
}

if (use_type && ((use_bjdata && bjdata_draft3) || !j.m_data.m_value.binary->empty()))
if (use_type && (bjdata_draft3 || !j.m_data.m_value.binary->empty()))
{
JSON_ASSERT(use_count);
oa->write_character(to_char_type('$'));
oa->write_character(use_bjdata && bjdata_draft3 ? 'B' : 'U');
oa->write_character(bjdata_draft3 ? 'B' : 'U');
}

if (use_count)
Expand All @@ -880,7 +880,7 @@ class binary_writer
{
for (size_t i = 0; i < j.m_data.m_value.binary->size(); ++i)
{
oa->write_character(to_char_type((use_bjdata && bjdata_draft3) ? 'B' : 'U'));
oa->write_character(to_char_type(bjdata_draft3 ? 'B' : 'U'));
oa->write_character(j.m_data.m_value.binary->data()[i]);
}
}
Expand Down
8 changes: 4 additions & 4 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16384,7 +16384,7 @@ class binary_writer
const bool use_type, const bool add_prefix = true,
const bool use_bjdata = false, const bjdata_version_t bjdata_version = bjdata_version_t::draft2)
{
const bool bjdata_draft3 = bjdata_version == bjdata_version_t::draft3;
const bool bjdata_draft3 = use_bjdata && bjdata_version == bjdata_version_t::draft3;

switch (j.type())
{
Expand Down Expand Up @@ -16493,11 +16493,11 @@ class binary_writer
oa->write_character(to_char_type('['));
}

if (use_type && ((use_bjdata && bjdata_draft3) || !j.m_data.m_value.binary->empty()))
if (use_type && (bjdata_draft3 || !j.m_data.m_value.binary->empty()))
{
JSON_ASSERT(use_count);
oa->write_character(to_char_type('$'));
oa->write_character(use_bjdata && bjdata_draft3 ? 'B' : 'U');
oa->write_character(bjdata_draft3 ? 'B' : 'U');
}

if (use_count)
Expand All @@ -16516,7 +16516,7 @@ class binary_writer
{
for (size_t i = 0; i < j.m_data.m_value.binary->size(); ++i)
{
oa->write_character(to_char_type((use_bjdata && bjdata_draft3) ? 'B' : 'U'));
oa->write_character(to_char_type(bjdata_draft3 ? 'B' : 'U'));
oa->write_character(j.m_data.m_value.binary->data()[i]);
}
}
Expand Down

0 comments on commit 48e7b4c

Please sign in to comment.