Skip to content

Commit

Permalink
Serialize tool capabilities JSON without whitespace
Browse files Browse the repository at this point in the history
fixes #11087
  • Loading branch information
sfan5 committed Mar 20, 2021
1 parent 042131d commit 531e7ef
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/convert_json.cpp
Expand Up @@ -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();
}
3 changes: 3 additions & 0 deletions src/convert_json.h
Expand Up @@ -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);
3 changes: 2 additions & 1 deletion src/tool.cpp
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 531e7ef

Please sign in to comment.