mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00

threading/formatters/JSON.h currently includes rapidjson headers for declaring the NullDoubleWriter. This appears mostly an internal detail, but results in the situation that 1) we need to ship rapidjson headers with the Zeek install tree and 2) taking care that external plugins are able to find these headers should they include formatters/JSON.h. There are currently no other Zeek headers that include rapidjson, so this seems very unfortunate and self-inflicted given it's not actually required. Attempt to hide this implementation detail with the goal to remove the rapidjson includes with v7.1 and then also stop bundling and exposing the include path to external plugins. The NullDoubleWriter implementation moves into a new formatters/detail/json.h header which is not installed. Closes #3128
65 lines
1.9 KiB
C++
65 lines
1.9 KiB
C++
// See the file "COPYING" in the main distribution directory for copyright.
|
|
|
|
#pragma once
|
|
|
|
#define RAPIDJSON_HAS_STDSTRING 1
|
|
// Remove in v7.1 when removing NullDoubleWriter below and also remove
|
|
// rapidjson include tweaks from CMake's dynamic_plugin_base target.
|
|
#include <rapidjson/document.h>
|
|
#include <rapidjson/writer.h>
|
|
|
|
#include "zeek/threading/Formatter.h"
|
|
|
|
namespace zeek::json::detail
|
|
{
|
|
class NullDoubleWriter;
|
|
}
|
|
|
|
namespace zeek::threading::formatter
|
|
{
|
|
|
|
/**
|
|
* A thread-safe class for converting values into a JSON representation
|
|
* and vice versa.
|
|
*/
|
|
class JSON : public Formatter
|
|
{
|
|
public:
|
|
enum TimeFormat
|
|
{
|
|
TS_EPOCH, // Doubles that represents seconds from the UNIX epoch.
|
|
TS_ISO8601, // ISO 8601 defined human readable timestamp format.
|
|
TS_MILLIS // Milliseconds from the UNIX epoch. Some consumers need this (e.g.,
|
|
// elasticsearch).
|
|
};
|
|
|
|
JSON(MsgThread* t, TimeFormat tf, bool include_unset_fields = false);
|
|
~JSON() override;
|
|
|
|
bool Describe(ODesc* desc, Value* val, const std::string& name = "") const override;
|
|
bool Describe(ODesc* desc, int num_fields, const Field* const* fields,
|
|
Value** vals) const override;
|
|
Value* ParseValue(const std::string& s, const std::string& name, TypeTag type,
|
|
TypeTag subtype = TYPE_ERROR) const override;
|
|
|
|
class NullDoubleWriter : public rapidjson::Writer<rapidjson::StringBuffer>
|
|
{
|
|
public:
|
|
[[deprecated("Remove in v7.1 - This is an implementation detail.")]] NullDoubleWriter(
|
|
rapidjson::StringBuffer& stream)
|
|
: rapidjson::Writer<rapidjson::StringBuffer>(stream)
|
|
{
|
|
}
|
|
bool Double(double d);
|
|
};
|
|
|
|
private:
|
|
void BuildJSON(zeek::json::detail::NullDoubleWriter& writer, Value* val,
|
|
const std::string& name = "") const;
|
|
|
|
TimeFormat timestamps;
|
|
bool surrounding_braces;
|
|
bool include_unset_fields;
|
|
};
|
|
|
|
} // namespace zeek::threading::formatter
|