View Source jarl_jsonrpc (jarl v1.1.0)
Summary
Functions
Decode a JSONRpc text packet and decoded message or a list of decoded messages in the case of a batch.
Encode a JSONRpc message or a list of JSONRpc messages to JSON text. For backward compatibility, the method
can be an atom.
Types
-type json_rpc_message() :: {request, Method :: binary(), Params :: map() | list(), ReqRef :: binary() | integer()} | {result, Result :: term(), ReqRef :: binary()} | {notification, Method :: binary(), Params :: map() | list()} | {error, Code :: integer(), Message :: undefined | binary(), Data :: undefined | term(), ReqRef :: undefined | binary() | integer()} | {decoding_error, Code :: integer(), Message :: undefined | binary(), Data :: undefined | term(), ReqRef :: undefined | binary() | integer()}.
Functions
-spec decode(Data :: iodata()) -> json_rpc_message() | [json_rpc_message()].
Decode a JSONRpc text packet and decoded message or a list of decoded messages in the case of a batch.
If it returns a list, the all the responses are supposed to be sent back in a batch too, as per the JSONRpc 2.0 specifications.
If some decoding errors occure, a special error message with the tag decoding_error
will be returned, this message can be encoded and sent back directly to the JSON-RPC peer.
During JSON decoding, the null
values are changed to undefined
and when encoding, undefined
values are changed back to null
.
The method
will always be a binary, and id
will always be either a binary or an integer.
The possible decoded messages are:
{request, Method :: binary(), Params :: map() | list(), ReqRef :: binary() | integer()}
{result, Result :: term(), ReqRef :: binary()}
{notification, Method :: binary(), Params :: map() | list()}
{error, Code :: integer(), Message :: undefined | binary(), Data :: undefined | term(), ReqRef :: undefined | binary() | integer()}
{decoding_error, Code :: integer(), Message :: undefined | binary(), Data :: undefined | term(), ReqRef :: undefined | binary() | integer()}
-spec encode(Messages :: json_rpc_message() | [json_rpc_message()]) -> iodata().
Encode a JSONRpc message or a list of JSONRpc messages to JSON text. For backward compatibility, the method
can be an atom.