summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2021-03-20 22:06:17 +0100
committersfan5 <sfan5@live.de>2021-03-20 22:06:17 +0100
commit531e7ef8ebbb9c7e08bf9043d96a44558c7a6d7f (patch)
tree84d6ab76e46bcdcd06295f68113e909f01500f7d
parent042131d91d0f61d1252d240aa799f3b12b509cfe (diff)
downloadminetest-531e7ef8ebbb9c7e08bf9043d96a44558c7a6d7f.tar.gz
minetest-531e7ef8ebbb9c7e08bf9043d96a44558c7a6d7f.tar.bz2
minetest-531e7ef8ebbb9c7e08bf9043d96a44558c7a6d7f.zip
Serialize tool capabilities JSON without whitespace
fixes #11087
-rw-r--r--src/convert_json.cpp11
-rw-r--r--src/convert_json.h3
-rw-r--r--src/tool.cpp3
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)