diff --git a/src/serialize.h b/src/serialize.h index a1cce78451..89a9f32240 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -520,6 +520,29 @@ struct CompactSizeFormatter } }; +template +struct ChronoFormatter { + template + void Unser(Stream& s, Tp& tp) + { + U u; + s >> u; + // Lossy deserialization does not make sense, so force Wnarrowing + tp = Tp{typename Tp::duration{typename Tp::duration::rep{u}}}; + } + template + void Ser(Stream& s, Tp tp) + { + if constexpr (LOSSY) { + s << U(tp.time_since_epoch().count()); + } else { + s << U{tp.time_since_epoch().count()}; + } + } +}; +template +using LossyChronoFormatter = ChronoFormatter; + class CompactSizeWriter { protected: