1414
1515#include < cstddef>
1616#include < mp/proxy-types.h>
17+ #include < mp/type-chrono.h>
18+ #include < mp/type-context.h>
19+ #include < mp/type-data.h>
20+ #include < mp/type-decay.h>
21+ #include < mp/type-interface.h>
22+ #include < mp/type-message.h>
23+ #include < mp/type-number.h>
24+ #include < mp/type-optional.h>
25+ #include < mp/type-pointer.h>
26+ #include < mp/type-string.h>
27+ #include < mp/type-struct.h>
28+ #include < mp/type-threadmap.h>
29+ #include < mp/type-vector.h>
1730#include < type_traits>
1831#include < utility>
1932
@@ -94,26 +107,6 @@ requires ipc::capnp::Deserializable<LocalType>
94107 return read_dest.construct (::deserialize, wrapper);
95108}
96109
97- // ! Overload CustomBuildField and CustomReadField to serialize std::chrono
98- // ! parameters and return values as numbers.
99- template <class Rep , class Period , typename Value, typename Output>
100- void CustomBuildField (TypeList<std::chrono::duration<Rep, Period>>, Priority<1 >, InvokeContext& invoke_context, Value&& value,
101- Output&& output)
102- {
103- static_assert (std::numeric_limits<decltype (output.get ())>::lowest () <= std::numeric_limits<Rep>::lowest (),
104- " capnp type does not have enough range to hold lowest std::chrono::duration value" );
105- static_assert (std::numeric_limits<decltype (output.get ())>::max () >= std::numeric_limits<Rep>::max (),
106- " capnp type does not have enough range to hold highest std::chrono::duration value" );
107- output.set (value.count ());
108- }
109-
110- template <class Rep , class Period , typename Input, typename ReadDest>
111- decltype (auto ) CustomReadField(TypeList<std::chrono::duration<Rep, Period>>, Priority<1 >, InvokeContext& invoke_context,
112- Input&& input, ReadDest&& read_dest)
113- {
114- return read_dest.construct (input.get ());
115- }
116-
117110// ! Overload CustomBuildField and CustomReadField to serialize UniValue
118111// ! parameters and return values as JSON strings.
119112template <typename Value, typename Output>
@@ -134,32 +127,6 @@ decltype(auto) CustomReadField(TypeList<UniValue>, Priority<1>, InvokeContext& i
134127 });
135128}
136129
137- // ! Generic ::capnp::Data field builder for any C++ type that can be converted
138- // ! to a span of bytes, like std::vector<char> or std::array<uint8_t>, or custom
139- // ! blob types like uint256 or PKHash with data() and size() methods pointing to
140- // ! bytes.
141- // !
142- // ! Note: it might make sense to move this function into libmultiprocess, since
143- // ! it is fairly generic. However this would require decreasing its priority so
144- // ! it can be overridden, which would require more changes inside
145- // ! libmultiprocess to avoid conflicting with the Priority<1> CustomBuildField
146- // ! function it already provides for std::vector. Also, it might make sense to
147- // ! provide a CustomReadField counterpart to this function, which could be
148- // ! called to read C++ types that can be constructed from spans of bytes from
149- // ! ::capnp::Data fields. But so far there hasn't been a need for this.
150- template <typename LocalType, typename Value, typename Output>
151- void CustomBuildField (TypeList<LocalType>, Priority<2 >, InvokeContext& invoke_context, Value&& value, Output&& output)
152- requires
153- (std::is_same_v<decltype (output.get()), ::capnp::Data::Builder>) &&
154- (std::convertible_to<Value, std::span<const std::byte>> ||
155- std::convertible_to<Value, std::span<const char >> ||
156- std::convertible_to<Value, std::span<const unsigned char >> ||
157- std::convertible_to<Value, std::span<const signed char >>)
158- {
159- auto data = std::span{value};
160- auto result = output.init (data.size ());
161- memcpy (result.begin (), data.data (), data.size ());
162- }
163130} // namespace mp
164131
165132#endif // BITCOIN_IPC_CAPNP_COMMON_TYPES_H
0 commit comments