From c49e5b15e0f86080d7d33e4e31aecfb701f8f96f Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Mon, 13 Apr 2026 14:05:03 +0200 Subject: Some minor polish from tourist branch (#949) - Replace per-type fmt::formatter specializations (StringBuilderBase, NiceBase) with a single generic formatter using a HasStringViewConversion concept - Add ThousandsNum for comma-separated integer formatting (e.g. "1,234,567") - Thread naming now accepts a sort hint for trace ordering - Fix main thread trace registration to use actual thread ID and sort first - Add ExpandEnvironmentVariables() for expanding %VAR% references in strings, with tests - Add ParseHexBytes() overload with expected byte count validation - Add Flag_BelowNormalPriority to CreateProcOptions (BELOW_NORMAL_PRIORITY_CLASS on Windows, setpriority on POSIX) - Add PrettyScroll progress bar mode that pins the status line to the bottom of the terminal using scroll regions, with signal handler cleanup for Ctrl+C/SIGTERM --- src/zencore/compactbinaryjson.cpp | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'src/zencore/compactbinaryjson.cpp') diff --git a/src/zencore/compactbinaryjson.cpp b/src/zencore/compactbinaryjson.cpp index da560a449..5bfbd5e3e 100644 --- a/src/zencore/compactbinaryjson.cpp +++ b/src/zencore/compactbinaryjson.cpp @@ -11,6 +11,8 @@ #include #include +#include +#include #include ZEN_THIRD_PARTY_INCLUDES_START @@ -570,13 +572,37 @@ private: break; case Json::Type::NUMBER: { - if (FieldName.empty()) - { - Writer.AddFloat(Json.number_value()); + // If the JSON number has no fractional part and fits in an int64, + // store it as an integer so that AsInt32/AsInt64 work without + // requiring callers to go through AsFloat. + double Value = Json.number_value(); + double IntPart; + bool IsIntegral = (std::modf(Value, &IntPart) == 0.0) && + Value >= static_cast(std::numeric_limits::min()) && + Value <= static_cast(std::numeric_limits::max()); + + if (IsIntegral) + { + int64_t IntValue = static_cast(Value); + if (FieldName.empty()) + { + Writer.AddInteger(IntValue); + } + else + { + Writer.AddInteger(FieldName, IntValue); + } } else { - Writer.AddFloat(FieldName, Json.number_value()); + if (FieldName.empty()) + { + Writer.AddFloat(Value); + } + else + { + Writer.AddFloat(FieldName, Value); + } } } break; -- cgit v1.2.3