// Using https://www.jsonrpc.org/specification
DEFINITIONS
  "LibraryJSON.def";
  SOCKET == INTEGER;

  // connect to a ZMQ JSON-RPC socket
  EXTERNAL_FUNCTION_ZMQ_RPC_INIT == (STRING --> SOCKET);
  ZMQ_RPC_INIT(endpoint) == 0;

  EXTERNAL_SUBSTITUTION_ZMQ_RPC_DESTROY == SOCKET;
  ZMQ_RPC_DESTROY(socket) == skip;

  EXTERNAL_FUNCTION_ZMQ_RPC_SEND == (SOCKET*STRING*(STRING+->JsonValue) --> RpcResult);
  ZMQ_RPC_SEND(socket, name, args) == RpcError("");

  // connect to a regular socket (UTF-8 ndjson stream)
  EXTERNAL_FUNCTION_SOCKET_RPC_INIT == (INTEGER --> SOCKET);
  SOCKET_RPC_INIT(port) == 0;
  
  // server-side functions:
  // open socket and wait for client to connect and get request:
  EXTERNAL_FUNCTION_SOCKET_RPC_ACCEPT == (INTEGER --> JsonValue);
  SOCKET_RPC_ACCEPT(port) == JsonNull;
  // should be called after SOCKET_RPC_ACCEPT
  EXTERNAL_FUNCTION_SOCKET_RPC_REPLY == (INTEGER * RpcResult) --> BOOL;
  SOCKET_RPC_REPLY(port,rpcresult) == TRUE;
