Bitcoin Core 29.99.0
P2P Digital Currency
type-vector.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_VECTOR_H
6#define MP_PROXY_TYPE_VECTOR_H
7
8#include <mp/proxy-types.h>
9#include <mp/util.h>
10
11namespace mp {
12template <typename LocalType, typename Value, typename Output>
13void CustomBuildField(TypeList<std::vector<LocalType>>,
15 InvokeContext& invoke_context,
16 Value&& value,
17 Output&& output)
18{
19 // FIXME dedup with set handler below
20 auto list = output.init(value.size());
21 size_t i = 0;
22 for (auto it = value.begin(); it != value.end(); ++it, ++i) {
23 BuildField(TypeList<LocalType>(), invoke_context, ListOutput<typename decltype(list)::Builds>(list, i), *it);
24 }
25}
26
27inline static bool BuildPrimitive(InvokeContext& invoke_context, std::vector<bool>::const_reference value, TypeList<bool>)
28{
29 return value;
30}
31
32template <typename LocalType, typename Input, typename ReadDest>
33decltype(auto) CustomReadField(TypeList<std::vector<LocalType>>,
35 InvokeContext& invoke_context,
36 Input&& input,
37 ReadDest&& read_dest)
38{
39 return read_dest.update([&](auto& value) {
40 auto data = input.get();
41 value.clear();
42 value.reserve(data.size());
43 for (auto item : data) {
44 ReadField(TypeList<LocalType>(), invoke_context, Make<ValueField>(item),
45 ReadDestEmplace(TypeList<LocalType>(), [&](auto&&... args) -> auto& {
46 value.emplace_back(std::forward<decltype(args)>(args)...);
47 return value.back();
48 }));
49 }
50 });
51}
52
53template <typename Input, typename ReadDest>
54decltype(auto) CustomReadField(TypeList<std::vector<bool>>,
56 InvokeContext& invoke_context,
57 Input&& input,
58 ReadDest&& read_dest)
59{
60 return read_dest.update([&](auto& value) {
61 auto data = input.get();
62 value.clear();
63 value.reserve(data.size());
64 for (auto item : data) {
65 value.push_back(ReadField(TypeList<bool>(), invoke_context, Make<ValueField>(item), ReadDestTemp<bool>()));
66 }
67 });
68}
69} // namespace mp
70
71#endif // MP_PROXY_TYPE_VECTOR_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
LocalType BuildPrimitive(InvokeContext &invoke_context, const Value &value, TypeList< LocalType >, typename std::enable_if< std::is_enum< Value >::value >::type *enable=nullptr)
Definition: type-number.h:12
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