remove old property tree serialization code;

rename to_json_val -> to_rapidjson_val
This commit is contained in:
woodser
2019-11-30 17:24:11 -05:00
parent c3bc05d979
commit 2db2b209f5
6 changed files with 209 additions and 621 deletions
+7 -48
View File
@@ -170,7 +170,7 @@ void monero_utils::addJsonMember(string key, bool val, rapidjson::Document::Allo
}
}
rapidjson::Value monero_utils::to_json_val(rapidjson::Document::AllocatorType& allocator, const vector<string>& strs) {
rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const vector<string>& strs) {
rapidjson::Value value_arr(rapidjson::kArrayType);
rapidjson::Value value_str(rapidjson::kStringType);
for (const string& str : strs) {
@@ -180,7 +180,7 @@ rapidjson::Value monero_utils::to_json_val(rapidjson::Document::AllocatorType& a
return value_arr;
}
rapidjson::Value monero_utils::to_json_val(rapidjson::Document::AllocatorType& allocator, const vector<uint8_t>& nums) {
rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const vector<uint8_t>& nums) {
rapidjson::Value value_arr(rapidjson::kArrayType);
rapidjson::Value value_num(rapidjson::kNumberType);
for (const auto& num : nums) {
@@ -191,7 +191,7 @@ rapidjson::Value monero_utils::to_json_val(rapidjson::Document::AllocatorType& a
}
// TODO: remove these redundant implementations for different sizes?
rapidjson::Value monero_utils::to_json_val(rapidjson::Document::AllocatorType& allocator, const vector<uint32_t>& nums) {
rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const vector<uint32_t>& nums) {
rapidjson::Value value_arr(rapidjson::kArrayType);
rapidjson::Value value_num(rapidjson::kNumberType);
for (const auto& num : nums) {
@@ -201,7 +201,7 @@ rapidjson::Value monero_utils::to_json_val(rapidjson::Document::AllocatorType& a
return value_arr;
}
rapidjson::Value monero_utils::to_json_val(rapidjson::Document::AllocatorType& allocator, const vector<uint64_t>& nums) {
rapidjson::Value monero_utils::to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const vector<uint64_t>& nums) {
rapidjson::Value value_arr(rapidjson::kArrayType);
rapidjson::Value value_num(rapidjson::kNumberType);
for (const auto& num : nums) {
@@ -213,7 +213,7 @@ rapidjson::Value monero_utils::to_json_val(rapidjson::Document::AllocatorType& a
// ------------------------ PROPERTY TREES ---------------------------
// TODO: fully switch to rapidjson
// TODO: switch to rapidjson
string monero_utils::serialize(const boost::property_tree::ptree& node) {
std::stringstream ss;
@@ -222,7 +222,6 @@ string monero_utils::serialize(const boost::property_tree::ptree& node) {
return str.substr(0, str.size() - 1); // strip newline
}
// TODO: switch deserializes in this utils class to use this deserialize util
void monero_utils::deserialize(const string& json, boost::property_tree::ptree& root) {
std::istringstream iss = json.empty() ? std::istringstream() : std::istringstream(json);
try {
@@ -232,50 +231,10 @@ void monero_utils::deserialize(const string& json, boost::property_tree::ptree&
}
}
//boost::property_tree::ptree monero_utils::to_property_tree(const vector<string>& strs) {
// boost::property_tree::ptree strsNode;
// for (const auto& str : strs) {
// boost::property_tree::ptree strNode;
// strNode.put("", str);
// strsNode.push_back(std::make_pair("", strNode));
// }
// return strsNode;
//}
//
//boost::property_tree::ptree monero_utils::to_property_tree(const vector<uint8_t>& nums) {
// boost::property_tree::ptree numsNode;
// for (const auto& num : nums) {
// boost::property_tree::ptree numNode;
// numNode.put("", num);
// numsNode.push_back(std::make_pair("", numNode));
// }
// return numsNode;
//}
//
//// TODO: remove these redundant implementations for different sizes?
//boost::property_tree::ptree monero_utils::to_property_tree(const vector<uint32_t>& nums) {
// boost::property_tree::ptree numsNode;
// for (const auto& num : nums) {
// boost::property_tree::ptree numNode;
// numNode.put("", num);
// numsNode.push_back(std::make_pair("", numNode));
// }
// return numsNode;
//}
//
//boost::property_tree::ptree monero_utils::to_property_tree(const vector<uint64_t>& nums) {
// boost::property_tree::ptree numsNode;
// for (const auto& num : nums) {
// boost::property_tree::ptree numNode;
// numNode.put("", num);
// numsNode.push_back(std::make_pair("", numNode));
// }
// return numsNode;
//}
// ----------------------------------------------------------------------------
// TODO: is this unused?
// TODO: this is unused
shared_ptr<monero_block> monero_utils::cn_block_to_block(const cryptonote::block& cn_block) {
cryptonote::block temp = cn_block;
cout << cryptonote::obj_to_json_str(temp) << endl;
+8 -34
View File
@@ -66,8 +66,6 @@ namespace monero_utils
using namespace std;
using namespace cryptonote;
void dummy_method(const string& str); // TODO: remove this
// ------------------------ BINARY SERIALIZATION ----------------------------
void json_to_binary(const std::string &json, std::string &bin);
@@ -85,27 +83,27 @@ namespace monero_utils
void addJsonMember(string key, bool val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root);
// TODO: template implementation here, could move to monero_utils.hpp per https://stackoverflow.com/questions/3040480/c-template-function-compiles-in-header-but-not-implementation
template <class T> rapidjson::Value to_json_val(rapidjson::Document::AllocatorType& allocator, const vector<shared_ptr<T>>& vals) {
template <class T> rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const vector<shared_ptr<T>>& vals) {
rapidjson::Value value_arr(rapidjson::kArrayType);
for (const auto& val : vals) {
value_arr.PushBack(val->to_json_val(allocator), allocator);
value_arr.PushBack(val->to_rapidjson_val(allocator), allocator);
}
return value_arr;
}
// TODO: template implementation here, could move to monero_utils.hpp per https://stackoverflow.com/questions/3040480/c-template-function-compiles-in-header-but-not-implementation
template <class T> rapidjson::Value to_json_val(rapidjson::Document::AllocatorType& allocator, const vector<T>& vals) {
template <class T> rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const vector<T>& vals) {
rapidjson::Value value_arr(rapidjson::kArrayType);
for (const auto& val : vals) {
value_arr.PushBack(val.to_json_val(allocator), allocator);
value_arr.PushBack(val.to_rapidjson_val(allocator), allocator);
}
return value_arr;
}
rapidjson::Value to_json_val(rapidjson::Document::AllocatorType& allocator, const vector<string>& strs);
rapidjson::Value to_json_val(rapidjson::Document::AllocatorType& allocator, const vector<uint8_t>& nums);
rapidjson::Value to_json_val(rapidjson::Document::AllocatorType& allocator, const vector<uint32_t>& nums);
rapidjson::Value to_json_val(rapidjson::Document::AllocatorType& allocator, const vector<uint64_t>& nums);
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const vector<string>& strs);
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const vector<uint8_t>& nums);
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const vector<uint32_t>& nums);
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator, const vector<uint64_t>& nums);
// ------------------------ PROPERTY TREES ---------------------------
@@ -114,30 +112,6 @@ namespace monero_utils
string serialize(const boost::property_tree::ptree& node);
void deserialize(const string& json, boost::property_tree::ptree& root);
//
// // TODO: template implementation here, could move to monero_utils.hpp per https://stackoverflow.com/questions/3040480/c-template-function-compiles-in-header-but-not-implementation
// template <class T> boost::property_tree::ptree to_property_tree(const vector<shared_ptr<T>>& types) {
// boost::property_tree::ptree typeNodes;
// for (const auto& type : types) {
// typeNodes.push_back(std::make_pair("", type->to_property_tree()));
// }
// return typeNodes;
// }
//
// // TODO: template implementation here, could move to monero_utils.hpp per https://stackoverflow.com/questions/3040480/c-template-function-compiles-in-header-but-not-implementation
// template <class T> boost::property_tree::ptree to_property_tree(const vector<T>& types) {
// boost::property_tree::ptree typeNodes;
// for (const auto& type : types) {
// typeNodes.push_back(std::make_pair("", type.to_property_tree()));
// }
// return typeNodes;
// }
//
// boost::property_tree::ptree to_property_tree(const vector<string>& strs);
// boost::property_tree::ptree to_property_tree(const vector<uint8_t>& nums);
// boost::property_tree::ptree to_property_tree(const vector<uint32_t>& nums);
// boost::property_tree::ptree to_property_tree(const vector<uint64_t>& nums);
// --------------------------------------------------------------------------
/**