]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common: fix fmtlib v8 handling of OpSchedItem
authorRonen Friedman <rfriedma@redhat.com>
Thu, 13 Jul 2023 13:57:08 +0000 (08:57 -0500)
committerRonen Friedman <rfriedma@redhat.com>
Thu, 13 Jul 2023 14:24:00 +0000 (09:24 -0500)
by providing a formatter for Message & derivatives
that is implemented directly (not using operator<<).

This is only a first step, to be followed by an
implementation of a usable print() function for Message & co.

Signed-off-by: Ronen Friedman <rfriedma@redhat.com>
src/msg/Message.h

index c54bba7b66548f25698427459f862d34a6e5b503..7af72a8d74ce4e8ff3eb94257a1c3c131496f108 100644 (file)
@@ -591,8 +591,19 @@ MURef<T> make_message(Args&&... args) {
 }
 }
 
-#if FMT_VERSION >= 90000
-template <std::derived_from<Message> M> struct fmt::formatter<M> : fmt::ostream_formatter {};
-#endif
+template <std::derived_from<Message> M>
+struct fmt::formatter<M> {
+  constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
+  template <typename FormatContext>
+  auto format(const M& m, FormatContext& ctx) const {
+    std::ostringstream oss;
+    m.print(oss);
+    if (auto ver = m.get_header().version; ver) {
+      return fmt::format_to(ctx.out(), "{} v{}", oss.str(), ver);
+    } else {
+      return fmt::format_to(ctx.out(), "{}", oss.str());
+    }
+  }
+};
 
 #endif