TEST_F(ResultsTests, test_serialize_row) { auto results = getSerializedRow(); pt::ptree tree; auto s = serializeRow(results.second, tree); EXPECT_TRUE(s.ok()); EXPECT_EQ(s.toString(), "OK"); EXPECT_EQ(results.first, tree); }
Status serializeQueryData(const QueryData& q, pt::ptree& tree) { for (const auto& r : q) { pt::ptree serialized; auto s = serializeRow(r, serialized); if (!s.ok()) { return s; } tree.push_back(std::make_pair("", serialized)); } return Status(0, "OK"); }
Status serializeRowJSON(const Row& r, std::string& json) { auto doc = JSON::newObject(); // An empty column list will traverse the row map. ColumnNames cols; auto status = serializeRow(r, cols, doc, doc.doc()); if (!status.ok()) { return status; } return doc.toString(json); }
Status serializeQueryData(const QueryData& q, const ColumnNames& cols, JSON& doc, rj::Document& arr) { for (const auto& r : q) { auto row_obj = doc.getObject(); auto status = serializeRow(r, cols, doc, row_obj); if (!status.ok()) { return status; } doc.push(row_obj, arr); } return Status(); }
Status serializeRowJSON(const Row& r, std::string& json) { pt::ptree tree; try { auto status = serializeRow(r, tree); if (!status.ok()) { return status; } std::ostringstream ss; pt::write_json(ss, tree, false); json = ss.str(); } catch (const std::exception& e) { return Status(1, e.what()); } return Status(0, "OK"); }