nlib
nn::nlib::msgpack::jsonrpc::JsonRpcRequestWriter Class Referencefinal

Class to serialize and write the JSON-RPC request to memory. More...

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

Public Member Functions

 JsonRpcRequestWriter ()
 Instantiates the object with default parameters (default constructor).
 
 JsonRpcRequestWriter (bool use_msgpack)
 Sets the use of msgpack instead of JSON as the JSON description method. More...
 
errno_t BeginWriteRequest (uint32_t n)
 Call once before writing the JSON-RPC request. More...
 
errno_t WriteRequest (const char *method, reqid_t id, const MpObject &params)
 Writes the JSON-RPC request. More...
 
errno_t WriteNotification (const char *method, const MpObject &params)
 Writes the JSON-RPC notification. More...
 
errno_t WriteRequest (const JsonRpcRequest &req)
 Writes the JSON-RPC request. More...
 
errno_t EndWriteRequest (ReallocOutputStream::UniquePtrType *ptr, size_t *n)
 Finishes writing the JSON-RPC request. More...
 

Detailed Description

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 }
// Add code to actually send the content of reqBytes here.
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 }
// Add code to actually send the content of reqBytes here.

Definition at line 69 of file JsonRpcRequest.h.

Constructor & Destructor Documentation

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_msgpackIf 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.

Member Function Documentation

nn::nlib::msgpack::jsonrpc::JsonRpcRequestWriter::BeginWriteRequest ( uint32_t  n)

Call once before writing the JSON-RPC request.

Parameters
[in]nNumber of requests to write. (n >= 2 for a batch request.)
Return values
0Success.
ENOMEMmemory allocation failed.
nn::nlib::msgpack::jsonrpc::JsonRpcRequestWriter::EndWriteRequest ( ReallocOutputStream::UniquePtrType ptr,
size_t *  n 
)

Finishes writing the JSON-RPC request.

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 request 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 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]methodMethod name.
[in]paramsParameters.
Returns
Returns 0 on success.
Description
This is equivalent to the code below.
this->WriteRequest(method, 0, params);

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]methodMethod name.
[in]idRequest ID.
[in]paramsParameters.
Return values
0Success.
EINVALmethod is NULL or an empty character string.
ERANGEThe request count is larger than the number specified in BeginWriteRequest.
ENOMEMmemory allocation failed.
Anerror occurred. Another JSON/msgpack write operation failed.
nn::nlib::msgpack::jsonrpc::JsonRpcRequestWriter::WriteRequest ( const JsonRpcRequest req)
inline

Writes the JSON-RPC request.

Parameters
[in]reqJSON-RPC request.
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: