]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph_json: add a utime_t decoder
authorGreg Farnum <greg@inktank.com>
Mon, 1 Jul 2013 19:33:18 +0000 (12:33 -0700)
committerYehuda Sadeh <yehuda@inktank.com>
Tue, 2 Jul 2013 22:02:25 +0000 (15:02 -0700)
This needs to be cleaned up a bit as we don't actually want to
import rgw_common into ceph_json (we'll need to pull the parse_date
out of that and into somewhere more accessible/appropriate).

Signed-off-by: Greg Farnum <greg@inktank.com>
src/common/ceph_json.cc
src/common/ceph_json.h

index 04b21206ce8bf2082cdef6304f459f965adb79a5..516d263b6e1d8d065ae0a57ce9048d818f3a8a43 100644 (file)
@@ -440,6 +440,18 @@ void decode_json_obj(bufferlist& val, JSONObj *obj)
   }
 }
 
+void decode_json_obj(utime_t& val, JSONObj *obj)
+{
+  string s = obj->get_data();
+  uint64_t epoch;
+  int r = utime_t::parse_date(s, &epoch);
+  if (r == 0) {
+    val.set_from_double(epoch);
+  } else {
+    throw JSONDecoder::err("failed to decode utime_t");
+  }
+}
+
 void encode_json(const char *name, const string& val, Formatter *f)
 {
   f->dump_string(name, val);
index e11834a3371eb2b1d55f3e0a0b36143dd4116450..67efeae0e2a1388b49b381e46f87bed788e1abcf 100644 (file)
@@ -135,6 +135,8 @@ void decode_json_obj(unsigned& val, JSONObj *obj);
 void decode_json_obj(int& val, JSONObj *obj);
 void decode_json_obj(bool& val, JSONObj *obj);
 void decode_json_obj(bufferlist& val, JSONObj *obj);
+class utime_t;
+void decode_json_obj(utime_t& val, JSONObj *obj);
 
 template<class T>
 void decode_json_obj(list<T>& l, JSONObj *obj)