mirror of
https://github.com/zeek/zeek.git
synced 2025-10-08 17:48:21 +00:00
Merge remote-tracking branch 'origin/topic/timw/595-rapidjson'
Tweaks: - Small change to the logic for removing quotes around strings. - Updated NEWS & COPYING.3rdparty - Use of intrusive_ptr for stack-allocated StringVals - Little bit of refactoring (I would love to merge the two BuildJSON() functions, too, but that's a larger task) * origin/topic/timw/595-rapidjson: Use the list of files from clang-tidy when searching for unit tests Optimize json_escape_utf8 a bit by removing repeated calls to string methods Expand unit test for json_escape_utf8 to include all of the strings from the ascii-json-utf8 btest GHI-595: Convert from nlohmann/json to rapidjson for performance reasons Convert type-checking macros to actual functions
This commit is contained in:
commit
8170baabef
12 changed files with 335 additions and 210 deletions
|
@ -2,24 +2,14 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "../Formatter.h"
|
||||
#include "3rdparty/json.hpp"
|
||||
#include "3rdparty/tsl-ordered-map/ordered_map.h"
|
||||
#define RAPIDJSON_HAS_STDSTRING 1
|
||||
#include "3rdparty/rapidjson/include/rapidjson/document.h"
|
||||
#include "3rdparty/rapidjson/include/rapidjson/writer.h"
|
||||
|
||||
#include "../Formatter.h"
|
||||
|
||||
namespace threading { namespace formatter {
|
||||
|
||||
// Define a class for use with the json library that orders the keys in the same order that
|
||||
// they were inserted. By default, the json library orders them alphabetically and we don't
|
||||
// want it like that.
|
||||
template<class Key, class T, class Ignore, class Allocator,
|
||||
class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>,
|
||||
class AllocatorPair = typename std::allocator_traits<Allocator>::template rebind_alloc<std::pair<Key, T>>,
|
||||
class ValueTypeContainer = std::vector<std::pair<Key, T>, AllocatorPair>>
|
||||
using ordered_map = tsl::ordered_map<Key, T, Hash, KeyEqual, AllocatorPair, ValueTypeContainer>;
|
||||
|
||||
using ZeekJson = nlohmann::basic_json<ordered_map>;
|
||||
|
||||
/**
|
||||
* A thread-safe class for converting values into a JSON representation
|
||||
* and vice versa.
|
||||
|
@ -40,9 +30,14 @@ public:
|
|||
threading::Value** vals) const override;
|
||||
threading::Value* ParseValue(const string& s, const string& name, TypeTag type, TypeTag subtype = TYPE_ERROR) const override;
|
||||
|
||||
private:
|
||||
class NullDoubleWriter : public rapidjson::Writer<rapidjson::StringBuffer> {
|
||||
public:
|
||||
NullDoubleWriter(rapidjson::StringBuffer& stream) : rapidjson::Writer<rapidjson::StringBuffer>(stream) {}
|
||||
bool Double(double d);
|
||||
};
|
||||
|
||||
ZeekJson BuildJSON(Value* val, const string& name = "") const;
|
||||
private:
|
||||
void BuildJSON(NullDoubleWriter& writer, Value* val, const string& name = "") const;
|
||||
|
||||
TimeFormat timestamps;
|
||||
bool surrounding_braces;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue