using namespace json_spirit;
-#define dout_subsys ceph_subsys_rgw
+using std::ifstream;
+using std::pair;
+using std::ostream;
+using std::string;
+using std::vector;
+using ceph::bufferlist;
+using ceph::Formatter;
-static JSONFormattable default_formattable;
+#define dout_subsys ceph_subsys_rgw
+static JSONFormattable default_formattable;
void encode_json(const char *name, const JSONObj::data_val& v, Formatter *f)
{
JSONObj::~JSONObj()
{
- multimap<string, JSONObj *>::iterator iter;
- for (iter = children.begin(); iter != children.end(); ++iter) {
+ for (auto iter = children.begin(); iter != children.end(); ++iter) {
JSONObj *obj = iter->second;
delete obj;
}
JSONObjIter JSONObj::find(const string& name)
{
JSONObjIter iter;
- map<string, JSONObj *>::iterator first;
- map<string, JSONObj *>::iterator last;
- first = children.find(name);
+ auto first = children.find(name);
if (first != children.end()) {
- last = children.upper_bound(name);
+ auto last = children.upper_bound(name);
iter.set(first, last);
}
return iter;
JSONObjIter JSONObj::find_first(const string& name)
{
JSONObjIter iter;
- map<string, JSONObj *>::iterator first;
- first = children.find(name);
+ auto first = children.find(name);
iter.set(first, children.end());
return iter;
}
bl.append(s.c_str(), s.size());
try {
val.decode_base64(bl);
- } catch (buffer::error& err) {
+ } catch (ceph::buffer::error& err) {
throw JSONDecoder::err("failed to decode base64");
}
}
}
}
+void decode_json_obj(ceph::real_time& val, JSONObj *obj)
+{
+ const std::string& s = obj->get_data();
+ uint64_t epoch;
+ uint64_t nsec;
+ int r = utime_t::parse_date(s, &epoch, &nsec);
+ if (r == 0) {
+ using namespace std::chrono;
+ val = real_time{seconds(epoch) + nanoseconds(nsec)};
+ } else {
+ throw JSONDecoder::err("failed to decode real_time");
+ }
+}
+
+void decode_json_obj(ceph::coarse_real_time& val, JSONObj *obj)
+{
+ const std::string& s = obj->get_data();
+ uint64_t epoch;
+ uint64_t nsec;
+ int r = utime_t::parse_date(s, &epoch, &nsec);
+ if (r == 0) {
+ using namespace std::chrono;
+ val = coarse_real_time{seconds(epoch) + nanoseconds(nsec)};
+ } else {
+ throw JSONDecoder::err("failed to decode coarse_real_time");
+ }
+}
+
+void decode_json_obj(ceph_dir_layout& i, JSONObj *obj){
+
+ unsigned tmp;
+ JSONDecoder::decode_json("dir_hash", tmp, obj, true);
+ i.dl_dir_hash = tmp;
+ JSONDecoder::decode_json("unused1", tmp, obj, true);
+ i.dl_unused1 = tmp;
+ JSONDecoder::decode_json("unused2", tmp, obj, true);
+ i.dl_unused2 = tmp;
+ JSONDecoder::decode_json("unused3", tmp, obj, true);
+ i.dl_unused3 = tmp;
+}
+
void encode_json(const char *name, const string& val, Formatter *f)
{
f->dump_string(name, val);
val.gmtime(f->dump_stream(name));
}
+void encode_json(const char *name, const ceph::real_time& val, Formatter *f)
+{
+ encode_json(name, utime_t{val}, f);
+}
+
+void encode_json(const char *name, const ceph::coarse_real_time& val, Formatter *f)
+{
+ encode_json(name, utime_t{val}, f);
+}
+
void encode_json(const char *name, const bufferlist& bl, Formatter *f)
{
/* need to copy data from bl, as it is const bufferlist */