-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsonrpc.r
67 lines (43 loc) · 1.61 KB
/
jsonrpc.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# jsonrpc.R -
# Created on 18/12/2013
# Modified on 05/03/2014
# @author: sgonzalez
library("rjson");
JSONRPC.Protocol <- function(){
return("2.0");
}
JSONRPC.SuccessResponse <- function(m,p,id=1){
msg <- list(jsonrpc=JSONRPC.Protocol(),id=id,method=m,params=p);
return(toJSON(msg));
}
JSONRPC.SuccessResponse <- function(r,id=1){
msg <- list(jsonrpc=JSONRPC.Protocol(),id=id,result=r);
return(toJSON(msg));
}
JSONRPC.InvalidRequestError <- function(...){
return(list(code=-32600,message="Invalid Request"));
}
JSONRPC.MethodNotFoundError <- function(...){
return(list(code=-32601,message="Method not found"));
}
JSONRPC.InvalidParamsError <- function(...){
return(list(code=-32602,message="Invalid Params"));
}
JSONRPC.InternalError <- function(...){
return(list(code=-32603,message="Internal Error"));
}
JSONRPC.ServerError <- function(...){
return(list(code=-32000,message=""));
}
JSONRPC.SpecificError <- function(info){
return(list(code=info.code,message=info.message));
}
JSONRPC.ErrorResponse <- function(f,info,id=1){
datos <- do.call(f,info);
msg <- list(jsonrpc=JSONRPC.Protocol(),id=id,error=datos);
return(toJSON(msg));
}
JSONRPC.Request <- function(m,p,id=1){
msg <- list(jsonrpc=JSONRPC.Protocol(),id=id,method=m,params=p);
return(toJSON(msg));
}