Bitcoin Core  31.0.0
P2P Digital Currency
foo-types.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_TEST_FOO_TYPES_H
6 #define MP_TEST_FOO_TYPES_H
7 
8 #include <mp/proxy.h>
9 #include <mp/proxy-types.h>
10 
11 // IWYU pragma: begin_exports
12 #include <capnp/common.h>
13 #include <cstddef>
14 #include <mp/test/foo.capnp.h>
15 #include <mp/type-context.h>
16 #include <mp/type-data.h>
17 #include <mp/type-decay.h>
18 #include <mp/type-function.h>
19 #include <mp/type-interface.h>
20 #include <mp/type-map.h>
21 #include <mp/type-message.h>
22 #include <mp/type-number.h>
23 #include <mp/type-pointer.h>
24 #include <mp/type-set.h>
25 #include <mp/type-string.h>
26 #include <mp/type-struct.h>
27 #include <mp/type-threadmap.h>
28 #include <mp/type-vector.h>
29 #include <string>
30 #include <type_traits>
31 // IWYU pragma: end_exports
32 
33 namespace mp {
34 namespace test {
35 namespace messages {
36 struct ExtendedCallback; // IWYU pragma: export
37 struct FooCallback; // IWYU pragma: export
38 struct FooFn; // IWYU pragma: export
39 struct FooInterface; // IWYU pragma: export
40 } // namespace messages
41 
42 template <typename Output>
43 void CustomBuildField(TypeList<FooCustom>, Priority<1>, InvokeContext& invoke_context, const FooCustom& value, Output&& output)
44 {
45  BuildField(TypeList<std::string>(), invoke_context, output, value.v1);
46  output.setV2(value.v2);
47 }
48 
49 template <typename Input, typename ReadDest>
50 decltype(auto) CustomReadField(TypeList<FooCustom>, Priority<1>, InvokeContext& invoke_context, Input&& input, ReadDest&& read_dest)
51 {
52  messages::FooCustom::Reader custom = input.get();
53  return read_dest.update([&](FooCustom& value) {
54  value.v1 = ReadField(TypeList<std::string>(), invoke_context, mp::Make<mp::ValueField>(custom.getV1()), ReadDestTemp<std::string>());
55  value.v2 = custom.getV2();
56  });
57 }
58 
59 } // namespace test
60 
61 template <typename Input>
62 bool CustomHasField(TypeList<test::FooData>, InvokeContext& invoke_context, const Input& input)
63 {
64  // Cap'n Proto C++ cannot distinguish null vs empty Data in List(Data), so
65  // interpret empty Data as null for this specific type.
66  return input.get().size() != 0;
67 }
68 
69 inline void CustomBuildMessage(InvokeContext& invoke_context,
70  const test::FooMessage& src,
71  test::messages::FooMessage::Builder&& builder)
72 {
73  builder.setMessage(src.message + " build");
74 }
75 
76 inline void CustomReadMessage(InvokeContext& invoke_context,
77  const test::messages::FooMessage::Reader& reader,
78  test::FooMessage& dest)
79 {
80  dest.message = std::string{reader.getMessage()} + " read";
81 }
82 
83 inline void CustomBuildMessage(InvokeContext& invoke_context,
84  const test::FooMutable& src,
85  test::messages::FooMutable::Builder&& builder)
86 {
87  builder.setMessage(src.message + " build");
88 }
89 
90 inline void CustomReadMessage(InvokeContext& invoke_context,
91  const test::messages::FooMutable::Reader& reader,
92  test::FooMutable& dest)
93 {
94  dest.message = std::string{reader.getMessage()} + " read";
95 }
96 
97 inline void CustomPassMessage(InvokeContext& invoke_context,
98  const test::messages::FooMutable::Reader& reader,
99  test::messages::FooMutable::Builder builder,
100  std::function<void(test::FooMutable&)>&& fn)
101 {
102  test::FooMutable mut;
103  mut.message = std::string{reader.getMessage()} + " pass";
104  fn(mut);
105  builder.setMessage(mut.message + " return");
106 }
107 } // namespace mp
108 
109 #endif // MP_TEST_FOO_TYPES_H
void CustomBuildMessage(InvokeContext &invoke_context, const test::FooMessage &src, test::messages::FooMessage::Builder &&builder)
Definition: foo-types.h:69
void CustomPassMessage(InvokeContext &invoke_context, const test::messages::FooMutable::Reader &reader, test::messages::FooMutable::Builder builder, std::function< void(test::FooMutable &)> &&fn)
Definition: foo-types.h:97
Function parameter type for prioritizing overloaded function calls that would otherwise be ambiguous...
Definition: util.h:108
std::string message
Definition: foo.h:40
bool CustomHasField(TypeList< LocalTypes... >, InvokeContext &invoke_context, const Input &input)
Return whether to read a C++ value from a Cap&#39;n Proto field.
Definition: proxy-types.h:207
Generic utility functions used by capnp code.
Definition: util.h:32
Functions to serialize / deserialize common bitcoin types.
Definition: common-types.h:57
void CustomBuildField(TypeList< FooCustom >, Priority< 1 >, InvokeContext &invoke_context, const FooCustom &value, Output &&output)
Definition: foo-types.h:43
decltype(auto) CustomReadField(TypeList< FooCustom >, Priority< 1 >, InvokeContext &invoke_context, Input &&input, ReadDest &&read_dest)
Definition: foo-types.h:50
void BuildField(TypeList< LocalTypes... >, Context &context, Output &&output, Values &&... values)
Definition: proxy-types.h:250
decltype(auto) ReadField(TypeList< LocalTypes... >, InvokeContext &invoke_context, Input &&input, Args &&... args)
Definition: proxy-types.h:213
std::string message
Definition: foo.h:45
std::string v1
Definition: foo.h:30
void CustomReadMessage(InvokeContext &invoke_context, const test::messages::FooMessage::Reader &reader, test::FooMessage &dest)
Definition: foo-types.h:76