]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
tools/ceph-dencoder: add get_struct_v,get_struct_compat commands
authorKefu Chai <kchai@redhat.com>
Mon, 6 Jul 2020 10:12:31 +0000 (18:12 +0800)
committerKefu Chai <kchai@redhat.com>
Mon, 6 Jul 2020 14:58:05 +0000 (22:58 +0800)
for understanding the current encoding version and the lower bound of
supported decoders.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/tools/ceph-dencoder/ceph_dencoder.cc
src/tools/ceph-dencoder/denc_registry.h

index 53cf4c33696673cc3717495cda8b3c9927059775..2e4940256afd574e882f3b8cd11ab7f898d3a02e 100644 (file)
@@ -42,6 +42,8 @@ void usage(ostream &out)
   out << "  encode              encode in-memory object\n";
   out << "  dump_json           dump in-memory object as json (to stdout)\n";
   out << "  hexdump             print encoded data in hex\n";
+  out << "  get_struct_v        print version of the encoded object\n";
+  out << "  get_struct_compat   print the oldest version of decoder that can decode the encoded object\n";
   out << "\n";
   out << "  copy                copy object (via operator=)\n";
   out << "  copy_ctor           copy object (via copy ctor)\n";
@@ -154,6 +156,10 @@ int main(int argc, const char **argv)
 
     } else if (*i == string("hexdump")) {
       encbl.hexdump(cout);
+    } else if (*i == string("get_struct_v")) {
+      std::cout << den->get_struct_v(encbl, 0) << std::endl;
+    } else if (*i == string("get_struct_compat")) {
+      std::cout << den->get_struct_v(encbl, sizeof(uint8_t)) << std::endl;
     } else if (*i == string("import")) {
       ++i;
       if (i == args.end()) {
index d98c23130c1a63ff9a429ab0fcae62449b53fda1..74c7be97db7e674521c684bbd923e5e9b1394e27 100644 (file)
@@ -27,6 +27,12 @@ struct Dencoder {
   virtual int num_generated() = 0;
   virtual std::string select_generated(unsigned n) = 0;
   virtual bool is_deterministic() = 0;
+  unsigned get_struct_v(bufferlist bl, uint64_t seek) const {
+    auto p = bl.cbegin(seek);
+    uint8_t struct_v = 0;
+    ceph::decode(struct_v, p);
+    return struct_v;
+  }
   //virtual void print(ostream& out) = 0;
 };