diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/convert_json.cpp | 11 | ||||
-rw-r--r-- | src/convert_json.h | 3 | ||||
-rw-r--r-- | src/tool.cpp | 3 |
3 files changed, 13 insertions, 4 deletions
diff --git a/src/convert_json.cpp b/src/convert_json.cpp index c774aa002..e9ff1e56c 100644 --- a/src/convert_json.cpp +++ b/src/convert_json.cpp @@ -68,12 +68,17 @@ Json::Value fetchJsonValue(const std::string &url, return root; } -std::string fastWriteJson(const Json::Value &value) +void fastWriteJson(const Json::Value &value, std::ostream &to) { - std::ostringstream oss; Json::StreamWriterBuilder builder; builder["indentation"] = ""; std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter()); - writer->write(value, &oss); + writer->write(value, &to); +} + +std::string fastWriteJson(const Json::Value &value) +{ + std::ostringstream oss; + fastWriteJson(value, oss); return oss.str(); } diff --git a/src/convert_json.h b/src/convert_json.h index d8825acdc..2c094a946 100644 --- a/src/convert_json.h +++ b/src/convert_json.h @@ -20,8 +20,11 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #include <json/json.h> +#include <ostream> Json::Value fetchJsonValue(const std::string &url, std::vector<std::string> *extra_headers); +void fastWriteJson(const Json::Value &value, std::ostream &to); + std::string fastWriteJson(const Json::Value &value); diff --git a/src/tool.cpp b/src/tool.cpp index 90f4f9c12..3f639a69e 100644 --- a/src/tool.cpp +++ b/src/tool.cpp @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "log.h" #include "inventory.h" #include "exceptions.h" +#include "convert_json.h" #include "util/serialize.h" #include "util/numeric.h" @@ -142,7 +143,7 @@ void ToolCapabilities::serializeJson(std::ostream &os) const } root["damage_groups"] = damage_groups_object; - os << root; + fastWriteJson(root, os); } void ToolCapabilities::deserializeJson(std::istream &is) |