6 std::string method,
const std::optional<nlohmann::json> ¶ms,
7 std::optional<nlohmann::json>
id)
8 : method_(std::move(method)), params_(params), id_(std::move(id)) {
12 auto params = json_obj.contains(
"params")
13 ? std::optional<nlohmann::json>(json_obj[
"params"])
16 auto id = json_obj.contains(
"id")
17 ? std::optional<nlohmann::json>(json_obj[
"id"])
19 return Request(json_obj[
"method"], params,
id);
23 nlohmann::json json_obj;
24 json_obj[
"jsonrpc"] =
"2.0";
25 json_obj[
"method"] = method_;
26 if (params_.has_value()) {
27 json_obj[
"params"] = params_.value();
29 if (id_.has_value()) {
30 json_obj[
"id"] = id_.value();
Represents a JSON-RPC request.
static auto FromJson(const nlohmann::json &json_obj) -> Request
Creates a Request object from a JSON object.
auto ToJson() const -> nlohmann::json
Serializes the Request object to a JSON object.
Request(std::string method, const std::optional< nlohmann::json > ¶ms=std::nullopt, std::optional< nlohmann::json > id=std::nullopt)
Constructs a Request object.