Skip to content
Permalink
Browse files

Serialize tool capabilities JSON without whitespace

fixes #11087
  • Loading branch information
sfan5 committed Mar 20, 2021
1 parent 042131d commit 531e7ef8ebbb9c7e08bf9043d96a44558c7a6d7f
Showing with 13 additions and 4 deletions.
  1. +8 −3 src/convert_json.cpp
  2. +3 −0 src/convert_json.h
  3. +2 −1 src/tool.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();
}
@@ -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);
@@ -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)

0 comments on commit 531e7ef

Please sign in to comment.