Commit 8ddb4e5c authored by Matthias Wittgen's avatar Matthias Wittgen
Browse files

switch to PrettyWriter

parent b7189195
......@@ -21,7 +21,7 @@
#include <rapidjson/istreamwrapper.h>
#include <rapidjson/ostreamwrapper.h>
#include <rapidjson/reader.h>
#include <rapidjson/writer.h>
#include <rapidjson/prettywriter.h>
#include <rapidjson/stringbuffer.h>
#include <MemoryBuffer.hpp>
......@@ -563,15 +563,19 @@ using I64=typename std::conditional<N==64, int64_t, int32_t>::type;
}
void dump(unsigned indent=0) const {
void dump(unsigned indent=4) const {
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
writer.SetIndent(' ',indent);
writer.SetFormatOptions(rapidjson::kFormatSingleLineArray);
dump(writer);
std::cout << buffer.GetString() << std::endl;
}
void toJson(rapidjson::StringBuffer &buffer) {
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
void toJson(rapidjson::StringBuffer &buffer,unsigned indent=4) {
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
writer.SetIndent(' ',indent);
writer.SetFormatOptions(rapidjson::kFormatSingleLineArray);
dump(writer);
}
......@@ -606,7 +610,7 @@ using I64=typename std::conditional<N==64, int64_t, int32_t>::type;
return v;
}
void dump(rapidjson::Writer<rapidjson::StringBuffer> &w) const noexcept {
void dump(rapidjson::PrettyWriter<rapidjson::StringBuffer> &w) const noexcept {
visit_v([&w](auto &&arg) {
using T = std::decay_t<decltype(arg)>;
if constexpr (is_specialization<T, ValPtr>::value) {
......@@ -1231,7 +1235,9 @@ template<typename T,
int>::type = 0>
std::ostream &operator<<(std::ostream &out, T const &var) {
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
writer.SetIndent(' ',4);
writer.SetFormatOptions(rapidjson::kFormatSingleLineArray);
var.dump(writer);
out << buffer.GetString();
return out;
......
......@@ -27,7 +27,7 @@ void run(const char *fn) {
std::chrono::duration<double> m3 = end3-start3;
std::cout << "from msgpack " << m3.count() << std::endl;
if constexpr(std::is_same_v<T,variant>) {
// w.dump();
w.dump();
}
......
#include <variant.hpp>
const char json[] = " { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1.1, 2.1, 3.1, 4.1] } ";
const char json[] = " { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1.1, 2.1, 3.1, 4.1] } ";
int main(int argc,char *argv[]){
variant32 v,w;
variant j;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment