5#include <unordered_map>
7#include <nlohmann/json.hpp>
21 std::unordered_map<LibErrorKind, std::pair<int, const char*>>;
43 const nlohmann::json& response_json,
44 std::optional<nlohmann::json>
id) ->
Response;
53 const nlohmann::json& result,
54 const std::optional<nlohmann::json>&
id) ->
Response;
64 const std::optional<nlohmann::json>&
id = std::nullopt) ->
Response;
73 const nlohmann::json& error,
74 const std::optional<nlohmann::json>&
id) ->
Response;
80 [[nodiscard]]
auto ToJson() const -> nlohmann::json;
86 [[nodiscard]] auto
ToStr() const -> std::
string;
96 nlohmann::json response, std::optional<nlohmann::json>
id = std::nullopt);
99 void ValidateResponse() const;
108 static auto CreateErrorResponse(
109 const std::
string& message,
int code,
110 const std::optional<nlohmann::json>&
id) -> nlohmann::json;
113 nlohmann::json response_;
Represents a JSON-RPC response.
static auto CreateLibError(LibErrorKind error_kind, const std::optional< nlohmann::json > &id=std::nullopt) -> Response
Creates a Response object for a library error.
auto ToJson() const -> nlohmann::json
Serializes the Response object to a JSON object.
auto operator=(Response &&other) noexcept -> Response &=delete
Response(const Response &)=delete
static auto CreateUserError(const nlohmann::json &error, const std::optional< nlohmann::json > &id) -> Response
Creates a Response object for a user error.
static auto CreateResult(const nlohmann::json &result, const std::optional< nlohmann::json > &id) -> Response
Creates a successful Response object.
auto operator=(const Response &) -> Response &=delete
static auto FromUserResponse(const nlohmann::json &response_json, std::optional< nlohmann::json > id) -> Response
Creates a Response object from a JSON object that represents a user response.
auto ToStr() const -> std::string
Serializes the Response object to a string.
LibErrorKind
Enumeration for library error kinds.
std::unordered_map< LibErrorKind, std::pair< int, const char * > > ErrorInfoMap