Bitcoin Core 29.99.0
P2P Digital Currency
type-struct.h
Go to the documentation of this file.
1// Copyright (c) 2025 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef MP_PROXY_TYPE_STRUCT_H
6#define MP_PROXY_TYPE_STRUCT_H
7
8#include <mp/util.h>
9
10namespace mp {
11template <size_t index, typename LocalType, typename Value, typename Output>
13 InvokeContext& invoke_context,
14 Output&& output,
15 Value&& value,
16 typename std::enable_if < index<ProxyType<LocalType>::fields>::type * enable = nullptr)
17{
18 using Index = std::integral_constant<size_t, index>;
19 using Struct = typename ProxyType<LocalType>::Struct;
20 using Accessor = typename std::tuple_element<index, typename ProxyStruct<Struct>::Accessors>::type;
21 auto&& field_output = Make<StructField, Accessor>(output);
22 auto&& field_value = value.*ProxyType<LocalType>::get(Index());
23 BuildField(TypeList<Decay<decltype(field_value)>>(), invoke_context, field_output, field_value);
24 BuildOne<index + 1>(param, invoke_context, output, value);
25}
26
27template <size_t index, typename LocalType, typename Value, typename Output>
29 InvokeContext& invoke_context,
30 Output&& output,
31 Value&& value,
32 typename std::enable_if<index == ProxyType<LocalType>::fields>::type* enable = nullptr)
33{
34}
35
36template <typename LocalType, typename Value, typename Output>
39 InvokeContext& invoke_context,
40 Value&& value,
41 Output&& output,
42 typename ProxyType<LocalType>::Struct* enable = nullptr)
43{
44 BuildOne<0>(local_type, invoke_context, output.init(), value);
45}
46
47template <size_t index, typename LocalType, typename Input, typename Value>
49 InvokeContext& invoke_context,
50 Input&& input,
51 Value&& value,
52 typename std::enable_if<index != ProxyType<LocalType>::fields>::type* enable = nullptr)
53{
54 using Index = std::integral_constant<size_t, index>;
55 using Struct = typename ProxyType<LocalType>::Struct;
56 using Accessor = typename std::tuple_element<index, typename ProxyStruct<Struct>::Accessors>::type;
57 const auto& struc = input.get();
58 auto&& field_value = value.*ProxyType<LocalType>::get(Index());
59 ReadField(TypeList<RemoveCvRef<decltype(field_value)>>(), invoke_context, Make<StructField, Accessor>(struc),
60 ReadDestUpdate(field_value));
61 ReadOne<index + 1>(param, invoke_context, input, value);
62}
63
64template <size_t index, typename LocalType, typename Input, typename Value>
66 InvokeContext& invoke_context,
67 Input& input,
68 Value& value,
69 typename std::enable_if<index == ProxyType<LocalType>::fields>::type* enable = nullptr)
70{
71}
72
73template <typename LocalType, typename Input, typename ReadDest>
76 InvokeContext& invoke_context,
77 Input&& input,
78 ReadDest&& read_dest,
79 typename ProxyType<LocalType>::Struct* enable = nullptr)
80{
81 return read_dest.update([&](auto& value) { ReadOne<0>(param, invoke_context, input, value); });
82}
83} // namespace mp
84
85#endif // MP_PROXY_TYPE_STRUCT_H
Functions to serialize / deserialize common bitcoin types.
Definition: common-types.h:57
void BuildField(TypeList< LocalTypes... >, Context &context, Output &&output, Values &&... values)
Definition: proxy-types.h:175
void BuildOne(TypeList< LocalType > param, InvokeContext &invoke_context, Output &&output, Value &&value, typename std::enable_if< index< ProxyType< LocalType >::fields >::type *enable=nullptr)
Definition: type-struct.h:12
decltype(auto) CustomReadField(TypeList< LocalType >, Priority< 1 >, InvokeContext &invoke_context, Input &&input, ReadDest &&read_dest)
Overload multiprocess library's CustomReadField hook to allow any object with an Unserialize method t...
Definition: common-types.h:83
decltype(auto) ReadField(TypeList< LocalTypes... >, Args &&... args)
Definition: proxy-types.h:145
std::decay_t< T > Decay
Type helper abbreviating std::decay.
Definition: util.h:86
std::remove_cv_t< std::remove_reference_t< T > > RemoveCvRef
Substitutue for std::remove_cvref_t.
Definition: util.h:82
void CustomBuildField(TypeList< LocalType >, Priority< 1 >, InvokeContext &invoke_context, Value &&value, Output &&output)
Overload multiprocess library's CustomBuildField hook to allow any serializable object to be stored i...
Definition: common-types.h:63
void ReadOne(TypeList< LocalType > param, InvokeContext &invoke_context, Input &&input, Value &&value, typename std::enable_if< index !=ProxyType< LocalType >::fields >::type *enable=nullptr)
Definition: type-struct.h:48
Accessor type holding flags that determine how to access a message field.
Definition: proxy.h:277
Function parameter type for prioritizing overloaded function calls that would otherwise be ambiguous.
Definition: util.h:109
Mapping from local c++ type to capnp type and traits (specializations are generated by proxy-codegen....
Definition: proxy.h:37
Destination parameter type that can be passed to ReadField function as an alternative to ReadDestEmpl...
Definition: proxy-types.h:120
Generic utility functions used by capnp code.
Definition: util.h:33