-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsonrpc_types.go
175 lines (172 loc) · 16.3 KB
/
jsonrpc_types.go
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package jsonrpc_types
import "encoding/json"
import "errors"
// If it is not included it is assumed to be a notification. The Server MUST reply with the same value in the Response object if included. This member is used to correlate the context between the two objects.
type JSONRPCRequestIdAsString string
// If it is not included it is assumed to be a notification. The Server MUST reply with the same value in the Response object if included. This member is used to correlate the context between the two objects.
type JSONRPCRequestIdAsNumber float64
// If it is not included it is assumed to be a notification. The Server MUST reply with the same value in the Response object if included. This member is used to correlate the context between the two objects.
type JSONRPCRequestIdAsNull interface{}
// If it is not included it is assumed to be a notification. The Server MUST reply with the same value in the Response object if included. This member is used to correlate the context between the two objects.
type JSONRPCRequestId struct {
JSONRPCRequestIdAsString *JSONRPCRequestIdAsString
JSONRPCRequestIdAsNumber *JSONRPCRequestIdAsNumber
JSONRPCRequestIdAsNull *JSONRPCRequestIdAsNull
}
// UnmarshalJSON implements the json Unmarshaler interface.
// This implementation DOES NOT assert that ONE AND ONLY ONE
// of the simple properties is satisfied; it lazily uses the first one that is satisfied.
// Ergo, it will not return an error if more than one property is valid.
func (o *JSONRPCRequestId) UnmarshalJSON(bytes []byte) error {
var myJSONRPCRequestIdAsString JSONRPCRequestIdAsString
if err := json.Unmarshal(bytes, &myJSONRPCRequestIdAsString); err == nil {
o.JSONRPCRequestIdAsString = &myJSONRPCRequestIdAsString
return nil
}
var myJSONRPCRequestIdAsNumber JSONRPCRequestIdAsNumber
if err := json.Unmarshal(bytes, &myJSONRPCRequestIdAsNumber); err == nil {
o.JSONRPCRequestIdAsNumber = &myJSONRPCRequestIdAsNumber
return nil
}
var myJSONRPCRequestIdAsNull JSONRPCRequestIdAsNull
if err := json.Unmarshal(bytes, &myJSONRPCRequestIdAsNull); err == nil {
o.JSONRPCRequestIdAsNull = &myJSONRPCRequestIdAsNull
return nil
}
return errors.New("failed to unmarshal one of the object properties")
}
func (o JSONRPCRequestId) MarshalJSON() ([]byte, error) {
if o.JSONRPCRequestIdAsString != nil {
return json.Marshal(o.JSONRPCRequestIdAsString)
}
if o.JSONRPCRequestIdAsNumber != nil {
return json.Marshal(o.JSONRPCRequestIdAsNumber)
}
if o.JSONRPCRequestIdAsNull != nil {
return json.Marshal(o.JSONRPCRequestIdAsNull)
}
return nil, errors.New("failed to marshal any one of the object properties")
}
// A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0".
type JSONRPCVersion string
// A String containing the name of the method to be invoked. Method names that begin with the word rpc followed by a period character (U+002E or ASCII 46) are reserved for rpc-internal methods and extensions and MUST NOT be used for anything else.
type JSONRPCMethod string
// Parameters literal value as provided to the invocation of the method.
type JSONRPCParamValue interface{}
// by-position: params MUST be an Array, containing the values in the Server expected order.
type JSONRPCParamsByPosition []JSONRPCParamValue
// by-name: params MUST be an Object, with member names that match the Server expected parameter names. The absence of expected names MAY result in an error being generated. The names MUST match exactly, including case, to the method's expected parameters.
type JSONRPCParamsByName map[string]interface{}
// A Structured value that holds the parameter values to be used during the invocation of the method. This member MAY be omitted.
type JSONRPCParams struct {
JSONRPCParamsByPosition *JSONRPCParamsByPosition
JSONRPCParamsByName *JSONRPCParamsByName
}
// UnmarshalJSON implements the json Unmarshaler interface.
// This implementation DOES NOT assert that ONE AND ONLY ONE
// of the simple properties is satisfied; it lazily uses the first one that is satisfied.
// Ergo, it will not return an error if more than one property is valid.
func (o *JSONRPCParams) UnmarshalJSON(bytes []byte) error {
var myJSONRPCParamsByPosition JSONRPCParamsByPosition
if err := json.Unmarshal(bytes, &myJSONRPCParamsByPosition); err == nil {
o.JSONRPCParamsByPosition = &myJSONRPCParamsByPosition
return nil
}
var myJSONRPCParamsByName JSONRPCParamsByName
if err := json.Unmarshal(bytes, &myJSONRPCParamsByName); err == nil {
o.JSONRPCParamsByName = &myJSONRPCParamsByName
return nil
}
return errors.New("failed to unmarshal one of the object properties")
}
func (o JSONRPCParams) MarshalJSON() ([]byte, error) {
if o.JSONRPCParamsByPosition != nil {
return json.Marshal(o.JSONRPCParamsByPosition)
}
if o.JSONRPCParamsByName != nil {
return json.Marshal(o.JSONRPCParamsByName)
}
return nil, errors.New("failed to marshal any one of the object properties")
}
// A rpc call is represented by sending a Request object to a Server.
type JSONRPCRequest struct {
Id *JSONRPCRequestId `json:"id,omitempty"`
Jsonrpc *JSONRPCVersion `json:"jsonrpc"`
Method *JSONRPCMethod `json:"method"`
Params *JSONRPCParams `json:"params,omitempty"`
}
// A Number that indicates the error type that occurred. The error codes from and including -32768 to -32000 are reserved for pre-defined errors. Any code within this range, but not defined explicitly below is reserved for future use. The error codes are nearly the same as those suggested for XML-RPC at the [following url](http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php)
type JSONRPCErrorCode int64
// A String providing a short description of the error. The message SHOULD be limited to a concise single sentence.
type JSONRPCErrorMessage string
// A Primitive or Structured value that contains additional information about the error. This may be omitted. The value of this member is defined by the Server (e.g. detailed error information, nested errors etc.).
type JSONRPCErrorData interface{}
// When a rpc call encounters an error, the Response Object MUST contain the error member with a value that is a Object.
type JSONRPCError struct {
Code *JSONRPCErrorCode `json:"code,omitempty"`
Message *JSONRPCErrorMessage `json:"message,omitempty"`
Data *JSONRPCErrorData `json:"data,omitempty"`
}
// This member is REQUIRED on success. This member MUST NOT exist if there was an error invoking the method. The value of this member is determined by the method invoked on the Server.
type JSONRPCResponseResult interface{}
// When a rpc call is made, the Server MUST reply with a Response, except for in the case of Notifications. The Response is expressed as a single JSON Object,
type JSONRPCResponse struct {
Id *JSONRPCRequestId `json:"id"`
Jsonrpc *JSONRPCVersion `json:"jsonrpc"`
Error *JSONRPCError `json:"error,omitempty"`
Result *JSONRPCResponseResult `json:"result,omitempty"`
}
// To send several Request objects at the same time, the Client MAY send an Array filled with Request objects. The Client SHOULD match contexts between the set of Request objects and the resulting set of Response objects based on the id member within each Object.
type JSONRPCBatchRequest []JSONRPCRequest
// The Server should respond with an Array containing the corresponding Response objects, after all of the batch Request objects have been processed. A Response object SHOULD exist for each Request object, except that there SHOULD NOT be any Response objects for notifications. The Server MAY process a batch rpc call as a set of concurrent tasks, processing them in any order and with any width of parallelism. The Response objects being returned from a batch call MAY be returned in any order within the Array. If the batch rpc call itself fails to be recognized as an valid JSON or as an Array with at least one value, the response from the Server MUST be a single Response object. If there are no Response objects contained within the Response array as it is to be sent to the client, the server MUST NOT return an empty Array and should return nothing at all.
type JSONRPCBatchResponse []JSONRPCResponse
// Either a (possibly batch of) JSON-RPC request(s) and response(s)
type JSONRPCTypes struct {
JSONRPCRequest *JSONRPCRequest
JSONRPCResponse *JSONRPCResponse
JSONRPCBatchRequest *JSONRPCBatchRequest
JSONRPCBatchResponse *JSONRPCBatchResponse
}
// UnmarshalJSON implements the json Unmarshaler interface.
// This implementation DOES NOT assert that ONE AND ONLY ONE
// of the simple properties is satisfied; it lazily uses the first one that is satisfied.
// Ergo, it will not return an error if more than one property is valid.
func (o *JSONRPCTypes) UnmarshalJSON(bytes []byte) error {
var myJSONRPCRequest JSONRPCRequest
if err := json.Unmarshal(bytes, &myJSONRPCRequest); err == nil {
o.JSONRPCRequest = &myJSONRPCRequest
return nil
}
var myJSONRPCResponse JSONRPCResponse
if err := json.Unmarshal(bytes, &myJSONRPCResponse); err == nil {
o.JSONRPCResponse = &myJSONRPCResponse
return nil
}
var myJSONRPCBatchRequest JSONRPCBatchRequest
if err := json.Unmarshal(bytes, &myJSONRPCBatchRequest); err == nil {
o.JSONRPCBatchRequest = &myJSONRPCBatchRequest
return nil
}
var myJSONRPCBatchResponse JSONRPCBatchResponse
if err := json.Unmarshal(bytes, &myJSONRPCBatchResponse); err == nil {
o.JSONRPCBatchResponse = &myJSONRPCBatchResponse
return nil
}
return errors.New("failed to unmarshal one of the object properties")
}
func (o JSONRPCTypes) MarshalJSON() ([]byte, error) {
if o.JSONRPCRequest != nil {
return json.Marshal(o.JSONRPCRequest)
}
if o.JSONRPCResponse != nil {
return json.Marshal(o.JSONRPCResponse)
}
if o.JSONRPCBatchRequest != nil {
return json.Marshal(o.JSONRPCBatchRequest)
}
if o.JSONRPCBatchResponse != nil {
return json.Marshal(o.JSONRPCBatchResponse)
}
return nil, errors.New("failed to marshal any one of the object properties")
}
const RawJsonrpc_types = "{\"$schema\":\"https://meta.json-schema.tools\",\"$id\":\"https://meta.jsonrpc.net/\",\"title\":\"JSONRPCTypes\",\"description\":\"Either a (possibly batch of) JSON-RPC request(s) and response(s)\",\"oneOf\":[{\"$ref\":\"#/definitions/JSONRPCRequest\"},{\"$ref\":\"#/definitions/JSONRPCResponse\"},{\"$ref\":\"#/definitions/JSONRPCBatchRequest\"},{\"$ref\":\"#/definitions/JSONRPCBatchResponse\"}],\"definitions\":{\"JSONRPCBatchRequest\":{\"title\":\"JSONRPCBatchRequest\",\"description\":\"To send several Request objects at the same time, the Client MAY send an Array filled with Request objects. The Client SHOULD match contexts between the set of Request objects and the resulting set of Response objects based on the id member within each Object.\",\"type\":\"array\",\"items\":{\"$ref\":\"#/definitions/JSONRPCRequest\"}},\"JSONRPCBatchResponse\":{\"title\":\"JSONRPCBatchResponse\",\"description\":\"The Server should respond with an Array containing the corresponding Response objects, after all of the batch Request objects have been processed. A Response object SHOULD exist for each Request object, except that there SHOULD NOT be any Response objects for notifications. The Server MAY process a batch rpc call as a set of concurrent tasks, processing them in any order and with any width of parallelism. The Response objects being returned from a batch call MAY be returned in any order within the Array. If the batch rpc call itself fails to be recognized as an valid JSON or as an Array with at least one value, the response from the Server MUST be a single Response object. If there are no Response objects contained within the Response array as it is to be sent to the client, the server MUST NOT return an empty Array and should return nothing at all.\",\"type\":\"array\",\"items\":{\"$ref\":\"#/definitions/JSONRPCResponse\"}},\"JSONRPCId\":{\"title\":\"JSONRPCId\",\"description\":\"An identifier established by the Client that MUST contain a String, Number, or NULL value if included. The value SHOULD normally not be Null (The use of Null as a value for the id member in a Request object is discouraged, because this specification uses a value of Null for Responses with an unknown id. Also, because JSON-RPC 1.0 uses an id value of Null for Notifications this could cause confusion in handling.) and Numbers SHOULD NOT contain fractional parts (Fractional parts may be problematic, since many decimal fractions cannot be represented exactly as binary fractions.)\",\"type\":[\"string\",\"number\",\"null\"]},\"JSONRPCVersion\":{\"title\":\"JSONRPCVersion\",\"description\":\"A String specifying the version of the JSON-RPC protocol. MUST be exactly \\"2.0\\".\",\"type\":\"string\",\"const\":\"2.0\"},\"JSONRPCParamValue\":{\"title\":\"JSONRPCParamValue\",\"description\":\"Parameters literal value as provided to the invocation of the method.\"},\"JSONRPCRequest\":{\"title\":\"JSONRPCRequest\",\"description\":\"A rpc call is represented by sending a Request object to a Server.\",\"type\":\"object\",\"required\":[\"jsonrpc\",\"method\"],\"properties\":{\"id\":{\"title\":\"JSONRPCRequestId\",\"description\":\"If it is not included it is assumed to be a notification. The Server MUST reply with the same value in the Response object if included. This member is used to correlate the context between the two objects.\",\"$ref\":\"#/definitions/JSONRPCId\"},\"jsonrpc\":{\"$ref\":\"#/definitions/JSONRPCVersion\"},\"method\":{\"title\":\"JSONRPCMethod\",\"description\":\"A String containing the name of the method to be invoked. Method names that begin with the word rpc followed by a period character (U+002E or ASCII 46) are reserved for rpc-internal methods and extensions and MUST NOT be used for anything else.\",\"type\":\"string\"},\"params\":{\"title\":\"JSONRPCParams\",\"description\":\"A Structured value that holds the parameter values to be used during the invocation of the method. This member MAY be omitted.\",\"oneOf\":[{\"title\":\"JSONRPCParamsByPosition\",\"description\":\"by-position: params MUST be an Array, containing the values in the Server expected order.\",\"type\":\"array\",\"items\":{\"$ref\":\"#/definitions/JSONRPCParamValue\"}},{\"title\":\"JSONRPCParamsByName\",\"description\":\"by-name: params MUST be an Object, with member names that match the Server expected parameter names. The absence of expected names MAY result in an error being generated. The names MUST match exactly, including case, to the method's expected parameters.\",\"type\":\"object\",\"additionalProperties\":{\"$ref\":\"#/definitions/JSONRPCParamValue\"}}]}}},\"JSONRPCResponse\":{\"title\":\"JSONRPCResponse\",\"description\":\"When a rpc call is made, the Server MUST reply with a Response, except for in the case of Notifications. The Response is expressed as a single JSON Object,\",\"type\":\"object\",\"required\":[\"id\",\"jsonrpc\"],\"properties\":{\"id\":{\"title\":\"JSONRPCRequestId\",\"description\":\"If it is not included it is assumed to be a notification. The Server MUST reply with the same value in the Response object if included. This member is used to correlate the context between the two objects.\",\"$ref\":\"#/definitions/JSONRPCId\"},\"jsonrpc\":{\"$ref\":\"#/definitions/JSONRPCVersion\"},\"error\":{\"title\":\"JSONRPCError\",\"description\":\"When a rpc call encounters an error, the Response Object MUST contain the error member with a value that is a Object.\",\"type\":\"object\",\"properties\":{\"code\":{\"title\":\"JSONRPCErrorCode\",\"description\":\"A Number that indicates the error type that occurred. The error codes from and including -32768 to -32000 are reserved for pre-defined errors. Any code within this range, but not defined explicitly below is reserved for future use. The error codes are nearly the same as those suggested for XML-RPC at the [following url](http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php)\",\"type\":\"integer\"},\"message\":{\"title\":\"JSONRPCErrorMessage\",\"description\":\"A String providing a short description of the error. The message SHOULD be limited to a concise single sentence.\",\"type\":\"string\"},\"data\":{\"title\":\"JSONRPCErrorData\",\"description\":\"A Primitive or Structured value that contains additional information about the error. This may be omitted. The value of this member is defined by the Server (e.g. detailed error information, nested errors etc.).\"}}},\"result\":{\"title\":\"JSONRPCResponseResult\",\"description\":\"This member is REQUIRED on success. This member MUST NOT exist if there was an error invoking the method. The value of this member is determined by the method invoked on the Server.\"}}}}}"