Clio
develop
The XRP Ledger API server.
Theme:
Default
Round
Robot
Toggle main menu visibility
Loading...
Searching...
No Matches
Processors.hpp
1
#pragma once
2
3
#include "rpc/common/Concepts.hpp"
4
#include "rpc/common/Types.hpp"
5
6
#include <boost/json/value.hpp>
7
#include <rpcspec/backends/BoostJson.hpp>
8
9
#include <utility>
10
11
namespace
rpc::impl {
12
13
template
<SomeHandler HandlerType>
14
struct
DefaultProcessor
final {
15
[[nodiscard]]
ReturnType
16
operator()(
17
HandlerType
const
& handler,
18
boost::json::value
const
& value,
19
Context
const
& ctx
20
)
const
21
{
22
using
boost::json::value_from;
23
24
static_assert
(
25
SomeHandlerWithTypedInput<HandlerType>
or
SomeHandlerWithoutInput<HandlerType>
,
26
"handler matches none of the branches below"
27
);
28
29
if
constexpr
(
SomeHandlerWithTypedInput<HandlerType>
) {
30
auto
input = HandlerType::parseInput(value, ctx.
apiVersion
);
31
auto
warnings = rpc::spec::toJsonArray(HandlerType::spec(ctx.
apiVersion
).check(value));
32
33
if
(not input.has_value())
34
return
ReturnType
{
Error
{std::move(input).error()}, std::move(warnings)};
35
36
auto
ret = handler.process(*input, ctx);
37
38
if
(not ret.has_value())
39
return
ReturnType
{
Error
{std::move(ret).error()}, std::move(warnings)};
40
41
return
ReturnType
{value_from(std::move(ret).value()), std::move(warnings)};
42
}
43
44
if
constexpr
(
SomeHandlerWithoutInput<HandlerType>
) {
45
// no input to pass, ignore the value
46
auto
const
ret = handler.process(ctx);
47
if
(not ret.has_value())
48
return
ReturnType
{
Error
{ret.error()}};
// forward Status
49
50
return
ReturnType
{value_from(ret.value())};
51
}
52
}
53
};
54
55
}
// namespace rpc::impl
rpc::SomeHandlerWithTypedInput
Specifies what a Handler validated by the shared consteval spec must provide.
Definition
Concepts.hpp:51
rpc::SomeHandlerWithoutInput
Specifies what a Handler without Input must provide.
Definition
Concepts.hpp:63
rpc::Error
std::unexpected< Status > Error
The type that represents just the error part of MaybeError.
Definition
Types.hpp:55
rpc::Context
Context of an RPC call.
Definition
Types.hpp:102
rpc::Context::apiVersion
uint32_t apiVersion
The API version requested by the client; 0 means invalid/unset.
Definition
Types.hpp:126
rpc::ReturnType
The final return type out of RPC engine.
Definition
Types.hpp:68
rpc::impl::DefaultProcessor
Definition
Processors.hpp:14
src
rpc
common
impl
Processors.hpp
Generated by
1.17.0