Skip to content

BJData Fixes #4588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading