X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ceph%2Fsrc%2Fcommon%2Fcmdparse.cc;h=9a873f5144216e8cde871a4aa6c98e46eda246b7;hb=d2e6a577eb19928d58b31d1b6e096ca0f03c4052;hp=5a8e78e08f22ca3e2a40a16d51d1a8a2568a9b67;hpb=31f18b776d001752a193a7cec8bb49033c1a904c;p=ceph.git diff --git a/ceph/src/common/cmdparse.cc b/ceph/src/common/cmdparse.cc index 5a8e78e08..9a873f514 100644 --- a/ceph/src/common/cmdparse.cc +++ b/ceph/src/common/cmdparse.cc @@ -55,12 +55,10 @@ dump_cmd_to_json(Formatter *f, const string& cmd) // elements are: "name", meaning "the typeless name that means a literal" // an object {} with key:value pairs representing an argument - int argnum = 0; stringstream ss(cmd); std::string word; while (std::getline(ss, word, ' ')) { - argnum++; // if no , or =, must be a plain word to put out if (word.find_first_of(",=") == string::npos) { f->dump_string("arg", word); @@ -185,6 +183,15 @@ void cmdmap_dump(const cmdmap_t &cmdmap, Formatter *f) } f->close_section(); } + + void operator()(const std::vector &operand) const + { + f->open_array_section(key.c_str()); + for (const auto i : operand) { + f->dump_float("item", i); + } + f->close_section(); + } }; //f->open_object_section("cmdmap"); @@ -240,7 +247,7 @@ cmdmap_from_json(vector cmd, map *mapp, stringstrea case json_spirit::array_type: { // array is a vector of values. Unpack it to a vector - // of strings or int64_t, the only types we handle. + // of strings, doubles, or int64_t, the only types we handle. const vector& spvals = it->second.get_array(); if (spvals.empty()) { // if an empty array is acceptable, the caller should always check for @@ -265,9 +272,18 @@ cmdmap_from_json(vector cmd, map *mapp, stringstrea outv.push_back(sv.get_int64()); } (*mapp)[it->first] = std::move(outv); + } else if (spvals.front().type() == json_spirit::real_type) { + vector outv; + for (const auto& sv : spvals) { + if (spvals.front().type() != json_spirit::real_type) { + throw(runtime_error("Can't handle arrays of multiple types")); + } + outv.push_back(sv.get_real()); + } + (*mapp)[it->first] = std::move(outv); } else { throw(runtime_error("Can't handle arrays of types other than " - "int or string")); + "int, string, or double")); } } break;