JSON-RPC 2.0
JSON-RPC 2.0 Modern C++ Library
Loading...
Searching...
No Matches
jsonrpc_traits.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <concepts>
4#include <variant>
5
6#include "nlohmann/json.hpp"
7
8namespace jsonrpc::endpoint {
9
10template <typename T>
11concept FromJson = requires(nlohmann::json j) {
12 { j.get<T>() } -> std::same_as<T>;
13};
14
15template <typename T>
16concept ToJson = std::is_same_v<T, std::monostate> || requires(T value) {
17 { nlohmann::json(value) } -> std::same_as<nlohmann::json>;
18};
19
20template <typename T>
22
23template <typename T>
24concept NotJsonLike =
25 !std::is_same_v<std::decay_t<T>, nlohmann::json> &&
26 !std::is_same_v<std::decay_t<T>, std::optional<nlohmann::json>>;
27
28template <typename T>
29concept HasMessageMethod = std::is_same_v<T, std::monostate> || requires(T e) {
30 { e.Message() } -> std::convertible_to<std::string>;
31};
32
33} // namespace jsonrpc::endpoint