Coverage Report

Created: 2026-08-05 14:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/tmp/bitcoin/src/ipc/libmultiprocess/include/mp/type-data.h
Line
Count
Source
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
27
//! Generic ::capnp::Data field builder for any C++ type that can be converted
28
//! to a span of bytes, like std::vector<char> or std::array<uint8_t>, or custom
29
//! blob types like uint256 or PKHash with data() and size() methods pointing to
30
//! bytes.
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
4
{
35
4
    auto data = std::span{value};
36
4
    auto result = output.init(data.size());
37
4
    std::ranges::copy(data, result.begin());
38
4
}
void mp::CustomBuildField<std::vector<char, std::allocator<char>>, std::vector<char, std::allocator<char>>, mp::StructField<mp::Accessor<mp::ipc_test_fields::Arg, 17>, capnp::Request<gen::FooInterface::PassVectorCharParams, gen::FooInterface::PassVectorCharResults>>>(mp::TypeList<std::vector<char, std::allocator<char>>>, mp::Priority<2>, mp::InvokeContext&, std::vector<char, std::allocator<char>>&&, mp::StructField<mp::Accessor<mp::ipc_test_fields::Arg, 17>, capnp::Request<gen::FooInterface::PassVectorCharParams, gen::FooInterface::PassVectorCharResults>>&&) requires std::is_same_v<decltype(fp3.get()), capnp::Data::Builder> && IsByteSpan<std::vector<char, std::allocator<char>>>
Line
Count
Source
34
1
{
35
1
    auto data = std::span{value};
36
1
    auto result = output.init(data.size());
37
1
    std::ranges::copy(data, result.begin());
38
1
}
void mp::CustomBuildField<CScript, CScript, mp::StructField<mp::Accessor<mp::ipc_test_fields::Arg, 17>, capnp::Request<gen::FooInterface::PassScriptParams, gen::FooInterface::PassScriptResults>>>(mp::TypeList<CScript>, mp::Priority<2>, mp::InvokeContext&, CScript&&, mp::StructField<mp::Accessor<mp::ipc_test_fields::Arg, 17>, capnp::Request<gen::FooInterface::PassScriptParams, gen::FooInterface::PassScriptResults>>&&) requires std::is_same_v<decltype(fp3.get()), capnp::Data::Builder> && IsByteSpan<CScript>
Line
Count
Source
34
1
{
35
1
    auto data = std::span{value};
36
1
    auto result = output.init(data.size());
37
1
    std::ranges::copy(data, result.begin());
38
1
}
void mp::CustomBuildField<std::vector<char, std::allocator<char>>, std::vector<char, std::allocator<char>>, mp::StructField<mp::Accessor<mp::ipc_test_fields::Result, 18>, gen::FooInterface::PassVectorCharResults::Builder>&>(mp::TypeList<std::vector<char, std::allocator<char>>>, mp::Priority<2>, mp::InvokeContext&, std::vector<char, std::allocator<char>>&&, mp::StructField<mp::Accessor<mp::ipc_test_fields::Result, 18>, gen::FooInterface::PassVectorCharResults::Builder>&) requires std::is_same_v<decltype(fp3.get()), capnp::Data::Builder> && IsByteSpan<std::vector<char, std::allocator<char>>>
Line
Count
Source
34
1
{
35
1
    auto data = std::span{value};
36
1
    auto result = output.init(data.size());
37
1
    std::ranges::copy(data, result.begin());
38
1
}
void mp::CustomBuildField<CScript, CScript, mp::StructField<mp::Accessor<mp::ipc_test_fields::Result, 18>, gen::FooInterface::PassScriptResults::Builder>&>(mp::TypeList<CScript>, mp::Priority<2>, mp::InvokeContext&, CScript&&, mp::StructField<mp::Accessor<mp::ipc_test_fields::Result, 18>, gen::FooInterface::PassScriptResults::Builder>&) requires std::is_same_v<decltype(fp3.get()), capnp::Data::Builder> && IsByteSpan<CScript>
Line
Count
Source
34
1
{
35
1
    auto data = std::span{value};
36
1
    auto result = output.init(data.size());
37
1
    std::ranges::copy(data, result.begin());
38
1
}
Unexecuted instantiation: void mp::CustomBuildField<CScript, CScript&, mp::StructField<mp::Accessor<mp::mining_fields::ScriptSigPrefix, 19>, ipc::capnp::messages::CoinbaseTx::Builder>&>(mp::TypeList<CScript>, mp::Priority<2>, mp::InvokeContext&, CScript&, mp::StructField<mp::Accessor<mp::mining_fields::ScriptSigPrefix, 19>, ipc::capnp::messages::CoinbaseTx::Builder>&) requires std::is_same_v<decltype(fp3.get()), capnp::Data::Builder> && IsByteSpan<CScript>
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
4
{
44
4
    using ByteType = decltype(std::span{std::declval<LocalType>().begin(), std::declval<LocalType>().end()})::element_type;
45
4
    const kj::byte *begin{input.get().begin()}, *end{input.get().end()};
46
4
    return read_dest.construct(reinterpret_cast<const ByteType*>(begin), reinterpret_cast<const ByteType*>(end));
47
4
}
decltype(auto) mp::CustomReadField<std::vector<char, std::allocator<char>>, mp::StructField<mp::Accessor<mp::ipc_test_fields::Result, 18>, capnp::Response<gen::FooInterface::PassVectorCharResults>>, mp::ReadDestUpdate<std::vector<char, std::allocator<char>>>>(mp::TypeList<std::vector<char, std::allocator<char>>>, mp::Priority<2>, mp::InvokeContext&, mp::StructField<mp::Accessor<mp::ipc_test_fields::Result, 18>, capnp::Response<gen::FooInterface::PassVectorCharResults>>&&, mp::ReadDestUpdate<std::vector<char, std::allocator<char>>>&&) requires std::is_same_v<decltype(fp2.get()), capnp::Data::Reader> && IsByteSpan<std::vector<char, std::allocator<char>>>
Line
Count
Source
43
1
{
44
1
    using ByteType = decltype(std::span{std::declval<LocalType>().begin(), std::declval<LocalType>().end()})::element_type;
45
1
    const kj::byte *begin{input.get().begin()}, *end{input.get().end()};
46
1
    return read_dest.construct(reinterpret_cast<const ByteType*>(begin), reinterpret_cast<const ByteType*>(end));
47
1
}
decltype(auto) mp::CustomReadField<CScript, mp::StructField<mp::Accessor<mp::ipc_test_fields::Result, 18>, capnp::Response<gen::FooInterface::PassScriptResults>>, mp::ReadDestUpdate<CScript>>(mp::TypeList<CScript>, mp::Priority<2>, mp::InvokeContext&, mp::StructField<mp::Accessor<mp::ipc_test_fields::Result, 18>, capnp::Response<gen::FooInterface::PassScriptResults>>&&, mp::ReadDestUpdate<CScript>&&) requires std::is_same_v<decltype(fp2.get()), capnp::Data::Reader> && IsByteSpan<CScript>
Line
Count
Source
43
1
{
44
1
    using ByteType = decltype(std::span{std::declval<LocalType>().begin(), std::declval<LocalType>().end()})::element_type;
45
1
    const kj::byte *begin{input.get().begin()}, *end{input.get().end()};
46
1
    return read_dest.construct(reinterpret_cast<const ByteType*>(begin), reinterpret_cast<const ByteType*>(end));
47
1
}
decltype(auto) mp::CustomReadField<std::vector<char, std::allocator<char>>, mp::StructField<mp::Accessor<mp::ipc_test_fields::Arg, 17>, gen::FooInterface::PassVectorCharParams::Reader const>, mp::ReadDestEmplace<std::vector<char, std::allocator<char>>, void mp::PassField<mp::Accessor<mp::ipc_test_fields::Arg, 17>, std::vector<char, std::allocator<char>>, mp::ServerInvokeContext<mp::ProxyServer<gen::FooInterface>, capnp::CallContext<gen::FooInterface::PassVectorCharParams, gen::FooInterface::PassVectorCharResults>>, mp::ServerRet<mp::Accessor<mp::ipc_test_fields::Result, 18>, mp::ServerCall> const&, mp::TypeList<>>(mp::Priority<0>, mp::TypeList<std::vector<char, std::allocator<char>>>, mp::ServerInvokeContext<mp::ProxyServer<gen::FooInterface>, capnp::CallContext<gen::FooInterface::PassVectorCharParams, gen::FooInterface::PassVectorCharResults>>&, mp::ServerRet<mp::Accessor<mp::ipc_test_fields::Result, 18>, mp::ServerCall> const&, mp::TypeList<>&&)::'lambda'(auto&&...)>>(mp::TypeList<std::vector<char, std::allocator<char>>>, mp::Priority<2>, mp::InvokeContext&, std::vector<char, std::allocator<char>>&&, mp::ServerInvokeContext<mp::ProxyServer<gen::FooInterface>, capnp::CallContext<gen::FooInterface::PassVectorCharParams, gen::FooInterface::PassVectorCharResults>>&&) requires std::is_same_v<decltype(fp2.get()), capnp::Data::Reader> && IsByteSpan<std::vector<char, std::allocator<char>>>
Line
Count
Source
43
1
{
44
1
    using ByteType = decltype(std::span{std::declval<LocalType>().begin(), std::declval<LocalType>().end()})::element_type;
45
1
    const kj::byte *begin{input.get().begin()}, *end{input.get().end()};
46
1
    return read_dest.construct(reinterpret_cast<const ByteType*>(begin), reinterpret_cast<const ByteType*>(end));
47
1
}
decltype(auto) mp::CustomReadField<CScript, mp::StructField<mp::Accessor<mp::ipc_test_fields::Arg, 17>, gen::FooInterface::PassScriptParams::Reader const>, mp::ReadDestEmplace<CScript, void mp::PassField<mp::Accessor<mp::ipc_test_fields::Arg, 17>, CScript, mp::ServerInvokeContext<mp::ProxyServer<gen::FooInterface>, capnp::CallContext<gen::FooInterface::PassScriptParams, gen::FooInterface::PassScriptResults>>, mp::ServerRet<mp::Accessor<mp::ipc_test_fields::Result, 18>, mp::ServerCall> const&, mp::TypeList<>>(mp::Priority<0>, mp::TypeList<CScript>, mp::ServerInvokeContext<mp::ProxyServer<gen::FooInterface>, capnp::CallContext<gen::FooInterface::PassScriptParams, gen::FooInterface::PassScriptResults>>&, mp::ServerRet<mp::Accessor<mp::ipc_test_fields::Result, 18>, mp::ServerCall> const&, mp::TypeList<>&&)::'lambda'(auto&&...)>>(mp::TypeList<CScript>, mp::Priority<2>, mp::InvokeContext&, CScript&&, mp::ServerInvokeContext<mp::ProxyServer<gen::FooInterface>, capnp::CallContext<gen::FooInterface::PassScriptParams, gen::FooInterface::PassScriptResults>>&&) requires std::is_same_v<decltype(fp2.get()), capnp::Data::Reader> && IsByteSpan<CScript>
Line
Count
Source
43
1
{
44
1
    using ByteType = decltype(std::span{std::declval<LocalType>().begin(), std::declval<LocalType>().end()})::element_type;
45
1
    const kj::byte *begin{input.get().begin()}, *end{input.get().end()};
46
1
    return read_dest.construct(reinterpret_cast<const ByteType*>(begin), reinterpret_cast<const ByteType*>(end));
47
1
}
Unexecuted instantiation: decltype(auto) mp::CustomReadField<CScript, mp::StructField<mp::Accessor<mp::mining_fields::ScriptSigPrefix, 19>, ipc::capnp::messages::CoinbaseTx::Reader const>, mp::ReadDestUpdate<CScript>>(mp::TypeList<CScript>, mp::Priority<2>, mp::InvokeContext&, mp::StructField<mp::Accessor<mp::mining_fields::ScriptSigPrefix, 19>, ipc::capnp::messages::CoinbaseTx::Reader const>&&, mp::ReadDestUpdate<CScript>&&) requires std::is_same_v<decltype(fp2.get()), capnp::Data::Reader> && IsByteSpan<CScript>
48
} // namespace mp
49
50
#endif // MP_PROXY_TYPE_DATA_H