@@ -6,6 +6,12 @@ package jsonrpc2
6
6
7
7
import (
8
8
"strconv"
9
+
10
+ jsoniter "github.com/json-iterator/go"
11
+ )
12
+
13
+ var (
14
+ json = jsoniter .ConfigFastest
9
15
)
10
16
11
17
// ID is a Request identifier.
@@ -29,29 +35,30 @@ func (id *ID) String() string {
29
35
return "#" + strconv .FormatInt (id .Number , 10 )
30
36
}
31
37
32
- // // MarshalJSON implements json.MarshalJSON.
33
- // func (id *ID) MarshalJSON() ([]byte, error) {
34
- // if id.Name != "" {
35
- // return json.Marshal(id.Name)
36
- // }
37
- // return json.Marshal(id.Number)
38
- // }
39
- //
40
- // // MarshalJSON implements json.UnmarshalJSON.
41
- // func (id *ID) UnmarshalJSON(data []byte) error {
42
- // *id = ID{}
43
- // if err := json.Unmarshal(data, &id.Number); err == nil {
44
- // return nil
45
- // }
46
- // return json.Unmarshal(data, &id.Name)
47
- // }
38
+ // MarshalJSON implements json.MarshalJSON.
39
+ func (id * ID ) MarshalJSON () ([]byte , error ) {
40
+ if id .Name != "" {
41
+ return json .Marshal (id .Name )
42
+ }
43
+ return json .Marshal (id .Number )
44
+ }
45
+
46
+ // MarshalJSON implements json.UnmarshalJSON.
47
+ func (id * ID ) UnmarshalJSON (data []byte ) error {
48
+ * id = ID {}
49
+ if err := json .Unmarshal (data , & id .Number ); err == nil {
50
+ return nil
51
+ }
52
+ return json .Unmarshal (data , & id .Name )
53
+ }
48
54
49
55
// Message is a general message as defined by JSON-RPC. The language server protocol always uses "2.0" as the jsonrpc version.
50
56
type Message struct {
51
57
JSONRPC string `json:"jsonrpc"`
52
58
}
53
59
54
60
// Request is a request message to describe a request between the client and the server.
61
+ //
55
62
// Every processed request must send a response back to the sender of the request.
56
63
type Request struct {
57
64
Message
@@ -72,6 +79,7 @@ func (r *Request) IsNotify() bool {
72
79
}
73
80
74
81
// Response is a response ressage sent as a result of a request.
82
+ //
75
83
// If a request doesn't provide a result value the receiver of a request still needs to return a response message to
76
84
// conform to the JSON RPC specification.
77
85
// The result property of the ResponseMessage should be set to null in this case to signal a successful request.
@@ -89,6 +97,9 @@ type Response struct {
89
97
Result []byte `json:"result,omitempty"`
90
98
}
91
99
100
+ // NotificationMessage is a notification message.
101
+ //
102
+ // A processed notification message must not send a response back. They work like events.
92
103
type NotificationMessage struct {
93
104
Message
94
105
0 commit comments