Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
ipc
libmultiprocess
include
mp
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
14
namespace
mp
{
15
template
<
typename
T,
typename
U>
16
concept
IsSpanOf
=
17
std::convertible_to<T, std::span<const U>> &&
18
std::constructible_from<T, const U*, const U*>;
19
20
template
<
typename
T>
21
concept
IsByteSpan
=
22
IsSpanOf<T, std::byte>
||
23
IsSpanOf<T, char>
||
24
IsSpanOf<T, unsigned char>
||
25
IsSpanOf<T, signed char>
;
26
31
template
<
typename
LocalType,
typename
Value,
typename
Output>
32
void
CustomBuildField
(
TypeList<LocalType>
,
Priority<2>
,
InvokeContext
& invoke_context, Value&& value, Output&& output)
33
requires
(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
40
template
<
typename
LocalType,
typename
Input,
typename
ReadDest>
41
decltype
(
auto
)
CustomReadField
(
TypeList<LocalType>
,
Priority<2>
,
InvokeContext
& invoke_context, Input&& input, ReadDest&& read_dest)
42
requires
(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
ByteType
Definition
common.h:16
mp::IsByteSpan
Definition
type-data.h:21
mp::IsSpanOf
Definition
type-data.h:16
util.h
mp
Functions to serialize / deserialize common bitcoin types.
Definition
common-types.h:58
mp::CustomReadField
decltype(auto) CustomReadField(TypeList< LocalType >, Priority< 1 >, InvokeContext &invoke_context, Input &&input, ReadDest &&read_dest)
Definition
common-types.h:84
mp::CustomBuildField
void CustomBuildField(TypeList< LocalType >, Priority< 1 >, InvokeContext &invoke_context, Value &&value, Output &&output)
Definition
common-types.h:64
mp::InvokeContext
Definition
proxy-io.h:33
mp::Priority
Definition
util.h:115
mp::TypeList
Generic utility functions used by capnp code.
Definition
util.h:39
Generated on
for Bitcoin Core by
1.18.0