diff --git a/include/nlohmann/detail/input/binary_reader.hpp b/include/nlohmann/detail/input/binary_reader.hpp index 778beaf19..bd2b2468d 100644 --- a/include/nlohmann/detail/input/binary_reader.hpp +++ b/include/nlohmann/detail/input/binary_reader.hpp @@ -344,8 +344,8 @@ class binary_reader nested document could declare a length that disagrees with where its terminator actually falls and quietly hand the bytes in between to the enclosing document. A well-formed document is at least 5 bytes (the prefix - plus the terminator); the equality also rejects those impossible sizes, - since at least 5 bytes are always consumed. + plus the terminator); open_bson_document() rejects a smaller size before + it is stored, so @a document_size is never negative here. @param[in] document_start value of chars_read before the size prefix @param[in] document_size the declared document size @@ -5075,8 +5075,9 @@ class binary_reader JSON_PRIVATE_UNLESS_TESTED: /*! @brief check whether @a marker is a type marker that may follow '$' - UBJSON: Z N T F i U I l L d D H C S [ {; BJData: the numeric markers and C - (BJData's excluded markers are rejected separately). + UBJSON: Z N T F i U I l L d D H C S [ {; BJData: the numeric markers and C. + The markers BJData excludes (F H N S T Z [ {) are the ones + binary_writer::is_bjdata_excluded_type_marker() lists; keep the two in sync. */ bool is_valid_optimized_type(const char_int_type marker) const noexcept { @@ -5111,20 +5112,6 @@ class binary_reader } } - /*! - @brief whether @a marker is excluded from BJData's optimized ND-array types - @return whether @a marker is one of 'F', 'H', 'N', 'S', 'T', 'Z', '[', '{' - - Mirrors binary_writer's @ref binary_writer::is_bjdata_excluded_type_marker - "is_bjdata_excluded_type_marker()`, which encodes the same list the other - way; keep the two in sync. - */ - static constexpr bool is_bjd_excluded_optimized_type(const char_int_type marker) noexcept - { - return marker == '[' || marker == '{' || marker == 'S' || marker == 'H' - || marker == 'T' || marker == 'F' || marker == 'N' || marker == 'Z'; - } - /*! @brief look up the ND-array element type name for a BJData dtype marker @return the type name ("uint8", "int8", ...), or nullptr if @a marker does diff --git a/include/nlohmann/detail/output/binary_writer.hpp b/include/nlohmann/detail/output/binary_writer.hpp index 62702524e..3b2f72901 100644 --- a/include/nlohmann/detail/output/binary_writer.hpp +++ b/include/nlohmann/detail/output/binary_writer.hpp @@ -4057,7 +4057,7 @@ class binary_writer Containers, strings, high-precision numbers, booleans and null cannot be declared as the single type of an optimized container in BJData; such a container is written unoptimized. The reader rejects them with the same - list (binary_reader::is_bjd_excluded_optimized_type()). + list (binary_reader::is_valid_optimized_type()). */ static constexpr bool is_bjdata_excluded_type_marker(const CharType marker) noexcept { diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 37f4b5901..e864507b9 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -18351,8 +18351,8 @@ class binary_reader nested document could declare a length that disagrees with where its terminator actually falls and quietly hand the bytes in between to the enclosing document. A well-formed document is at least 5 bytes (the prefix - plus the terminator); the equality also rejects those impossible sizes, - since at least 5 bytes are always consumed. + plus the terminator); open_bson_document() rejects a smaller size before + it is stored, so @a document_size is never negative here. @param[in] document_start value of chars_read before the size prefix @param[in] document_size the declared document size @@ -23082,8 +23082,9 @@ class binary_reader JSON_PRIVATE_UNLESS_TESTED: /*! @brief check whether @a marker is a type marker that may follow '$' - UBJSON: Z N T F i U I l L d D H C S [ {; BJData: the numeric markers and C - (BJData's excluded markers are rejected separately). + UBJSON: Z N T F i U I l L d D H C S [ {; BJData: the numeric markers and C. + The markers BJData excludes (F H N S T Z [ {) are the ones + binary_writer::is_bjdata_excluded_type_marker() lists; keep the two in sync. */ bool is_valid_optimized_type(const char_int_type marker) const noexcept { @@ -23118,20 +23119,6 @@ class binary_reader } } - /*! - @brief whether @a marker is excluded from BJData's optimized ND-array types - @return whether @a marker is one of 'F', 'H', 'N', 'S', 'T', 'Z', '[', '{' - - Mirrors binary_writer's @ref binary_writer::is_bjdata_excluded_type_marker - "is_bjdata_excluded_type_marker()`, which encodes the same list the other - way; keep the two in sync. - */ - static constexpr bool is_bjd_excluded_optimized_type(const char_int_type marker) noexcept - { - return marker == '[' || marker == '{' || marker == 'S' || marker == 'H' - || marker == 'T' || marker == 'F' || marker == 'N' || marker == 'Z'; - } - /*! @brief look up the ND-array element type name for a BJData dtype marker @return the type name ("uint8", "int8", ...), or nullptr if @a marker does @@ -32017,7 +32004,7 @@ class binary_writer Containers, strings, high-precision numbers, booleans and null cannot be declared as the single type of an optimized container in BJData; such a container is written unoptimized. The reader rejects them with the same - list (binary_reader::is_bjd_excluded_optimized_type()). + list (binary_reader::is_valid_optimized_type()). */ static constexpr bool is_bjdata_excluded_type_marker(const CharType marker) noexcept { diff --git a/tests/src/unit-bjdata.cpp b/tests/src/unit-bjdata.cpp index 04ee3acc4..9924dd804 100644 --- a/tests/src/unit-bjdata.cpp +++ b/tests/src/unit-bjdata.cpp @@ -78,23 +78,25 @@ TEST_CASE("BJData") { SECTION("binary_reader BJData lookup tables") { - // both lookups are static member functions + // bjd_type_name() is static; is_valid_optimized_type() needs a BJData reader std::vector const data; using reader_t = nlohmann::detail::binary_reader; - // the excluded optimized-type markers must match binary_writer's - // is_bjdata_excluded_type_marker(), which encodes the same 8 markers + // the markers BJData excludes as optimized types must match + // binary_writer's is_bjdata_excluded_type_marker(), which encodes the + // same 8 markers + reader_t reader(nlohmann::detail::input_adapter(data), json::input_format_t::bjdata); for (const char marker : - {'[', '{', 'S', 'H', 'T', 'F', 'N', 'Z' + {'[', '{', 'S', 'H', 'T', 'F', 'N', 'Z', 'x' }) { - CHECK(reader_t::is_bjd_excluded_optimized_type(static_cast(marker))); + CHECK(!reader.is_valid_optimized_type(static_cast(marker))); } for (const char marker : - {'U', 'i', 'u', 'I', 'm', 'l', 'M', 'L', 'd', 'D', 'C', 'B', 'x' + {'U', 'i', 'u', 'I', 'm', 'l', 'M', 'L', 'd', 'D', 'C', 'B', 'h' }) { - CHECK(!reader_t::is_bjd_excluded_optimized_type(static_cast(marker))); + CHECK(reader.is_valid_optimized_type(static_cast(marker))); } // every dtype marker must round-trip to its ND-array type name