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 {
  OK = 0,
  PARSE_ERROR = -32700,
  INVALID_REQUEST = -32600,
  METHOD_NOT_FOUND = -32601,
  INVALID_PARAMS = -32602,
  INTERNAL_ERROR = -32603,
  CLIENT_ABORT = -31000
}
 Definition of the predefined error code contained in the JSON-RPC response. More...
 

Public Member Functions

 JsonRpcResponse () noexcept
 Instantiates the object with default parameters (default constructor).
 
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. More...
 
reqid_t GetId () const noexcept
 Returns the ID of the JSON-RPC response. More...
 
const char * GetErrorMessage () const noexcept
 Returns an error message. More...
 
MpObjectGetMpObject () noexcept
 Returns the JSON-RPC return value, or additional information about an error. More...
 
const MpObjectGetMpObject () const noexcept
 Returns the JSON-RPC return value, or additional information about an error. More...
 
 operator bool () const
 Returns true if an error has not occurred.
 

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 22 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
OK 

Execution of JSON-RPC was successful.

PARSE_ERROR 

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

INVALID_REQUEST 

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

METHOD_NOT_FOUND 

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

INVALID_PARAMS 

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

INTERNAL_ERROR 

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

CLIENT_ABORT 

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

Definition at line 24 of file JsonRpcResponse.h.

Member Function Documentation

§ GetError()

nn::nlib::msgpack::jsonrpc::JsonRpcResponse::GetError ( ) const
inlinenoexcept

Returns an error code.

Returns
Error code.

Definition at line 44 of file JsonRpcResponse.h.

§ GetErrorMessage()

nn::nlib::msgpack::jsonrpc::JsonRpcResponse::GetErrorMessage ( ) const
inlinenoexcept

Returns an error message.

Returns
Error message.

Definition at line 48 of file JsonRpcResponse.h.

§ GetId()

nn::nlib::msgpack::jsonrpc::JsonRpcResponse::GetId ( ) const
inlinenoexcept

Returns the ID of the JSON-RPC response.

Returns
ID of the JSON-RPC response.

Definition at line 47 of file JsonRpcResponse.h.

§ GetMpObject() [1/2]

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 51 of file JsonRpcResponse.h.

§ GetMpObject() [2/2]

nn::nlib::msgpack::jsonrpc::JsonRpcResponse::GetMpObject ( ) const
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 52 of file JsonRpcResponse.h.

§ MoveResultFrom()

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 39 of file JsonRpcResponse.h.


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