Bitcoin Core 29.99.0
P2P Digital Currency
type-map.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_MAP_H
6#define MP_PROXY_TYPE_MAP_H
7
8#include <mp/proxy-types.h>
9#include <mp/type-pair.h>
10#include <mp/util.h>
11
12namespace mp {
13template <typename KeyLocalType, typename ValueLocalType, typename Value, typename Output>
14void CustomBuildField(TypeList<std::map<KeyLocalType, ValueLocalType>>,
16 InvokeContext& invoke_context,
17 Value&& value,
18 Output&& output)
19{
20 // FIXME dededup with vector handler above
21 auto list = output.init(value.size());
22 size_t i = 0;
23 for (const auto& elem : value) {
24 BuildField(TypeList<std::pair<KeyLocalType, ValueLocalType>>(), invoke_context,
25 ListOutput<typename decltype(list)::Builds>(list, i), elem);
26 ++i;
27 }
28}
29
30template <typename KeyLocalType, typename ValueLocalType, typename Input, typename ReadDest>
31decltype(auto) CustomReadField(TypeList<std::map<KeyLocalType, ValueLocalType>>,
33 InvokeContext& invoke_context,
34 Input&& input,
35 ReadDest&& read_dest)
36{
37 return read_dest.update([&](auto& value) {
38 auto data = input.get();
39 value.clear();
40 for (auto item : data) {
41 ReadField(TypeList<std::pair<const KeyLocalType, ValueLocalType>>(), invoke_context,
42 Make<ValueField>(item),
44 TypeList<std::pair<const KeyLocalType, ValueLocalType>>(), [&](auto&&... args) -> auto& {
45 return *value.emplace(std::forward<decltype(args)>(args)...).first;
46 }));
47 }
48 });
49}
50} // namespace mp
51
52#endif // MP_PROXY_TYPE_MAP_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
Generic utility functions used by capnp code.
Definition: util.h:33