JSON-RPC 2.0
JSON-RPC 2.0 Modern C++ Library
Loading...
Searching...
No Matches
typed_handlers.hpp File Reference

Type-safe handlers for JSON-RPC method calls and notifications. More...

#include <expected>
#include <optional>
#include <utility>
#include <variant>
#include <asio/awaitable.hpp>
#include <nlohmann/json.hpp>
#include <spdlog/spdlog.h>
#include "jsonrpc/endpoint/jsonrpc_traits.hpp"
Include dependency graph for typed_handlers.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  jsonrpc::endpoint::TypedMethodHandler< ParamsType, ResultType, ErrorType >
 
class  jsonrpc::endpoint::TypedNotificationHandler< ParamsType, ErrorType >
 

Namespaces

namespace  jsonrpc
 
namespace  jsonrpc::endpoint
 

Detailed Description

Type-safe handlers for JSON-RPC method calls and notifications.

This file contains handler classes that safely adapt typed C++ functions to work with the JSON-RPC protocol. We use class-based handlers instead of direct lambda functions because:

  1. Lambda captures in coroutines can lead to use-after-free issues when the lambda object is destroyed while the coroutine is suspended.
  2. These classes provide well-defined lifetime semantics when shared_ptr-wrapped, ensuring the handler and its state remain valid throughout coroutine execution.
  3. They offer cleaner separation of type conversion logic from the endpoint code.

This design prevents potential memory corruption that could occur with direct lambda captures in coroutines, especially when those lambdas capture by reference.

Definition in file typed_handlers.hpp.