t = Clock::from_timespec(ts);
}
+template<typename Rep, typename Period,
+ typename std::enable_if_t<std::is_integral_v<Rep>>* = nullptr>
+void encode(const std::chrono::duration<Rep, Period>& d,
+ ceph::bufferlist &bl) {
+ using namespace std::chrono;
+ uint32_t s = duration_cast<seconds>(d).count();
+ uint32_t ns = (duration_cast<nanoseconds>(d) % seconds(1)).count();
+ encode(s, bl);
+ encode(ns, bl);
+}
+
+template<typename Rep, typename Period,
+ typename std::enable_if_t<std::is_integral_v<Rep>>* = nullptr>
+void decode(std::chrono::duration<Rep, Period>& d,
+ bufferlist::iterator& p) {
+ uint32_t s;
+ uint32_t ns;
+ decode(s, p);
+ decode(ns, p);
+ d = std::chrono::seconds(s) + std::chrono::nanoseconds(ns);
+}
+
// -----------------------------
// STL container types
using coarse_real_time_wrapper = time_point_wrapper<ceph::coarse_real_clock>;
WRITE_CLASS_ENCODER(coarse_real_time_wrapper)
+// wrapper for ceph::timespan that implements the dencoder interface
+class timespan_wrapper {
+ ceph::timespan d;
+ public:
+ timespan_wrapper() = default;
+ explicit timespan_wrapper(const ceph::timespan& d) : d(d) {}
+
+ void encode(bufferlist& bl) const {
+ using ceph::encode;
+ encode(d, bl);
+ }
+ void decode(bufferlist::iterator &p) {
+ using ceph::decode;
+ decode(d, p);
+ }
+ void dump(Formatter* f) {
+ f->dump_int("timespan", d.count());
+ }
+ static void generate_test_instances(std::list<timespan_wrapper*>& ls) {
+ constexpr std::chrono::seconds d{7377}; // marathon world record (2:02:57)
+ ls.push_back(new timespan_wrapper(d));
+ }
+};
+WRITE_CLASS_ENCODER(timespan_wrapper)
+
#endif