]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cls_replica_log: implement decode_json for the types
authorYehuda Sadeh <yehuda@inktank.com>
Sat, 29 Jun 2013 07:25:09 +0000 (00:25 -0700)
committerYehuda Sadeh <yehuda@inktank.com>
Tue, 2 Jul 2013 22:02:30 +0000 (15:02 -0700)
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/cls/replica_log/cls_replica_log_types.cc
src/cls/replica_log/cls_replica_log_types.h

index ba89fd42ae383d027711fd2a85ff5f2a53fec6c8..133d06c1f7f0fd71ec2fdba78dd95fff8b124cbf 100644 (file)
 
 void cls_replica_log_item_marker::dump(Formatter *f) const
 {
-  f->dump_string("item name", item_name);
-  f->dump_stream("item timestamp") << item_timestamp;
+  f->dump_string("name", item_name);
+  f->dump_stream("timestamp") << item_timestamp;
+}
+
+void cls_replica_log_item_marker::decode_json(JSONObj *obj)
+{
+  JSONDecoder::decode_json("name", item_name, obj);
+  JSONDecoder::decode_json("timestamp", item_timestamp, obj);
 }
 
 void cls_replica_log_item_marker::
@@ -32,12 +38,20 @@ generate_test_instances(std::list<cls_replica_log_item_marker*>& ls)
 
 void cls_replica_log_progress_marker::dump(Formatter *f) const
 {
-  f->dump_string("entity", entity_id);
-  f->dump_string("position_marker", position_marker);
-  position_time.gmtime(f->dump_stream("position_time"));
+  encode_json("entity", entity_id, f);
+  encode_json("position_marker", position_marker, f);
+  encode_json("position_time", position_time, f);
   encode_json("items_in_progress", items, f);
 }
 
+void cls_replica_log_progress_marker::decode_json(JSONObj *obj)
+{
+  JSONDecoder::decode_json("entity", entity_id, obj);
+  JSONDecoder::decode_json("position_marker", position_marker, obj);
+  JSONDecoder::decode_json("position_time", position_time, obj);
+  JSONDecoder::decode_json("items_in_progress", items, obj);
+}
+
 void cls_replica_log_progress_marker::
 generate_test_instances(std::list<cls_replica_log_progress_marker*>& ls)
 {
@@ -57,14 +71,24 @@ generate_test_instances(std::list<cls_replica_log_progress_marker*>& ls)
 
 void cls_replica_log_bound::dump(Formatter *f) const
 {
-  f->dump_string("position_marker", position_marker);
-  position_time.gmtime(f->dump_stream("position_time"));
-  f->dump_string("marker_exists", marker_exists ? "yes" : "no");
+  encode_json("position_marker", position_marker, f);
+  encode_json("position_time", position_time, f);
+  encode_json("marker_exists", marker_exists, f);
   if (marker_exists) {
     encode_json("marker", marker, f); //progress marker
   }
 }
 
+void cls_replica_log_bound::decode_json(JSONObj *obj)
+{
+  JSONDecoder::decode_json("position_marker", position_marker, obj);
+  JSONDecoder::decode_json("position_time", position_time, obj);
+  JSONDecoder::decode_json("marker_exists", marker_exists, obj);
+  if (marker_exists) {
+    JSONDecoder::decode_json("marker", marker, obj); //progress marker
+  }
+}
+
 void cls_replica_log_bound::
 generate_test_instances(std::list<cls_replica_log_bound*>& ls)
 {
index 39dc22e4456deb3bf12d65b8a0b75fd794614602..acd55dde533349fa6192a468640cf1451cf4c445 100644 (file)
@@ -17,6 +17,8 @@
 #include "include/types.h"
 #include <errno.h>
 
+class JSONObj;
+
 struct cls_replica_log_item_marker {
   string item_name; // the name of the item we're marking
   utime_t item_timestamp; // the time stamp at which the item was outdated
@@ -40,6 +42,7 @@ struct cls_replica_log_item_marker {
   }
 
   void dump(Formatter *f) const;
+  void decode_json(JSONObj *obj);
   static void generate_test_instances(std::list<cls_replica_log_item_marker*>& ls);
 };
 WRITE_CLASS_ENCODER(cls_replica_log_item_marker)
@@ -82,6 +85,7 @@ struct cls_replica_log_progress_marker {
   }
 
   void dump(Formatter *f) const;
+  void decode_json(JSONObj *obj);
   static void generate_test_instances(std::list<cls_replica_log_progress_marker*>& ls);
 };
 WRITE_CLASS_ENCODER(cls_replica_log_progress_marker)
@@ -182,6 +186,7 @@ public:
   }
 
   void dump(Formatter *f) const;
+  void decode_json(JSONObj *obj);
   static void generate_test_instances(std::list<cls_replica_log_bound*>& ls);
 };
 WRITE_CLASS_ENCODER(cls_replica_log_bound);