From: Igor Fedotov Date: Tue, 16 Apr 2024 14:44:52 +0000 (+0300) Subject: tools/ceph-dencoder: introduce add_crc32c command to append crc32 for the X-Git-Tag: v20.0.0~166^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F56925%2Fhead;p=ceph.git tools/ceph-dencoder: introduce add_crc32c command to append crc32 for the 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 --- diff --git a/src/tools/ceph-dencoder/ceph_dencoder.cc b/src/tools/ceph-dencoder/ceph_dencoder.cc index a278e08629f..24640f9b51d 100644 --- a/src/tools/ceph-dencoder/ceph_dencoder.cc +++ b/src/tools/ceph-dencoder/ceph_dencoder.cc @@ -49,6 +49,7 @@ void usage(ostream &out) out << " skip skip 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 '" << std::endl;