From 9b19e94594576d874c0d6756a492b4c3a592619d Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 15 Sep 2026 21:00:38 +0200 Subject: [PATCH] Future-proof the Draft-3-only 'B' marker gate @gregmarr pointed out that dtype == 'B' && bjdata_version != draft3 only future-proofs by accident, since bjdata_version_t currently has exactly two values. Compare with < instead, so a later draft that keeps the 'B' marker valid does not need this gate revisited. Signed-off-by: Niels Lohmann --- include/nlohmann/detail/output/binary_writer.hpp | 12 ++++++------ single_include/nlohmann/json.hpp | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/nlohmann/detail/output/binary_writer.hpp b/include/nlohmann/detail/output/binary_writer.hpp index 70911ea6e2..a1f4957234 100644 --- a/include/nlohmann/detail/output/binary_writer.hpp +++ b/include/nlohmann/detail/output/binary_writer.hpp @@ -1691,12 +1691,12 @@ class binary_writer } CharType dtype = it->second; - // the 'B' (byte) marker is only defined by BJData Draft 3; emitting it - // under the default Draft 2 mode would produce a stream that Draft 2 - // readers reject, so such an object falls back to a plain object - // encoding instead (see the "Binary values" section of the BJData - // documentation) - if (dtype == 'B' && bjdata_version != bjdata_version_t::draft3) + // the 'B' (byte) marker is only defined from BJData Draft 3 onward; + // emitting it under an earlier draft would produce a stream that an + // earlier-draft reader rejects, so such an object falls back to a + // plain object encoding instead (see the "Binary values" section of + // the BJData documentation) + if (dtype == 'B' && bjdata_version < bjdata_version_t::draft3) { return true; } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index f3dcd34269..06fb89acc0 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -20262,12 +20262,12 @@ class binary_writer } CharType dtype = it->second; - // the 'B' (byte) marker is only defined by BJData Draft 3; emitting it - // under the default Draft 2 mode would produce a stream that Draft 2 - // readers reject, so such an object falls back to a plain object - // encoding instead (see the "Binary values" section of the BJData - // documentation) - if (dtype == 'B' && bjdata_version != bjdata_version_t::draft3) + // the 'B' (byte) marker is only defined from BJData Draft 3 onward; + // emitting it under an earlier draft would produce a stream that an + // earlier-draft reader rejects, so such an object falls back to a + // plain object encoding instead (see the "Binary values" section of + // the BJData documentation) + if (dtype == 'B' && bjdata_version < bjdata_version_t::draft3) { return true; }