]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
tools/ceph-dencoder: introduce add_crc32c command to append crc32 for the 56925/head
authorIgor Fedotov <igor.fedotov@croit.io>
Tue, 16 Apr 2024 14:44:52 +0000 (17:44 +0300)
committerIgor Fedotov <igor.fedotov@croit.io>
Thu, 14 Nov 2024 11:22:49 +0000 (14:22 +0300)
encoded buffer.
Sometimes we might need to recalculate encoded object crc and this
looked like a non-trivial task before this patch.

Signed-off-by: Igor Fedotov <igor.fedotov@croit.io>
src/tools/ceph-dencoder/ceph_dencoder.cc

index a278e08629f5f30d557d8353d3d7419b8501b5e0..24640f9b51d656e5aa09bb0b3a7ef27d76993742 100644 (file)
@@ -49,6 +49,7 @@ void usage(ostream &out)
   out << "  skip <num>          skip <num> leading bytes before decoding\n";
   out << "  decode              decode into in-memory object\n";
   out << "  encode              encode in-memory object\n";
+  out << "  add_crc32c          calculate and encode crc32c for 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";
@@ -163,6 +164,16 @@ int main(int argc, const char **argv)
        return 1;
       }
       den->encode(encbl, features | CEPH_FEATURE_RESERVED); // hack for OSDMap
+    } else if (*i == string("add_crc32c")) {
+      if (!encbl.length()) {
+       cerr << "must first encode something" << std::endl;
+       return 1;
+      }
+      auto p = encbl.begin();
+      ceph_assert(skip < encbl.length());
+      p += skip;
+      __u32 crc = p.crc32c(encbl.length() - skip, 0);
+      encode(crc, encbl);
     } else if (*i == string("decode")) {
       if (!den) {
        cerr << "must first select type with 'type <name>'" << std::endl;