6 std::string method, std::optional<nlohmann::json> params,
7 bool is_notification,
const std::function<
int()> &id_generator)
8 : method_(std::move(method)),
9 params_(std::move(params)),
10 is_notification_(is_notification),
12 if (!is_notification_) {
18 return !is_notification_;
26 nlohmann::json json_request;
27 json_request[
"jsonrpc"] =
"2.0";
28 json_request[
"method"] = method_;
30 json_request[
"params"] = *params_;
32 if (!is_notification_) {
33 json_request[
"id"] = id_;
35 return json_request.dump();
auto Dump() const -> std::string
Serializes the request to a JSON string.
auto GetKey() const -> int
Returns the unique key (ID) for the request.
auto RequiresResponse() const -> bool
Checks if the request requires a response.
Request(std::string method, std::optional< nlohmann::json > params, bool is_notification, const std::function< int()> &id_generator)
Constructs a new Request object.