' JSON-RPC 2.0 constants and optional helper declarations.
#IF NOT %DEF(PBX_JSON_RPC2_PBI)
#DEFINE PBX_JSON_RPC2_PBI
#include once "json_core.inc"

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

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

CONST JSONRPC_ID_TYPE_NONE = 0
CONST JSONRPC_ID_TYPE_STRING = 1
CONST JSONRPC_ID_TYPE_NUMBER = 2
CONST 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
