Bitcoin Core 31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
type-vector.h
Go to the documentation of this file.
1// Copyright (c) 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>>,
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>>,
36 Input&& input,
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) {
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>>,
57 Input&& input,
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) {
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.
void BuildField(TypeList< LocalTypes... >, Context &context, Output &&output, Values &&... values)
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...
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... >, InvokeContext &invoke_context, Input &&input, Args &&... args)
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...
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
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition time.h:73