Bitcoin Core 29.99.0
P2P Digital Currency
type-optional.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_OPTIONAL_H
6#define MP_PROXY_TYPE_OPTIONAL_H
7
8#include <mp/util.h>
9
10namespace mp {
11template <typename LocalType, typename Value, typename Output>
12void CustomBuildField(TypeList<std::optional<LocalType>>,
14 InvokeContext& invoke_context,
15 Value&& value,
16 Output&& output)
17{
18 if (value) {
19 output.setHas();
20 // FIXME: should std::move value if destvalue is rref?
21 BuildField(TypeList<LocalType>(), invoke_context, output, *value);
22 }
23}
24
25template <typename LocalType, typename Input, typename ReadDest>
26decltype(auto) CustomReadField(TypeList<std::optional<LocalType>>,
28 InvokeContext& invoke_context,
29 Input&& input,
30 ReadDest&& read_dest)
31{
32 return read_dest.update([&](auto& value) {
33 if (!input.has()) {
34 value.reset();
35 } else if (value) {
36 ReadField(TypeList<LocalType>(), invoke_context, input, ReadDestUpdate(*value));
37 } else {
38 ReadField(TypeList<LocalType>(), invoke_context, input,
39 ReadDestEmplace(TypeList<LocalType>(), [&](auto&&... args) -> auto& {
40 value.emplace(std::forward<decltype(args)>(args)...);
41 return *value;
42 }));
43 }
44 });
45}
46} // namespace mp
47
48#endif // MP_PROXY_TYPE_OPTIONAL_H
ArgsManager & args
Definition: bitcoind.cpp:277
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
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
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
Function parameter type for prioritizing overloaded function calls that would otherwise be ambiguous.
Definition: util.h:109
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