================ @@ -297,6 +340,450 @@ class JSONRPCTransport : public IOTransport<Req, Resp, Evt> { static constexpr llvm::StringLiteral kMessageSeparator = "\n"; }; -} // namespace lldb_private +/// A handler for the response to an outgoing request. +template <typename T> +using Reply = + std::conditional_t<std::is_void_v<T>, + llvm::unique_function<void(llvm::Error)>, + llvm::unique_function<void(llvm::Expected<T>)>>; + +namespace detail { +template <typename R, typename P> struct request_t final { + using type = llvm::unique_function<void(const P &, Reply<R>)>; +}; +template <typename R> struct request_t<R, void> final { + using type = llvm::unique_function<void(Reply<R>)>; +}; +template <typename P> struct event_t final { + using type = llvm::unique_function<void(const P &)>; +}; +template <> struct event_t<void> final { + using type = llvm::unique_function<void()>; +}; +} // namespace detail + +template <typename R, typename P> +using OutgoingRequest = typename detail::request_t<R, P>::type; + +/// A function to send an outgoing event. +template <typename P> using OutgoingEvent = typename detail::event_t<P>::type; + +/// Creates a request with the given id, method, and optional params. +template <typename Id, typename Req> +Req MakeRequest(Id, llvm::StringRef, std::optional<llvm::json::Value>); + +/// Creates an error response for a given request. +template <typename Req, typename Resp> +Resp MakeResponse(const Req &, llvm::Error); + +/// Creates a success response for a given request. +template <typename Req, typename Resp> +Resp MakeResponse(const Req &, llvm::json::Value); + +/// Creates an event. +template <typename Evt> +Evt MakeEvent(llvm::StringRef, std::optional<llvm::json::Value>); + +/// Extracts the result value from a response. +template <typename Resp> +llvm::Expected<llvm::json::Value> GetResult(const Resp &); + +/// Extracts the id from a response. +template <typename Id, typename Resp> Id GetId(const Resp &); + +/// Extracts the method from a request or event. +template <typename T> llvm::StringRef GetMethod(const T &); + +/// Extracts the parameters from a request or event. +template <typename T> llvm::json::Value GetParams(const T &); + +/// Binder collects a table of functions that handle calls. ---------------- JDevlieghere wrote:
I apologize for the bike-shedding, but maybe it would be helpful to describe this in terms of JSONRPC. Something like, the binder registers functions/callback for JSONRPC remote method calls. The JSONRPC transport takes care of parsing incoming calls and serializing responses. https://github.com/llvm/llvm-project/pull/159160 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits