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

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

#include <framed_stdio_transport.hpp>

Inheritance diagram for jsonrpc::transport::FramedStdioTransport:
Collaboration diagram for jsonrpc::transport::FramedStdioTransport:

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
 

Additional Inherited Members

- Static Protected Member Functions inherited from jsonrpc::transport::FramedTransport
static void FrameMessage (std::ostream &output, const std::string &message)
 Constructs a framed message.
 
static auto ReadHeadersFromStream (std::istream &input) -> HeaderMap
 
static auto ReadContentLengthFromStream (std::istream &input) -> int
 
static auto ReadContent (std::istream &input, std::size_t content_length) -> std::string
 Reads content from the input stream based on the content length.
 
static auto ReceiveFramedMessage (std::istream &input) -> std::string
 Receives a framed message.
 
- Static Protected Attributes inherited from jsonrpc::transport::FramedTransport
static constexpr const char * kHeaderDelimiter = "\r\n\r\n"
 The delimiter used to separate headers from the message content.
 

Detailed Description

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

This class uses framed transport to send and receive JSON-RPC messages over standard I/O.

Definition at line 17 of file framed_stdio_transport.hpp.

Member Function Documentation

◆ ReceiveMessage()

auto jsonrpc::transport::FramedStdioTransport::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 15 of file framed_stdio_transport.cpp.

15 {
16 std::string response = ReceiveFramedMessage(std::cin);
17 spdlog::debug("FramedStdioTransport received message: {}", response);
18 return response;
19}
static auto ReceiveFramedMessage(std::istream &input) -> std::string
Receives a framed message.

◆ SendMessage()

void jsonrpc::transport::FramedStdioTransport::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 framed_stdio_transport.cpp.

9 {
10 spdlog::debug("FramedStdioTransport sending message: {}", message);
11 FrameMessage(std::cout, message);
12 std::cout << std::flush;
13}
static void FrameMessage(std::ostream &output, const std::string &message)
Constructs a framed message.

References jsonrpc::transport::FramedTransport::FrameMessage().

Here is the call graph for this function:

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