mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
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:
parent
7c3b5553d8
commit
d892cac58c
2 changed files with 12 additions and 8 deletions
|
@ -22,12 +22,14 @@ namespace zeek::threading::formatter
|
||||||
{
|
{
|
||||||
|
|
||||||
// For deprecated NullDoubleWriter
|
// For deprecated NullDoubleWriter
|
||||||
|
JSON::NullDoubleWriter::NullDoubleWriter(rapidjson::StringBuffer& stream)
|
||||||
|
: writer(std::make_unique<zeek::json::detail::NullDoubleWriter>(stream))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
bool JSON::NullDoubleWriter::Double(double d)
|
bool JSON::NullDoubleWriter::Double(double d)
|
||||||
{
|
{
|
||||||
if ( rapidjson::internal::Double(d).IsNanOrInf() )
|
return writer->Double(d);
|
||||||
return rapidjson::Writer<rapidjson::StringBuffer>::Null();
|
|
||||||
|
|
||||||
return rapidjson::Writer<rapidjson::StringBuffer>::Double(d);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON::JSON(MsgThread* t, TimeFormat tf, bool arg_include_unset_fields)
|
JSON::JSON(MsgThread* t, TimeFormat tf, bool arg_include_unset_fields)
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#define RAPIDJSON_HAS_STDSTRING 1
|
#define RAPIDJSON_HAS_STDSTRING 1
|
||||||
// Remove in v7.1 when removing NullDoubleWriter below and also remove
|
// Remove in v7.1 when removing NullDoubleWriter below and also remove
|
||||||
// rapidjson include tweaks from CMake's dynamic_plugin_base target.
|
// rapidjson include tweaks from CMake's dynamic_plugin_base target.
|
||||||
|
@ -46,11 +48,11 @@ public:
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
[[deprecated("Remove in v7.1 - This is an implementation detail.")]] NullDoubleWriter(
|
[[deprecated("Remove in v7.1 - This is an implementation detail.")]] NullDoubleWriter(
|
||||||
rapidjson::StringBuffer& stream)
|
rapidjson::StringBuffer& stream);
|
||||||
: rapidjson::Writer<rapidjson::StringBuffer>(stream)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
bool Double(double d);
|
bool Double(double d);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<json::detail::NullDoubleWriter> writer;
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue