29 {
30 auto root = nlohmann::json::parse(request, nullptr, false);
31 if (root.is_discarded()) {
33 }
34
35
36 if (root.is_object()) {
38 if (!request.has_value()) {
40 }
41
42 auto response = co_await DispatchSingleRequest(request.value());
43 if (response.has_value()) {
44 co_return response.value().ToJson().dump();
45 }
46 co_return std::nullopt;
47 }
48
49
50 if (root.is_array()) {
51 if (root.empty()) {
53 .ToJson()
54 .dump();
55 }
56
57 std::vector<Request> requests;
58 std::vector<Response> responses;
59 for (const auto& element : root) {
61 if (!request.has_value()) {
63 continue;
64 }
65 requests.push_back(request.value());
66 }
67
68 auto dispatched = co_await DispatchBatchRequest(requests);
69 for (const auto& response : dispatched) {
70 responses.push_back(response);
71 }
72
73 co_return nlohmann::json(responses).dump();
74 }
75
77 .ToJson()
78 .dump();
79}
static auto FromJson(const nlohmann::json &json_obj) -> std::expected< Request, error::RpcError >
static auto CreateError(RpcErrorCode code, const std::optional< RequestId > &id=std::nullopt) -> Response