mirror of
https://github.com/xmrig/xmrig.git
synced 2024-11-18 10:01:06 +00:00
More compact JSON formatting.
This commit is contained in:
parent
7eaf7764f7
commit
a8e86c3530
6 changed files with 16 additions and 5 deletions
12
src/3rdparty/rapidjson/prettywriter.h
vendored
12
src/3rdparty/rapidjson/prettywriter.h
vendored
|
@ -164,9 +164,10 @@ public:
|
|||
(void)memberCount;
|
||||
RAPIDJSON_ASSERT(Base::level_stack_.GetSize() >= sizeof(typename Base::Level));
|
||||
RAPIDJSON_ASSERT(Base::level_stack_.template Top<typename Base::Level>()->inArray);
|
||||
bool empty = Base::level_stack_.template Pop<typename Base::Level>(1)->valueCount == 0;
|
||||
typename Base::Level* level = Base::level_stack_.template Pop<typename Base::Level>(1);
|
||||
bool empty = level->valueCount == 0;
|
||||
|
||||
if (!empty && !(formatOptions_ & kFormatSingleLineArray)) {
|
||||
if (!empty && !level->inLine) {
|
||||
Base::os_->Put('\n');
|
||||
WriteIndent();
|
||||
}
|
||||
|
@ -211,13 +212,16 @@ protected:
|
|||
typename Base::Level* level = Base::level_stack_.template Top<typename Base::Level>();
|
||||
|
||||
if (level->inArray) {
|
||||
level->inLine = (formatOptions_ & kFormatSingleLineArray) && type != kObjectType && type != kArrayType;
|
||||
|
||||
if (level->valueCount > 0) {
|
||||
Base::os_->Put(','); // add comma if it is not the first element in array
|
||||
if (formatOptions_ & kFormatSingleLineArray)
|
||||
if (level->inLine) {
|
||||
Base::os_->Put(' ');
|
||||
}
|
||||
}
|
||||
|
||||
if (!(formatOptions_ & kFormatSingleLineArray)) {
|
||||
if (!level->inLine) {
|
||||
Base::os_->Put('\n');
|
||||
WriteIndent();
|
||||
}
|
||||
|
|
2
src/3rdparty/rapidjson/rapidjson.h
vendored
2
src/3rdparty/rapidjson/rapidjson.h
vendored
|
@ -403,7 +403,7 @@ RAPIDJSON_NAMESPACE_END
|
|||
*/
|
||||
#ifndef RAPIDJSON_ASSERT
|
||||
#include <cassert>
|
||||
#define RAPIDJSON_ASSERT(x) assert(x)
|
||||
#define RAPIDJSON_ASSERT(x)
|
||||
#endif // RAPIDJSON_ASSERT
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
|
1
src/3rdparty/rapidjson/writer.h
vendored
1
src/3rdparty/rapidjson/writer.h
vendored
|
@ -288,6 +288,7 @@ protected:
|
|||
Level(bool inArray_) : valueCount(0), inArray(inArray_) {}
|
||||
size_t valueCount; //!< number of values in this level
|
||||
bool inArray; //!< true if in array, otherwise in object
|
||||
bool inLine = false;
|
||||
};
|
||||
|
||||
static const size_t kDefaultLevelDepth = 32;
|
||||
|
|
|
@ -56,6 +56,8 @@ bool xmrig::Json::save(const char *fileName, const rapidjson::Document &doc)
|
|||
|
||||
rapidjson::OStreamWrapper osw(ofs);
|
||||
rapidjson::PrettyWriter<rapidjson::OStreamWrapper> writer(osw);
|
||||
writer.SetFormatOptions(rapidjson::kFormatSingleLineArray);
|
||||
|
||||
doc.Accept(writer);
|
||||
|
||||
return true;
|
||||
|
|
|
@ -118,6 +118,8 @@ bool xmrig::Json::save(const char *fileName, const rapidjson::Document &doc)
|
|||
|
||||
OStreamWrapper osw(ofs);
|
||||
PrettyWriter<OStreamWrapper> writer(osw);
|
||||
writer.SetFormatOptions(kFormatSingleLineArray);
|
||||
|
||||
doc.Accept(writer);
|
||||
|
||||
return true;
|
||||
|
|
|
@ -80,6 +80,8 @@ void xmrig::HttpApiResponse::end()
|
|||
StringBuffer buffer(nullptr, 4096);
|
||||
PrettyWriter<StringBuffer> writer(buffer);
|
||||
writer.SetMaxDecimalPlaces(10);
|
||||
writer.SetFormatOptions(kFormatSingleLineArray);
|
||||
|
||||
m_doc.Accept(writer);
|
||||
|
||||
HttpResponse::end(buffer.GetString(), buffer.GetSize());
|
||||
|
|
Loading…
Reference in a new issue