From 288088d2739f3bc5473a9e246d780bcf39bc1e75 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Sat, 29 Jun 2013 00:25:09 -0700 Subject: [PATCH] cls_replica_log: implement decode_json for the types Signed-off-by: Yehuda Sadeh --- src/cls/replica_log/cls_replica_log_types.cc | 40 ++++++++++++++++---- src/cls/replica_log/cls_replica_log_types.h | 5 +++ 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/cls/replica_log/cls_replica_log_types.cc b/src/cls/replica_log/cls_replica_log_types.cc index ba89fd42ae383..133d06c1f7f0f 100644 --- a/src/cls/replica_log/cls_replica_log_types.cc +++ b/src/cls/replica_log/cls_replica_log_types.cc @@ -15,8 +15,14 @@ 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& 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& ls) { @@ -57,14 +71,24 @@ generate_test_instances(std::list& 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& ls) { diff --git a/src/cls/replica_log/cls_replica_log_types.h b/src/cls/replica_log/cls_replica_log_types.h index 39dc22e4456de..acd55dde53334 100644 --- a/src/cls/replica_log/cls_replica_log_types.h +++ b/src/cls/replica_log/cls_replica_log_types.h @@ -17,6 +17,8 @@ #include "include/types.h" #include +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& 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& 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& ls); }; WRITE_CLASS_ENCODER(cls_replica_log_bound); -- 2.39.5