Skip to content

Commit b6c8d2c

Browse files
committed
jsonrpc2,types: rename request and Response to add wire prefix
1 parent faf38d5 commit b6c8d2c

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

jsonrpc2.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ type Conn struct {
6767
RejectIfOverloaded bool
6868
stream Stream
6969
err error
70-
pending map[ID]chan *Response
70+
pending map[ID]chan *wireResponse
7171
pendingMu sync.Mutex // protects the pending map
7272
handling map[ID]*Request
7373
handlingMu sync.Mutex // protects the handling map
@@ -157,7 +157,7 @@ func NewConn(s Stream, options ...Options) *Conn {
157157
conn := &Conn{
158158
seq: new(atomic.Int64),
159159
stream: s,
160-
pending: make(map[ID]chan *Response),
160+
pending: make(map[ID]chan *wireResponse),
161161
handling: make(map[ID]*Request),
162162
}
163163

@@ -233,7 +233,7 @@ func (c *Conn) Call(ctx context.Context, method string, params, result interface
233233
}
234234

235235
id := ID{Number: c.seq.Add(1)}
236-
req := &request{
236+
req := &wireRequest{
237237
JSONRPC: Version,
238238
ID: &id,
239239
Method: method,
@@ -246,7 +246,7 @@ func (c *Conn) Call(ctx context.Context, method string, params, result interface
246246
return Errorf(ParseError, "failed to marshaling call request: %v", err)
247247
}
248248

249-
rchan := make(chan *Response)
249+
rchan := make(chan *wireResponse)
250250

251251
c.pendingMu.Lock()
252252
c.pending[id] = rchan
@@ -352,7 +352,7 @@ func (r *Request) Reply(ctx context.Context, result interface{}, err error) erro
352352
raw, err = marshalInterface(result)
353353
}
354354

355-
resp := &Response{
355+
resp := &wireResponse{
356356
JSONRPC: Version,
357357
Result: raw,
358358
ID: r.ID,
@@ -482,7 +482,7 @@ func (c *Conn) Run(ctx context.Context) (err error) {
482482
c.pendingMu.Unlock()
483483

484484
// send the reply to the channel
485-
resp := &Response{
485+
resp := &wireResponse{
486486
JSONRPC: Version,
487487
Result: msg.Result,
488488
Error: msg.Error,

types.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ func (id *ID) UnmarshalJSON(data []byte) error {
5858
var _ json.Marshaler = (*ID)(nil)
5959
var _ json.Unmarshaler = (*ID)(nil)
6060

61-
// request represents a rpc call by sending a request object to a Server.
61+
// wireRequest represents a rpc call by sending a request object to a Server.
6262
// This is a request message to describe a request between the client and the server.
6363
//
6464
// Every processed request must send a response back to the sender of the request.
65-
type request struct {
65+
type wireRequest struct {
6666
// JSONRPC is a string specifying the version of the JSON-RPC protocol.
6767
//
6868
// MUST be exactly "2.0".
@@ -88,18 +88,13 @@ type request struct {
8888
ID *ID `json:"id"`
8989
}
9090

91-
// IsNotify returns true if this request is a notification.
92-
func (r *request) IsNotify() bool {
93-
return r.ID == nil
94-
}
95-
96-
// Response is a response ressage sent as a result of a request.
91+
// wireResponse is a response ressage sent as a result of a request.
9792
// When a rpc call is made, the Server MUST reply with a Response, except for in the case of Notifications.
9893
//
9994
// If a request doesn't provide a result value the receiver of a request still needs to return a response message to
10095
// conform to the JSON RPC specification.
10196
// The result property of the ResponseMessage should be set to null in this case to signal a successful request.
102-
type Response struct {
97+
type wireResponse struct {
10398
// JSONRPC is a string specifying the version of the JSON-RPC protocol.
10499
//
105100
// MUST be exactly "2.0".

types_gojay.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var _ json.Marshaler = (*RawMessage)(nil)
5757
var _ json.Unmarshaler = (*RawMessage)(nil)
5858

5959
// UnmarshalJSONObject implements gojay's UnmarshalerJSONObject
60-
func (v *request) UnmarshalJSONObject(dec *gojay.Decoder, k string) error {
60+
func (v *wireRequest) UnmarshalJSONObject(dec *gojay.Decoder, k string) error {
6161
switch k {
6262
case keyJSONRPC:
6363
return dec.String(&v.JSONRPC)
@@ -76,21 +76,21 @@ func (v *request) UnmarshalJSONObject(dec *gojay.Decoder, k string) error {
7676
}
7777

7878
// NKeys returns the number of keys to unmarshal
79-
func (v *request) NKeys() int { return 4 }
79+
func (v *wireRequest) NKeys() int { return 4 }
8080

8181
// MarshalJSONObject implements gojay's MarshalerJSONObject
82-
func (v *request) MarshalJSONObject(enc *gojay.Encoder) {
82+
func (v *wireRequest) MarshalJSONObject(enc *gojay.Encoder) {
8383
enc.StringKey(keyJSONRPC, v.JSONRPC)
8484
enc.StringKey(keyID, v.ID.String())
8585
enc.StringKey(keyMethod, v.Method)
8686
enc.AddEmbeddedJSONKeyOmitEmpty(keyParams, (*gojay.EmbeddedJSON)(v.Params))
8787
}
8888

8989
// IsNil returns wether the structure is nil value or not
90-
func (v *request) IsNil() bool { return v == nil }
90+
func (v *wireRequest) IsNil() bool { return v == nil }
9191

9292
// UnmarshalJSONObject implements gojay's UnmarshalerJSONObject
93-
func (v *Response) UnmarshalJSONObject(dec *gojay.Decoder, k string) error {
93+
func (v *wireResponse) UnmarshalJSONObject(dec *gojay.Decoder, k string) error {
9494
switch k {
9595
case keyJSONRPC:
9696
return dec.String(&v.JSONRPC)
@@ -112,18 +112,18 @@ func (v *Response) UnmarshalJSONObject(dec *gojay.Decoder, k string) error {
112112
}
113113

114114
// NKeys returns the number of keys to unmarshal
115-
func (v *Response) NKeys() int { return 4 }
115+
func (v *wireResponse) NKeys() int { return 4 }
116116

117117
// MarshalJSONObject implements gojay's MarshalerJSONObject
118-
func (v *Response) MarshalJSONObject(enc *gojay.Encoder) {
118+
func (v *wireResponse) MarshalJSONObject(enc *gojay.Encoder) {
119119
enc.StringKey(keyJSONRPC, v.JSONRPC)
120120
enc.StringKey(keyID, v.ID.String())
121121
enc.ObjectKeyOmitEmpty(keyError, v.Error)
122122
enc.AddEmbeddedJSONKeyOmitEmpty(keyResult, (*gojay.EmbeddedJSON)(v.Result))
123123
}
124124

125125
// IsNil returns wether the structure is nil value or not
126-
func (v *Response) IsNil() bool { return v == nil }
126+
func (v *wireResponse) IsNil() bool { return v == nil }
127127

128128
// UnmarshalJSONObject implements gojay's UnmarshalerJSONObject
129129
func (v *Combined) UnmarshalJSONObject(dec *gojay.Decoder, k string) error {

0 commit comments

Comments
 (0)