' JSON-RPC 2.0 constants and optional helper declarations.
#IF NOT %DEF(PBX_JSON_RPC2_PBI)
#DEFINE PBX_JSON_RPC2_PBI
#INCLUDE ONCE "Legacy/System/json_core.inc"

%EQUATE `JSONRPC_VERSION_2_0 = "2.0"
%EQUATE `JSONRPC_FIELD_JSONRPC = "jsonrpc"
%EQUATE `JSONRPC_FIELD_METHOD = "method"
%EQUATE `JSONRPC_FIELD_PARAMS = "params"
%EQUATE `JSONRPC_FIELD_ID = "id"
%EQUATE `JSONRPC_FIELD_RESULT = "result"
%EQUATE `JSONRPC_FIELD_ERROR = "error"
%EQUATE `JSONRPC_FIELD_CODE = "code"
%EQUATE `JSONRPC_FIELD_MESSAGE = "message"
%EQUATE `JSONRPC_FIELD_DATA = "data"

%EQUATE `JSONRPC_ERR_PARSE_ERROR = -32700
%EQUATE `JSONRPC_ERR_INVALID_REQUEST = -32600
%EQUATE `JSONRPC_ERR_METHOD_NOT_FOUND = -32601
%EQUATE `JSONRPC_ERR_INVALID_PARAMS = -32602
%EQUATE `JSONRPC_ERR_INTERNAL_ERROR = -32603
%EQUATE `JSONRPC_ERR_SERVER_ERROR_MIN = -32099
%EQUATE `JSONRPC_ERR_SERVER_ERROR_MAX = -32000

%EQUATE `JSONRPC_ID_TYPE_NONE = 0
%EQUATE `JSONRPC_ID_TYPE_STRING = 1
%EQUATE `JSONRPC_ID_TYPE_NUMBER = 2
%EQUATE `JSONRPC_ID_TYPE_NULL = 3

TYPE JSONRPC_MESSAGE_INFO
    isRequest AS LONG
    isNotification AS LONG
    idType AS LONG
    methodNode AS QUAD
    paramsNode AS QUAD
    resultNode AS QUAD
    errorNode AS QUAD
END TYPE

DECLARE FUNCTION PBXJsonRpc_ParseMessage LIB "pbxjson64.dll" ALIAS "PBXJsonRpc_ParseMessage" (BYVAL hDoc AS QUAD, BYVAL pInfo AS QUAD) AS LONG
DECLARE FUNCTION PBXJsonRpc_BuildRequest LIB "pbxjson64.dll" ALIAS "PBXJsonRpc_BuildRequest" (BYVAL pMethod AS QUAD, BYVAL cbMethod AS QUAD, BYVAL hParams AS QUAD, BYVAL pId AS QUAD, BYVAL cbId AS QUAD, BYVAL phDoc AS QUAD) AS LONG
DECLARE FUNCTION PBXJsonRpc_BuildNotification LIB "pbxjson64.dll" ALIAS "PBXJsonRpc_BuildNotification" (BYVAL pMethod AS QUAD, BYVAL cbMethod AS QUAD, BYVAL hParams AS QUAD, BYVAL phDoc AS QUAD) AS LONG
DECLARE FUNCTION PBXJsonRpc_BuildResult LIB "pbxjson64.dll" ALIAS "PBXJsonRpc_BuildResult" (BYVAL hResult AS QUAD, BYVAL pId AS QUAD, BYVAL cbId AS QUAD, BYVAL phDoc AS QUAD) AS LONG
DECLARE FUNCTION PBXJsonRpc_BuildError LIB "pbxjson64.dll" ALIAS "PBXJsonRpc_BuildError" (BYVAL errCode AS LONG, BYVAL pMessage AS QUAD, BYVAL cbMessage AS QUAD, BYVAL hData AS QUAD, BYVAL pId AS QUAD, BYVAL cbId AS QUAD, BYVAL phDoc AS QUAD) AS LONG

#ENDIF
