Skip to content

Commit 5417716

Browse files
committed
moveonly: add mp/type-char.h
1 parent 83c444d commit 5417716

File tree

3 files changed

+37
-24
lines changed

3 files changed

+37
-24
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ set(MP_PUBLIC_HEADERS
4545
include/mp/proxy-io.h
4646
include/mp/proxy-types.h
4747
include/mp/proxy.h
48+
include/mp/type-char.h
4849
include/mp/type-context.h
4950
include/mp/type-map.h
5051
include/mp/type-number.h

include/mp/proxy-types.h

-24
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,6 @@ struct ReadDestUpdate
141141
Value& m_value;
142142
};
143143

144-
template <size_t size, typename Input, typename ReadDest>
145-
decltype(auto) CustomReadField(TypeList<unsigned char[size]>,
146-
Priority<1>,
147-
InvokeContext& invoke_context,
148-
Input&& input,
149-
ReadDest&& read_dest)
150-
{
151-
return read_dest.update([&](auto& value) {
152-
auto data = input.get();
153-
memcpy(value, data.begin(), size);
154-
});
155-
}
156-
157144
template <typename Interface, typename Impl>
158145
std::unique_ptr<Impl> MakeProxyClient(InvokeContext& context, typename Interface::Client&& client)
159146
{
@@ -306,17 +293,6 @@ void CustomBuildField(TypeList<LocalType>, Priority<1>, InvokeContext& invoke_co
306293
{
307294
}
308295

309-
template <typename Output, size_t size>
310-
void CustomBuildField(TypeList<const unsigned char*>,
311-
Priority<3>,
312-
InvokeContext& invoke_context,
313-
const unsigned char (&value)[size],
314-
Output&& output)
315-
{
316-
auto result = output.init(size);
317-
memcpy(result.begin(), value, size);
318-
}
319-
320296
template <typename... Values>
321297
bool CustomHasValue(InvokeContext& invoke_context, Values&&... value)
322298
{

include/mp/type-char.h

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2025 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_CHAR_H
6+
#define MP_PROXY_TYPE_CHAR_H
7+
8+
#include <mp/util.h>
9+
10+
namespace mp {
11+
template <typename Output, size_t size>
12+
void CustomBuildField(TypeList<const unsigned char*>,
13+
Priority<3>,
14+
InvokeContext& invoke_context,
15+
const unsigned char (&value)[size],
16+
Output&& output)
17+
{
18+
auto result = output.init(size);
19+
memcpy(result.begin(), value, size);
20+
}
21+
22+
template <size_t size, typename Input, typename ReadDest>
23+
decltype(auto) CustomReadField(TypeList<unsigned char[size]>,
24+
Priority<1>,
25+
InvokeContext& invoke_context,
26+
Input&& input,
27+
ReadDest&& read_dest)
28+
{
29+
return read_dest.update([&](auto& value) {
30+
auto data = input.get();
31+
memcpy(value, data.begin(), size);
32+
});
33+
}
34+
} // namespace mp
35+
36+
#endif // MP_PROXY_TYPE_CHAR_H

0 commit comments

Comments
 (0)