Bitcoin Core
31.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
13
namespace
mp
{
14
template
<
typename
T,
typename
U>
15
concept
IsSpanOf
=
16
std::convertible_to<T, std::span<const U>> &&
17
std::constructible_from<T, const U*, const U*>;
18
19
template
<
typename
T>
20
concept
IsByteSpan
=
21
IsSpanOf<T, std::byte>
||
22
IsSpanOf<T, char>
||
23
IsSpanOf<T, unsigned char>
||
24
IsSpanOf<T, signed char>
;
25
30
template
<
typename
LocalType,
typename
Value,
typename
Output>
31
void
CustomBuildField
(
TypeList<LocalType>
,
Priority<2>
,
InvokeContext
& invoke_context, Value&& value, Output&& output)
32
requires
(std::is_same_v<
decltype
(output.get()), ::capnp::Data::Builder> &&
IsByteSpan<LocalType>
)
33
{
34
auto
data = std::span{value};
35
auto
result = output.init(data.size());
36
memcpy(result.begin(), data.data(), data.size());
37
}
38
39
template
<
typename
LocalType,
typename
Input,
typename
ReadDest>
40
decltype
(
auto
)
CustomReadField
(
TypeList<LocalType>
,
Priority<2>
,
InvokeContext
& invoke_context, Input&& input, ReadDest&& read_dest)
41
requires
(std::is_same_v<
decltype
(input.get()), ::capnp::Data::Reader> &&
IsByteSpan<LocalType>
)
42
{
43
using
ByteType
=
decltype
(std::span{std::declval<LocalType>().begin(), std::declval<LocalType>().end()})::element_type;
44
const
kj::byte *begin{input.get().begin()}, *end{input.get().end()};
45
return
read_dest.construct(
reinterpret_cast<
const
ByteType
*
>
(begin),
reinterpret_cast<
const
ByteType
*
>
(end));
46
}
47
}
// namespace mp
48
49
#endif
// MP_PROXY_TYPE_DATA_H
ByteType
Definition
common.h:16
mp::IsByteSpan
Definition
type-data.h:20
mp::IsSpanOf
Definition
type-data.h:15
util.h
mp
Functions to serialize / deserialize common bitcoin types.
Definition
common-types.h:57
mp::CustomReadField
decltype(auto) CustomReadField(TypeList< LocalType >, Priority< 1 >, InvokeContext &invoke_context, Input &&input, ReadDest &&read_dest)
Definition
common-types.h:83
mp::CustomBuildField
void CustomBuildField(TypeList< LocalType >, Priority< 1 >, InvokeContext &invoke_context, Value &&value, Output &&output)
Definition
common-types.h:63
mp::InvokeContext
Definition
proxy-io.h:30
mp::Priority
Definition
util.h:109
mp::TypeList
Generic utility functions used by capnp code.
Definition
util.h:33
Generated on
for Bitcoin Core by
1.17.0