nlib
nn::nlib::msgpack::jsonrpc::JsonRpcResponse Class Referencefinal

Class for representing the JSON-RPC response. More...

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

Public Types

enum  ErrorCode {
  kOk = 0,
  kParseError = -32700,
  kInvalidRequest = -32600,
  kMethodNotFound = -32601,
  kInvalidParams = -32602,
  kInternalError = -32603,
  kClientAbort = -31000
}
 Definition of the predefined error code contained in the JSON-RPC response. More...
 

Public Member Functions

void MoveResultFrom (MpObject &obj) noexcept
 Sets the JSON-RPC return value (when not an error). More...
 
void MoveResultFrom (MpObject &&obj) noexcept
 Sets the JSON-RPC return value (when not an error). More...
 
void SetError (int errcode, const char *msg, MpObject &data) noexcept
 Sets the JSON-RPC function error. More...
 
void SetError (int errcode, const char *msg) noexcept
 Sets the JSON-RPC function error. More...
 
ErrorCode GetError () const noexcept
 Returns an error code.
 
reqid_t GetId () const noexcept
 Returns the ID of the JSON-RPC response.
 
const char * GetErrorMessage () const noexcept
 Returns an error message.
 
MpObjectGetMpObject () noexcept
 Returns the JSON-RPC return value, or additional information about an error. More...
 
const MpObjectGetMpObject () const noexcept
 The const decoration version of the above function.
 
 operator bool () const
 Returns true if the object has been initialized and an error has not occurred inside, or returns false if an error has occurred inside.
 
Constructor, Destructor, and Initialization
 JsonRpcResponse () noexcept
 Instantiates the object with default parameters (default constructor).
 
 ~JsonRpcResponse () noexcept
 Destructor.
 

Detailed Description

Class for representing the JSON-RPC response.

Description
The server must return a response to the JSON-RPC request. (Does not include notifications.) The response is the associative array that includes the following keys.
jsonrpc:
The string 2.0 becomes the value.
result:
Included when the call is successful. Not included in the case of an error. The value is the result of the server function call.
id:
Request ID.
The client side sorts the response according to this ID.
error:
Included when the call is an error. Not included in the case of a success.
An associative array that includes the following keys.
  • code: Error code.
  • message: Error message.
  • data: Additional information about the error. The value may be abbreviated by the server definition.
See also
http://www.jsonrpc.org/specification#examples

Definition at line 40 of file JsonRpcResponse.h.

Member Enumeration Documentation

◆ ErrorCode

Definition of the predefined error code contained in the JSON-RPC response.

Description
In addition, -32000 to -32768 is reserved. -32000 to -32099 is also reserved for errors defined in the server implementation.
Enumerator
kOk 

Execution of JSON-RPC was successful.

kParseError 

Failed to parse JSON. This value is defined as -32700 by JSON-RPC 2.0.

kInvalidRequest 

The JSON received was invalid as JSON-RPC. This value is defined as -32600 by JSON-RPC 2.0.

kMethodNotFound 

The specified method does not exist, or is not available. This value is defined as -32601 by JSON-RPC 2.0.

kInvalidParams 

Invalid parameter. This value is defined as -32602 by JSON-RPC 2.0.

kInternalError 

Internal error. This value is defined as -32603 by JSON-RPC 2.0.

kClientAbort 

The RPC call was halted by the client. This value is defined by nlib.

Definition at line 42 of file JsonRpcResponse.h.

Member Function Documentation

◆ GetMpObject()

nn::nlib::msgpack::jsonrpc::JsonRpcResponse::GetMpObject ( )
inlinenoexcept

Returns the JSON-RPC return value, or additional information about an error.

Returns
The JSON-RPC return value, or additional information about an error.

Definition at line 70 of file JsonRpcResponse.h.

◆ MoveResultFrom() [1/2]

nn::nlib::msgpack::jsonrpc::JsonRpcResponse::MoveResultFrom ( MpObject obj)
noexcept

Sets the JSON-RPC return value (when not an error).

Parameters
[in,out]objThe specified return value.
Description
Note that the content of obj is moved to the JsonRpcResponse object to avoid the overhead of copying.

◆ MoveResultFrom() [2/2]

nn::nlib::msgpack::jsonrpc::JsonRpcResponse::MoveResultFrom ( MpObject &&  obj)
noexcept

Sets the JSON-RPC return value (when not an error).

Parameters
[in,out]objThe specified return value.
Description
Note that the content of obj is moved to the JsonRpcResponse object to avoid the overhead of copying.

◆ SetError() [1/2]

nn::nlib::msgpack::jsonrpc::JsonRpcResponse::SetError ( int  errcode,
const char *  msg,
MpObject data 
)
noexcept

Sets the JSON-RPC function error.

Parameters
[in]errcodeError code.
[in]msgError message.
[in,out]dataAdditional information about the error.
Description
Note that the content of data is moved to the JsonRpcResponse object to avoid the overhead of copying.

◆ SetError() [2/2]

nn::nlib::msgpack::jsonrpc::JsonRpcResponse::SetError ( int  errcode,
const char *  msg 
)
inlinenoexcept

Sets the JSON-RPC function error.

Parameters
[in]errcodeError code.
[in]msgError message.

Definition at line 62 of file JsonRpcResponse.h.


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