github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/runtime/util.cpp (about) 1 // Copyright (C) 2018 go-nebulas authors 2 // 3 // This file is part of the go-nebulas library. 4 // 5 // the go-nebulas library is free software: you can redistribute it and/or 6 // modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation, either version 3 of the License, or 9 // (at your option) any later version. 10 // 11 // the go-nebulas library is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with the go-nebulas library. If not, see 18 // <http://www.gnu.org/licenses/>. 19 // 20 21 #include "runtime/util.h" 22 #include "util/json_parser.h" 23 24 namespace neb { 25 namespace rt { 26 27 std::string meta_info_to_json( 28 const std::vector<std::pair<std::string, std::string>> &meta_info) { 29 boost::property_tree::ptree pt; 30 for (auto &ele : meta_info) { 31 pt.put(ele.first, ele.second); 32 } 33 std::string ret; 34 neb::util::json_parser::write_json(ret, pt); 35 return ret; 36 } 37 38 std::vector<std::pair<std::string, std::string>> 39 json_to_meta_info(const std::string &json) { 40 boost::property_tree::ptree pt; 41 neb::util::json_parser::read_json(json, pt); 42 43 std::vector<std::pair<std::string, std::string>> meta_info; 44 std::string start_height = pt.get<std::string>("start_height"); 45 std::string end_height = pt.get<std::string>("end_height"); 46 std::string version = pt.get<std::string>("version"); 47 48 meta_info.push_back(std::make_pair("start_height", start_height)); 49 meta_info.push_back(std::make_pair("end_height", end_height)); 50 meta_info.push_back(std::make_pair("version", version)); 51 return meta_info; 52 } 53 54 } // namespace rt 55 } // namespace neb