formatters/JSON: Make JSON::NullDoubleWriter use zeek::json::detail version

Not using inheritance and preferring composition to avoid including the
detail/json.h header do an indirection via a unique_ptr and then just
re-use the Double() implementation.
This commit is contained in:
Arne Welzel 2023-06-17 14:09:03 +02:00
parent 7c3b5553d8
commit d892cac58c
2 changed files with 12 additions and 8 deletions

View file

@ -22,12 +22,14 @@ namespace zeek::threading::formatter
{
// For deprecated NullDoubleWriter
JSON::NullDoubleWriter::NullDoubleWriter(rapidjson::StringBuffer& stream)
: writer(std::make_unique<zeek::json::detail::NullDoubleWriter>(stream))
{
}
bool JSON::NullDoubleWriter::Double(double d)
{
if ( rapidjson::internal::Double(d).IsNanOrInf() )
return rapidjson::Writer<rapidjson::StringBuffer>::Null();
return rapidjson::Writer<rapidjson::StringBuffer>::Double(d);
return writer->Double(d);
}
JSON::JSON(MsgThread* t, TimeFormat tf, bool arg_include_unset_fields)