From b37d1d71f115f6b5a0000e09c7be063994387e1a Mon Sep 17 00:00:00 2001 From: Ryan Ofsky Date: Sat, 6 Jun 2026 18:27:03 -0400 Subject: [PATCH] type-chrono: Add CustomBuildField/CustomReadField overloads for std::chrono::time_point Needed by bitcoin/bitcoin#34882 which uses NodeClock::time_point in the Node stats struct (m_last_send, m_last_recv, m_ping_start), requiring IPC serialization support for time_point types. Co-Authored-By: Claude Sonnet 4.6 --- include/mp/type-chrono.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/mp/type-chrono.h b/include/mp/type-chrono.h index d7154986..f58adddf 100644 --- a/include/mp/type-chrono.h +++ b/include/mp/type-chrono.h @@ -29,6 +29,29 @@ decltype(auto) CustomReadField(TypeList>, Pri { return read_dest.construct(input.get()); } + +//! Overload CustomBuildField and CustomReadField to serialize +//! std::chrono::time_point parameters and return values as integer tick counts. +//! The capnp field type must be an integer type with enough range to hold the +//! time_since_epoch() count for the given Duration (e.g. Int64 for nanoseconds). +template +void CustomBuildField(TypeList>, Priority<1>, InvokeContext& invoke_context, + Value&& value, Output&& output) +{ + using Rep = typename Duration::rep; + static_assert(std::numeric_limits::lowest() <= std::numeric_limits::lowest(), + "capnp type does not have enough range to hold lowest std::chrono::time_point value"); + static_assert(std::numeric_limits::max() >= std::numeric_limits::max(), + "capnp type does not have enough range to hold highest std::chrono::time_point value"); + output.set(value.time_since_epoch().count()); +} + +template +decltype(auto) CustomReadField(TypeList>, Priority<1>, + InvokeContext& invoke_context, Input&& input, ReadDest&& read_dest) +{ + return read_dest.construct(std::chrono::time_point{Duration{input.get()}}); +} } // namespace mp #endif // MP_PROXY_TYPE_CHRONO_H