-
Notifications
You must be signed in to change notification settings - Fork 0
/
json_codec.go
55 lines (41 loc) · 1.66 KB
/
json_codec.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
package jrpc2server
import (
"encoding/json"
"github.com/riftbit/jrpc2errors"
)
var null = json.RawMessage([]byte("null"))
// Version is JSON RPC version that allowed to use
var Version = "2.0"
// ----------------------------------------------------------------------------
// Request and Response
// ----------------------------------------------------------------------------
// ServerRequest represents a JSON-RPC request received by the server.
type ServerRequest struct {
// JSON-RPC protocol.
Version string `json:"jsonrpc"`
// A String containing the name of the method to be invoked.
Method string `json:"method"`
// A Structured value to pass as arguments to the method.
Params *json.RawMessage `json:"params"`
// The request id. MUST be a string, number or null.
// Our implementation will not do type checking for id.
// It will be copied as it is.
ID *json.RawMessage `json:"id"`
}
// ServerResponse represents a JSON-RPC response returned by the server.
type ServerResponse struct {
// JSON-RPC protocol.
Version string `json:"jsonrpc"`
// The Object that was returned by the invoked method. This must be null
// in case there was an error invoking the method.
// As per spec the member will be omitted if there was an error.
Result interface{} `json:"result,omitempty"`
// An Error object if there was an error invoking the method. It must be
// null if there was no error.
// As per spec the member will be omitted if there was no error.
Error *jrpc2errors.Error `json:"error,omitempty"`
// This must be the same id as the request it is responding to.
ID *json.RawMessage `json:"id"`
}
// EmptyResponse empty response
type EmptyResponse struct{}