object
json_rpc
JSON-RPC 2.0 protocol encoding and decoding. Provides predicates for constructing and parsing JSON-RPC 2.0 request, notification, response, and error objects. Uses the json library for JSON parsing and generation.
logtalk_load(json_rpc(loader))static, context_switching_calls
Specification: Implements the JSON-RPC 2.0 specification: https://www.jsonrpc.org/specification
JSON representation: Uses the
jsonlibrary default representation: curly terms for objects, dashes for pairs, and atoms for strings.Request: A JSON-RPC 2.0 request is represented as
{jsonrpc-'2.0', method-Method, params-Params, id-Id}.Notification: A JSON-RPC 2.0 notification is represented as
{jsonrpc-'2.0', method-Method, params-Params}.Successful response: A JSON-RPC 2.0 successful response is represented as
{jsonrpc-'2.0', result-Result, id-Id}.Error response: A JSON-RPC 2.0 error response is represented as
{jsonrpc-'2.0', error-{code-Code, message-Message}, id-Id}or{jsonrpc-'2.0', error-{code-Code, message-Message, data-Data}, id-Id}.Batch request: A JSON-RPC 2.0 batch request is represented as a list of request and/or notification terms.
Error codes: Standard error codes: -32700 (parse error), -32600 (invalid request), -32601 (method not found), -32602 (invalid params), -32603 (internal error). Server errors: -32000 to -32099.
Public predicates
request/4
Constructs a JSON-RPC 2.0 request term.
staticrequest(Method,Params,Id,Request)request(+atom,+list,+nonvar,--compound) - onerequest/3
Constructs a JSON-RPC 2.0 request term with no parameters.
staticrequest(Method,Id,Request)request(+atom,+nonvar,--compound) - onenotification/3
Constructs a JSON-RPC 2.0 notification term (a request without an id).
staticnotification(Method,Params,Notification)notification(+atom,+list,--compound) - onenotification/2
Constructs a JSON-RPC 2.0 notification term with no parameters.
staticnotification(Method,Notification)notification(+atom,--compound) - oneresponse/3
Constructs a JSON-RPC 2.0 successful response term.
staticresponse(Result,Id,Response)response(+nonvar,+nonvar,--compound) - oneerror_response/4
Constructs a JSON-RPC 2.0 error response term with a null id (used when the request id cannot be determined).
staticerror_response(Code,Message,Id,ErrorResponse)error_response(+integer,+atom,+nonvar,--compound) - oneerror_response/5
Constructs a JSON-RPC 2.0 error response term with additional error data.
staticerror_response(Code,Message,Data,Id,ErrorResponse)error_response(+integer,+atom,+nonvar,+nonvar,--compound) - oneparse_error/1
Constructs a JSON-RPC 2.0 parse error response (-32700) with a null id.
staticparse_error(ErrorResponse)parse_error(--compound) - oneinvalid_request/1
Constructs a JSON-RPC 2.0 invalid request error response (-32600) with a null id.
staticinvalid_request(ErrorResponse)invalid_request(--compound) - onemethod_not_found/2
Constructs a JSON-RPC 2.0 method not found error response (-32601).
staticmethod_not_found(Id,ErrorResponse)method_not_found(+nonvar,--compound) - oneinvalid_params/2
Constructs a JSON-RPC 2.0 invalid params error response (-32602).
staticinvalid_params(Id,ErrorResponse)invalid_params(+nonvar,--compound) - oneinternal_error/2
Constructs a JSON-RPC 2.0 internal error response (-32603).
staticinternal_error(Id,ErrorResponse)internal_error(+nonvar,--compound) - oneencode/2
Encodes a JSON-RPC 2.0 term (request, notification, response, error, or batch) into a JSON atom.
staticencode(Term,JSON)encode(+compound,--atom) - onedecode/2
Decodes a JSON atom into a JSON-RPC 2.0 term (request, notification, response, error, or batch).
staticdecode(JSON,Term)decode(+atom,--compound) - one_or_erroris_request/1
True if the term is a valid JSON-RPC 2.0 request (has jsonrpc, method, and id fields).
staticis_request(Term)is_request(+compound) - zero_or_oneis_notification/1
True if the term is a valid JSON-RPC 2.0 notification (has jsonrpc and method fields but no id field).
staticis_notification(Term)is_notification(+compound) - zero_or_oneis_response/1
True if the term is a valid JSON-RPC 2.0 successful response (has jsonrpc, result, and id fields).
staticis_response(Term)is_response(+compound) - zero_or_oneis_error_response/1
True if the term is a valid JSON-RPC 2.0 error response (has jsonrpc, error, and id fields).
staticis_error_response(Term)is_error_response(+compound) - zero_or_oneis_batch/1
True if the term is a valid JSON-RPC 2.0 batch (a non-empty list).
staticis_batch(Term)is_batch(+compound) - zero_or_oneid/2
Extracts the id field from a JSON-RPC 2.0 message.
staticid(Message,Id)id(+compound,--nonvar) - zero_or_onemethod/2
Extracts the method field from a JSON-RPC 2.0 request or notification.
staticmethod(Message,Method)method(+compound,--atom) - zero_or_oneparams/2
Extracts the params field from a JSON-RPC 2.0 request or notification.
staticparams(Message,Params)params(+compound,--nonvar) - zero_or_oneresult/2
Extracts the result field from a JSON-RPC 2.0 response.
staticresult(Message,Result)result(+compound,--nonvar) - zero_or_oneerror/2
Extracts the error field from a JSON-RPC 2.0 error response.
staticerror(Message,Error)error(+compound,--compound) - zero_or_oneerror_code/2
Extracts the error code from a JSON-RPC 2.0 error response.
staticerror_code(Message,Code)error_code(+compound,--integer) - zero_or_oneerror_message/2
Extracts the error message from a JSON-RPC 2.0 error response.
staticerror_message(Message,ErrorMessage)error_message(+compound,--atom) - zero_or_oneerror_data/2
Extracts the error data from a JSON-RPC 2.0 error response. Fails if no data field is present.
staticerror_data(Message,Data)error_data(+compound,--nonvar) - zero_or_onewrite_message/2
Writes a JSON-RPC 2.0 message to an output stream as a single line of JSON followed by a newline. Flushes the output stream after writing.
staticwrite_message(Output,Message)write_message(+stream,+compound) - oneread_message/2
Reads a JSON-RPC 2.0 message from an input stream. Reads a line of JSON text and parses it. Fails at end of stream.
staticread_message(Input,Message)read_message(+stream,--compound) - zero_or_onewrite_framed_message/2
Writes a JSON-RPC 2.0 message to an output stream using Content-Length framing (as used by LSP style protocols). The message is preceded by a Content-Length: N\r\n\r\n header where N is the byte length of the JSON body. Flushes the output stream after writing.
staticwrite_framed_message(Output,Message)write_framed_message(+stream,+compound) - oneread_framed_message/2
Reads a JSON-RPC 2.0 message from an input stream using Content-Length framing (as used by LSP style protocols). Reads a Content-Length: N\r\n\r\n header followed by exactly N bytes of JSON body. Fails at end of stream or if the header is missing or malformed.
staticread_framed_message(Input,Message)read_framed_message(+stream,--compound) - zero_or_oneProtected predicates
(no local declarations; see entity ancestors if any)
Private predicates
(no local declarations; see entity ancestors if any)
Operators
(none)