nlib
nn::nlib::msgpack::jsonrpc::JsonRpcResponseWriter Class Referencefinal

Class that writes the JSON-RPC response byte string. More...

#include "nn/nlib/msgpack/jsonrpc/JsonRpcResponse.h"

Public Member Functions

 JsonRpcResponseWriter (bool msgpack) noexcept
 Creates a msgpack byte string when true is specified as the argument. More...
 
errno_t BeginWriteResponse (uint32_t n) noexcept
 Called once before writing the JSON-RPC response. More...
 
errno_t WriteResponse (JsonRpcResponse *result) noexcept
 Writes the JSON-RPC response. More...
 
errno_t EndWriteResponse (UniquePtrType *ptr, size_t *n) noexcept
 Finishes writing the JSON-RPC response. More...
 
std::tuple< errno_t, UniquePtrType, size_t > EndWriteResponse () noexcept
 Completes writing a JSON-RPC response and returns a tupple of the error value, byte string, and the byte string size. More...
 
Constructor, Destructor, and Initialization
constexpr JsonRpcResponseWriter () noexcept
 Instantiates the object with default parameters (default constructor).
 
 ~JsonRpcResponseWriter () noexcept
 Destructor.
 
 JsonRpcResponseWriter (JsonRpcResponseWriter &&rhs) noexcept
 Instantiates the object (move constructor).
 
JsonRpcResponseWriteroperator= (JsonRpcResponseWriter &&rhs) noexcept
 Move assignment operator.
 

Detailed Description

Class that writes the JSON-RPC response byte string.

Description
This class is used on the server side of JSON-RPC.
The send process after converting to a byte string must be written by the user.
Not required when using JsonRpcServerExec for server processing. It is used within JsonRpcServerExec.

Definition at line 100 of file JsonRpcResponse.h.

Constructor & Destructor Documentation

◆ JsonRpcResponseWriter()

nn::nlib::msgpack::jsonrpc::JsonRpcResponseWriter::JsonRpcResponseWriter ( bool  msgpack)
inlineexplicitnoexcept

Creates a msgpack byte string when true is specified as the argument.

Parameters
[in]msgpackSet to true if creating a msgpack byte string.

Definition at line 129 of file JsonRpcResponse.h.

Member Function Documentation

◆ BeginWriteResponse()

nn::nlib::msgpack::jsonrpc::JsonRpcResponseWriter::BeginWriteResponse ( uint32_t  n)
noexcept

Called once before writing the JSON-RPC response.

Parameters
[in]nNumber of responses (n >= 2 for responses to a batch request).
Return values
0Success.
ENOMEMmemory allocation failed.

◆ EndWriteResponse() [1/2]

nn::nlib::msgpack::jsonrpc::JsonRpcResponseWriter::EndWriteResponse ( UniquePtrType ptr,
size_t *  n 
)
noexcept

Finishes writing the JSON-RPC response.

Parameters
[out]ptrPointer to the byte string.
[out]nPointer where the byte count of the data is written to.
Return values
0Success.
EINVALptr or n is NULL.
ERANGEThe response count does not match the number specified in BeginWriteRequest.
ENOMEMmemory allocation failed.
Description
When successful, n byte data is set to the ptr parameter. The server side process is completed by sending this data to the client.

◆ EndWriteResponse() [2/2]

nn::nlib::msgpack::jsonrpc::JsonRpcResponseWriter::EndWriteResponse ( )
noexcept

Completes writing a JSON-RPC response and returns a tupple of the error value, byte string, and the byte string size.

Return values
0,buf,bufsizeSuccess.
ERANGE,nullptr,0The response count does not match the number specified in BeginWriteRequest().
ENOMEM,nullptr,0Indicates memory allocation failed.
Description
The server side process is completed by sending the returned byte string to the client. Only if the error value is 0, the byte string and the byte string size in the tupple are valid.

◆ WriteResponse()

nn::nlib::msgpack::jsonrpc::JsonRpcResponseWriter::WriteResponse ( JsonRpcResponse result)
noexcept

Writes the JSON-RPC response.

Parameters
[in]resultPointer to JsonRpcResponse
Return values
0Success.
EINVALIndicates that result is NULL.
ERANGEThe request count is larger than the number specified in BeginWriteRequest.
ENOMEMmemory allocation failed.
Anerror occurred. Another JSON/msgpack write operation failed.
Description
In some cases the object that result points to is altered.

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