params: Json.t
}
+type rpc_error = int * string * Json.t option (* code, message, optional_data *)
type rpc_response_payload =
| Result of Json.t
- | Error of (int * string * Json.t option) (* code, message, optional data *)
+ | Error of rpc_error
type rpc_response =
{
| Error e -> error_to_json resp.response_id e
let response_to_string resp = Json.to_string (response_to_json resp)
+
+
+type rpc_type =
+ | Non_JSONRPC
+ | Request of (* id *) Json.t * rpc_request
+ | Notification of rpc_request
+ | Response of rpc_response
+
+let rpc_type_of_json j =
+ (* First try request/notification. *)
+ try
+ let req = request_of_json j in
+ match req.request_id with
+ | None -> Notification req
+ | Some id -> Request (id, req)
+ with _ ->
+ (* Next, try a response. *)
+ try
+ Response (response_of_json j)
+ with _ ->
+ Non_JSONRPC
params : Json.t;
}
+type rpc_error = int * string * Json.t option (* code, message, optional_data *)
type rpc_response_payload =
| Result of Json.t
- | Error of (int * string * Json.t option) (* code, message, optional_data *)
+ | Error of rpc_error
type rpc_response =
{
val request_to_string: rpc_request -> string
val response_of_string: string -> rpc_response
val response_to_string: rpc_response -> string
+
+(* determine what type of jsonrpc object a json value is *)
+type rpc_type =
+ | Non_JSONRPC
+ | Request of (* id *) Json.t * rpc_request
+ | Notification of rpc_request
+ | Response of rpc_response
+
+val rpc_type_of_json: Json.t -> rpc_type