diff --git a/include/nlohmann/detail/input/binary_reader.hpp b/include/nlohmann/detail/input/binary_reader.hpp index a6e100e761..d94f5cc771 100644 --- a/include/nlohmann/detail/input/binary_reader.hpp +++ b/include/nlohmann/detail/input/binary_reader.hpp @@ -2311,6 +2311,7 @@ class binary_reader return sax->null(); case 'U': + case 'B': { std::uint8_t number{}; return get_number(input_format, number) && sax->number_unsigned(number); @@ -2532,6 +2533,13 @@ class binary_reader return (sax->end_array() && sax->end_object()); } + // If BJData type marker is 'B' decode as binary + if (input_format == input_format_t::bjdata && size_and_type.first != npos && size_and_type.second == 'B') + { + binary_t result; + return get_binary(input_format, size_and_type.first, result) && sax->binary(result); + } + if (size_and_type.first != npos) { if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first))) diff --git a/include/nlohmann/detail/output/binary_writer.hpp b/include/nlohmann/detail/output/binary_writer.hpp index f475d57be8..44e3912616 100644 --- a/include/nlohmann/detail/output/binary_writer.hpp +++ b/include/nlohmann/detail/output/binary_writer.hpp @@ -851,7 +851,7 @@ class binary_writer { JSON_ASSERT(use_count); oa->write_character(to_char_type('$')); - oa->write_character('U'); + oa->write_character(use_bjdata ? 'B' : 'U'); } if (use_count) @@ -870,7 +870,7 @@ class binary_writer { for (size_t i = 0; i < j.m_data.m_value.binary->size(); ++i) { - oa->write_character(to_char_type('U')); + oa->write_character(to_char_type(use_bjdata ? 'B' : 'U')); oa->write_character(j.m_data.m_value.binary->data()[i]); } } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 8b72ea6539..5b7590f9b2 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -11456,6 +11456,7 @@ class binary_reader return sax->null(); case 'U': + case 'B': { std::uint8_t number{}; return get_number(input_format, number) && sax->number_unsigned(number); @@ -11677,6 +11678,13 @@ class binary_reader return (sax->end_array() && sax->end_object()); } + // If BJData type marker is 'B' decode as binary + if (input_format == input_format_t::bjdata && size_and_type.first != npos && size_and_type.second == 'B') + { + binary_t result; + return get_binary(input_format, size_and_type.first, result) && sax->binary(result); + } + if (size_and_type.first != npos) { if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first))) @@ -15890,7 +15898,7 @@ class binary_writer { JSON_ASSERT(use_count); oa->write_character(to_char_type('$')); - oa->write_character('U'); + oa->write_character(use_bjdata ? 'B' : 'U'); } if (use_count) @@ -15909,7 +15917,7 @@ class binary_writer { for (size_t i = 0; i < j.m_data.m_value.binary->size(); ++i) { - oa->write_character(to_char_type('U')); + oa->write_character(to_char_type(use_bjdata ? 'B' : 'U')); oa->write_character(j.m_data.m_value.binary->data()[i]); } }