Bitcoin Core 31.99.0
P2P Digital Currency
type-data.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_DATA_H
6#define MP_PROXY_TYPE_DATA_H
7
8#include <mp/util.h>
9
10#include <concepts>
11#include <span>
12#include <ranges>
13
14namespace mp {
15template <typename T, typename U>
16concept IsSpanOf =
17 std::convertible_to<T, std::span<const U>> &&
18 std::constructible_from<T, const U*, const U*>;
19
20template <typename T>
21concept IsByteSpan =
26
31template <typename LocalType, typename Value, typename Output>
32void CustomBuildField(TypeList<LocalType>, Priority<2>, InvokeContext& invoke_context, Value&& value, Output&& output)
33requires (std::is_same_v<decltype(output.get()), ::capnp::Data::Builder> && IsByteSpan<LocalType>)
34{
35 auto data = std::span{value};
36 auto result = output.init(data.size());
37 std::ranges::copy(data, result.begin());
38}
39
40template <typename LocalType, typename Input, typename ReadDest>
41decltype(auto) CustomReadField(TypeList<LocalType>, Priority<2>, InvokeContext& invoke_context, Input&& input, ReadDest&& read_dest)
42requires (std::is_same_v<decltype(input.get()), ::capnp::Data::Reader> && IsByteSpan<LocalType>)
43{
44 using ByteType = decltype(std::span{std::declval<LocalType>().begin(), std::declval<LocalType>().end()})::element_type;
45 const kj::byte *begin{input.get().begin()}, *end{input.get().end()};
46 return read_dest.construct(reinterpret_cast<const ByteType*>(begin), reinterpret_cast<const ByteType*>(end));
47}
48} // namespace mp
49
50#endif // MP_PROXY_TYPE_DATA_H
static const PrecomputedData data
Precomputed COutPoint and CCoins values.
Functions to serialize / deserialize common bitcoin types.
Definition: common-types.h:57
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
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:115
Generic utility functions used by capnp code.
Definition: util.h:39