JSON-RPC 2.0
JSON-RPC 2.0 Modern C++ Library
Loading...
Searching...
No Matches
jsonrpc::transport::StdioTransport Class Reference

Transport layer using standard I/O for JSON-RPC communication. More...

#include <stdio_transport.hpp>

Inheritance diagram for jsonrpc::transport::StdioTransport:
Collaboration diagram for jsonrpc::transport::StdioTransport:

Public Member Functions

void SendMessage (const std::string &message) override
 Sends a message in string to the transport layer.
 
auto ReceiveMessage () -> std::string override
 Receives a message from the transport layer.
 
- Public Member Functions inherited from jsonrpc::transport::Transport
 Transport ()=default
 
virtual ~Transport ()=default
 
 Transport (const Transport &)=default
 
auto operator= (const Transport &) -> Transport &=default
 
 Transport (Transport &&)=delete
 
auto operator= (Transport &&) -> Transport &=delete
 

Detailed Description

Transport layer using standard I/O for JSON-RPC communication.

Definition at line 12 of file stdio_transport.hpp.

Member Function Documentation

◆ ReceiveMessage()

auto jsonrpc::transport::StdioTransport::ReceiveMessage ( ) -> std::string
overridevirtual

Receives a message from the transport layer.

Returns
The JSON-RPC response as a string.

Implements jsonrpc::transport::Transport.

Definition at line 14 of file stdio_transport.cpp.

14 {
15 std::string response;
16 if (!std::getline(std::cin, response)) {
17 throw std::runtime_error("Failed to receive message");
18 }
19 spdlog::debug("StdioTransport received response: {}", response);
20 return response;
21}

◆ SendMessage()

void jsonrpc::transport::StdioTransport::SendMessage ( const std::string & message)
overridevirtual

Sends a message in string to the transport layer.

Parameters
requestThe JSON-RPC request as a string.

Implements jsonrpc::transport::Transport.

Definition at line 9 of file stdio_transport.cpp.

9 {
10 spdlog::debug("StdioTransport sending message: {}", message);
11 std::cout << message << std::endl;
12}

The documentation for this class was generated from the following files: