Class to serialize and write the JSON-RPC request to memory.
More...
#include "nn/nlib/msgpack/jsonrpc/JsonRpcRequest.h"
Class to serialize and write the JSON-RPC request to memory.
- Description
- This class is used by the client side to create the byte string that becomes the JSON-RPC request.
Serializes and converts the JSON-RPC request created by JsonRpcRequest
into a byte string that can be sent to the server.
The actual data transmission (send and receive) must be written by the user.
- Both individual and batch requests can be created.
- Code to send an individual request is written as follows.
JsonRpcRequest& req = ...;
e = w.BeginWriteRequest(1);
if (e != 0) { ERROR }
e = w.WriteRequest(req);
if (e != 0) { ERROR }
size_t nBytes;
e = w.EndWriteRequest(&reqBytes, &nBytes);
if (e != 0) { ERROR }
- Code to send a batch request is written as follows.
Seq<JsonRpcRequest>& seq = ...;
e = w.BeginWriteRequest(seq.size());
if (e != 0) { ERROR }
foreach(item in seq) {
e = w.WriteRequest(item);
if (e != 0) { ERROR }
}
size_t nBytes;
e = w.EndWriteRequest(&reqBytes, &nBytes);
if (e != 0) { ERROR }
Definition at line 69 of file JsonRpcRequest.h.
nn::nlib::msgpack::jsonrpc::JsonRpcRequestWriter::JsonRpcRequestWriter |
( |
bool |
use_msgpack | ) |
|
|
inlineexplicit |
Sets the use of msgpack
instead of JSON as the JSON description method.
- Parameters
-
[in] | use_msgpack | If true , msgpack is used. |
- Description
- The nlib JSON-RPC server can handle
msgpack
requests. In this case, the response is sent to the client in the msgpack
format.
Definition at line 72 of file JsonRpcRequest.h.
nn::nlib::msgpack::jsonrpc::JsonRpcRequestWriter::BeginWriteRequest |
( |
uint32_t |
n | ) |
|
Call once before writing the JSON-RPC request.
- Parameters
-
[in] | n | Number of requests to write. (n >= 2 for a batch request.) |
- Return values
-
0 | Success. |
ENOMEM | memory allocation failed. |
Finishes writing the JSON-RPC request.
- Parameters
-
[out] | ptr | Pointer to the byte string. |
[out] | n | Pointer where the byte count of the data is written to. |
- Return values
-
0 | Success. |
EINVAL | ptr or n is NULL . |
ERANGE | The request count does not match the number specified in BeginWriteRequest . |
ENOMEM | memory allocation failed. |
- Description
- When successful, n byte data is set to the ptr parameter. The client side JSON-RPC call is completed by sending this data to the server.
nn::nlib::msgpack::jsonrpc::JsonRpcRequestWriter::WriteNotification |
( |
const char * |
method, |
|
|
const MpObject & |
params |
|
) |
| |
|
inline |
Writes the JSON-RPC notification.
- Parameters
-
[in] | method | Method name. |
[in] | params | Parameters. |
- Returns
- Returns
0
on success.
- Description
- This is equivalent to the code below.
Definition at line 76 of file JsonRpcRequest.h.
nn::nlib::msgpack::jsonrpc::JsonRpcRequestWriter::WriteRequest |
( |
const char * |
method, |
|
|
reqid_t |
id, |
|
|
const MpObject & |
params |
|
) |
| |
Writes the JSON-RPC request.
- Parameters
-
[in] | method | Method name. |
[in] | id | Request ID. |
[in] | params | Parameters. |
- Return values
-
0 | Success. |
EINVAL | method is NULL or an empty character string. |
ERANGE | The request count is larger than the number specified in BeginWriteRequest . |
ENOMEM | memory allocation failed. |
An | error occurred. Another JSON/msgpack write operation failed. |
nn::nlib::msgpack::jsonrpc::JsonRpcRequestWriter::WriteRequest |
( |
const JsonRpcRequest & |
req | ) |
|
|
inline |
Writes the JSON-RPC request.
- Parameters
-
- Returns
- Returns
0
on success.
- Description
- This is equivalent to the code below.
this->
WriteRequest(req.GetMethod(), req.GetId(), req.GetParams());
Definition at line 79 of file JsonRpcRequest.h.
The documentation for this class was generated from the following files: