Skip to content

Commit 9de1ccc

Browse files
nebkatslowriot
authored andcommitted
BJData Fixes (nlohmann#4588)
1 parent 064d0ed commit 9de1ccc

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

docs/mkdocs/docs/api/basic_json/to_bjdata.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ The exact mapping and its limitations is described on a [dedicated page](../../f
3737
3838
`use_type` (in)
3939
: whether to add type annotations to container types (must be combined with `#!cpp use_size = true`); optional,
40+
`#!cpp false` by default.
4041
4142
`version` (in)
42-
: which version of BJData to use (see [draft 3](../../features/binary_formats/bjdata.md#draft-3-binary-format)); optional,
43-
`#!cpp false` by default.
43+
: which version of BJData to use (see [draft 3](../../features/binary_formats/bjdata.md#draft-3-binary-format));
44+
optional, `#!cpp bjdata_version_t::draft2` by default.
4445
4546
## Return value
4647

include/nlohmann/detail/output/binary_writer.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ class binary_writer
748748
const bool use_type, const bool add_prefix = true,
749749
const bool use_bjdata = false, const bjdata_version_t bjdata_version = bjdata_version_t::draft2)
750750
{
751-
const bool bjdata_draft3 = bjdata_version == bjdata_version_t::draft3;
751+
const bool bjdata_draft3 = use_bjdata && bjdata_version == bjdata_version_t::draft3;
752752

753753
switch (j.type())
754754
{
@@ -857,11 +857,11 @@ class binary_writer
857857
oa->write_character(to_char_type('['));
858858
}
859859

860-
if (use_type && ((use_bjdata && bjdata_draft3) || !j.m_data.m_value.binary->empty()))
860+
if (use_type && (bjdata_draft3 || !j.m_data.m_value.binary->empty()))
861861
{
862862
JSON_ASSERT(use_count);
863863
oa->write_character(to_char_type('$'));
864-
oa->write_character(use_bjdata && bjdata_draft3 ? 'B' : 'U');
864+
oa->write_character(bjdata_draft3 ? 'B' : 'U');
865865
}
866866

867867
if (use_count)
@@ -880,7 +880,7 @@ class binary_writer
880880
{
881881
for (size_t i = 0; i < j.m_data.m_value.binary->size(); ++i)
882882
{
883-
oa->write_character(to_char_type((use_bjdata && bjdata_draft3) ? 'B' : 'U'));
883+
oa->write_character(to_char_type(bjdata_draft3 ? 'B' : 'U'));
884884
oa->write_character(j.m_data.m_value.binary->data()[i]);
885885
}
886886
}

single_include/nlohmann/json.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16390,7 +16390,7 @@ class binary_writer
1639016390
const bool use_type, const bool add_prefix = true,
1639116391
const bool use_bjdata = false, const bjdata_version_t bjdata_version = bjdata_version_t::draft2)
1639216392
{
16393-
const bool bjdata_draft3 = bjdata_version == bjdata_version_t::draft3;
16393+
const bool bjdata_draft3 = use_bjdata && bjdata_version == bjdata_version_t::draft3;
1639416394

1639516395
switch (j.type())
1639616396
{
@@ -16499,11 +16499,11 @@ class binary_writer
1649916499
oa->write_character(to_char_type('['));
1650016500
}
1650116501

16502-
if (use_type && ((use_bjdata && bjdata_draft3) || !j.m_data.m_value.binary->empty()))
16502+
if (use_type && (bjdata_draft3 || !j.m_data.m_value.binary->empty()))
1650316503
{
1650416504
JSON_ASSERT(use_count);
1650516505
oa->write_character(to_char_type('$'));
16506-
oa->write_character(use_bjdata && bjdata_draft3 ? 'B' : 'U');
16506+
oa->write_character(bjdata_draft3 ? 'B' : 'U');
1650716507
}
1650816508

1650916509
if (use_count)
@@ -16522,7 +16522,7 @@ class binary_writer
1652216522
{
1652316523
for (size_t i = 0; i < j.m_data.m_value.binary->size(); ++i)
1652416524
{
16525-
oa->write_character(to_char_type((use_bjdata && bjdata_draft3) ? 'B' : 'U'));
16525+
oa->write_character(to_char_type(bjdata_draft3 ? 'B' : 'U'));
1652616526
oa->write_character(j.m_data.m_value.binary->data()[i]);
1652716527
}
1652816528
}

0 commit comments

Comments
 (0)