45#if defined(INLINE_VTABLE)
47#define self_arg(type) const type & this_,
48#define self_app(value) value,
49#define prototype(ret, name, args) const ret (*name) args
50#define definition(ret, name, args) static ret name args
54#define self_app(value)
55#define prototype(ret, name, args) virtual ret name args const = 0
56#define definition(ret, name, args) ret name args const override
59#define LITERAL_COMPTIME_STRING(name, value) const decltype(CompTimeString{value}) name{value}
63template<std::
integral I>
69template<
size_t extent>
74template<
typename... Ts>
75struct Type<std::tuple<Ts...>>
79 (..., Type<Ts>::python) +
94template<
typename Ret,
typename... Args>
98 using Fun = Ret (*)(Args...);
99 using ArgsTup = std::tuple<Args...>;
105 std::array<
const char *,
sizeof...(Args)> argNames_,
108#if defined(INLINE_VTABLE)
114 .schema =
reinterpret_cast<decltype(NonTemplatedCall::schema)
>(
reinterpret_cast<void *
>(&schema)),
115 .call =
reinterpret_cast<decltype(NonTemplatedCall::call)
>(
reinterpret_cast<void *
>(&call)),
127 subseq.encode(std::string_view(self.name)) &&
128 subseq.encode(std::string_view(self.doc)) &&
129 subseq.encode(
static_cast<std::string_view
>(Type<Return>::python)) &&
130 [&]<
size_t... Idx>(std::index_sequence<Idx...>)
134 subseq.encode(std::string_view(self.argNames[Idx])) &&
135 subseq.encode(
static_cast<std::string_view
>(
136 Type<std::tuple_element_t<Idx, ArgsTup>>::python))
140 }(std::index_sequence_for<Args...>{}) &&
141 subseq.as_expected();
144 definition(
bool, call, (self_arg(Call) std::span<uint8_t> & args, std::span<uint8_t> & ret))
146 if (self.ptr ==
nullptr)
152 for (
const auto byte : args)
169 std::array<
const char *,
sizeof...(Args)> argNames;
173template<
typename... Calls>
177 Rpc(Calls && ... calls_)
178 : tuple{std::forward<Calls>(calls_)...},
180 [&]<
size_t... Idx>(std::index_sequence<Idx...>)
182 return std::array<std::reference_wrapper<NonTemplatedCall>,
sizeof...(Calls)>{
183 (std::reference_wrapper<NonTemplatedCall>{
186 }(std::index_sequence_for<Calls...>{})
190 bool schema(std::span<uint8_t> & buf)
const
193 for (
auto & c : calls)
195 auto &
call = c.get();
196 if (!
call.schema(self_app(
call) seq))
202 return seq.as_expected();
207 bool call(
size_t n, std::span<uint8_t> & args, std::span<uint8_t> & ret)
const
213 else if (n <
sizeof...(Calls) + 1)
215 auto &
call = calls[n-1].get();
216 return call.call(self_app(
call) args, ret);
225 std::tuple<Calls...> tuple;
226 std::array<std::reference_wrapper<NonTemplatedCall>,
sizeof...(Calls)> calls;
Encoding for structured data (numbers, strings, bytes, arrays and maps). Also supports custom tags.
prototype(bool, call,(self_arg(NonTemplatedCall) std::span< uint8_t > &args, std::span< uint8_t > &ret))
prototype(bool, schema,(self_arg(NonTemplatedCall) Cbor::Sequence< Cbor::Major::Array > &seq))
Encodes the schema for the function into seq.
bool schema(std::span< uint8_t > &buf) const
Encode the schema for all the RPC functions onto buf.
Definition rpc.hpp:190
bool call(size_t n, std::span< uint8_t > &args, std::span< uint8_t > &ret) const
Definition rpc.hpp:207
Compile-time string manipulation.
#define debugf(...)
Definition ndebug.hpp:23
#define END
Terminator of log message at the end.
Definition ndebug.hpp:50
#define LOGLEVEL_ARGS
Definition ndebug.hpp:28
#define DEBUG
Debug levels at the start of debugf.
Definition ndebug.hpp:33
Parametrized CBOR interface.
Definition cbor.hpp:400
Allows materialising void values using a placeholder.
Definition cbor.hpp:312
Definition comptime_str.hpp:23