25 virtual std::ostream&
Write(std::ostream& os, Args... args)
override {
27 os.seekp(0, std::ios::beg);
28 rapidjson::StringBuffer sb;
29 rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(sb);
31 (args.Write(writer, os), ...);
33 if (writer.IsComplete())
36 os.setstate(std::ios::failbit);
38 catch (
const std::exception& e) {
39 std::cerr <<
"Serialize error: " << e.what() << std::endl;
46 virtual std::istream&
Read(std::istream& is, Args&... args)
override {
49 std::streampos current_pos = is.tellg();
50 is.seekg(0, std::ios::end);
51 int length =
static_cast<int>(is.tellg());
52 is.seekg(current_pos, std::ios::beg);
55 char* buf = (
char*)malloc(length + 1);
60 is.rdbuf()->sgetn(buf, length);
66 rapidjson::Document doc;
71 if (doc.HasParseError())
74 is.setstate(std::ios::failbit);
75 std::cout <<
"Parse error: " << doc.GetParseError() << std::endl;
76 std::cout <<
"Error offset: " << doc.GetErrorOffset() << std::endl;
80 (args.Read(doc, is), ...);
83 catch (
const std::exception& e) {
84 std::cerr <<
"Deserialize error: " << e.what() << std::endl;