Coverage Report

Created: 2026-05-06 07:53

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
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
26
//! Generic ::capnp::Data field builder for any C++ type that can be converted
27
//! to a span of bytes, like std::vector<char> or std::array<uint8_t>, or custom
28
//! blob types like uint256 or PKHash with data() and size() methods pointing to
29
//! bytes.
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
4
{
34
4
    auto data = std::span{value};
35
4
    auto result = output.init(data.size());
36
4
    memcpy(result.begin(), data.data(), data.size());
37
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
33
1
{
34
1
    auto data = std::span{value};
35
1
    auto result = output.init(data.size());
36
1
    memcpy(result.begin(), data.data(), data.size());
37
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
33
1
{
34
1
    auto data = std::span{value};
35
1
    auto result = output.init(data.size());
36
1
    memcpy(result.begin(), data.data(), data.size());
37
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
33
1
{
34
1
    auto data = std::span{value};
35
1
    auto result = output.init(data.size());
36
1
    memcpy(result.begin(), data.data(), data.size());
37
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
33
1
{
34
1
    auto data = std::span{value};
35
1
    auto result = output.init(data.size());
36
1
    memcpy(result.begin(), data.data(), data.size());
37
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>
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
4
{
43
4
    using ByteType = decltype(std::span{std::declval<LocalType>().begin(), std::declval<LocalType>().end()})::element_type;
44
4
    const kj::byte *begin{input.get().begin()}, *end{input.get().end()};
45
4
    return read_dest.construct(reinterpret_cast<const ByteType*>(begin), reinterpret_cast<const ByteType*>(end));
46
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
42
1
{
43
1
    using ByteType = decltype(std::span{std::declval<LocalType>().begin(), std::declval<LocalType>().end()})::element_type;
44
1
    const kj::byte *begin{input.get().begin()}, *end{input.get().end()};
45
1
    return read_dest.construct(reinterpret_cast<const ByteType*>(begin), reinterpret_cast<const ByteType*>(end));
46
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
42
1
{
43
1
    using ByteType = decltype(std::span{std::declval<LocalType>().begin(), std::declval<LocalType>().end()})::element_type;
44
1
    const kj::byte *begin{input.get().begin()}, *end{input.get().end()};
45
1
    return read_dest.construct(reinterpret_cast<const ByteType*>(begin), reinterpret_cast<const ByteType*>(end));
46
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
42
1
{
43
1
    using ByteType = decltype(std::span{std::declval<LocalType>().begin(), std::declval<LocalType>().end()})::element_type;
44
1
    const kj::byte *begin{input.get().begin()}, *end{input.get().end()};
45
1
    return read_dest.construct(reinterpret_cast<const ByteType*>(begin), reinterpret_cast<const ByteType*>(end));
46
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
42
1
{
43
1
    using ByteType = decltype(std::span{std::declval<LocalType>().begin(), std::declval<LocalType>().end()})::element_type;
44
1
    const kj::byte *begin{input.get().begin()}, *end{input.get().end()};
45
1
    return read_dest.construct(reinterpret_cast<const ByteType*>(begin), reinterpret_cast<const ByteType*>(end));
46
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>
47
} // namespace mp
48
49
#endif // MP_PROXY_TYPE_DATA_H