@@ -7,8 +7,8 @@ package jsonrpc2
7
7
import (
8
8
"encoding/json"
9
9
"errors"
10
- "io"
11
10
"strconv"
11
+ "unsafe"
12
12
13
13
"github.com/francoispqt/gojay"
14
14
)
@@ -56,51 +56,62 @@ func (id *ID) UnmarshalJSON(data []byte) error {
56
56
return json .Unmarshal (data , & id .Name )
57
57
}
58
58
59
- // RawMessage is the same as json.RawMessage.
59
+ // RawMessage mimic json.RawMessage
60
+ // RawMessage is a raw encoded JSON value.
61
+ // It implements Marshaler and Unmarshaler and can
62
+ // be used to delay JSON decoding or precompute a JSON encoding.
60
63
type RawMessage gojay.EmbeddedJSON
61
64
62
- var _ io.Reader = (* RawMessage )(nil )
63
- var _ json.Marshaler = (* RawMessage )(nil )
64
- var _ json.Unmarshaler = (* RawMessage )(nil )
65
-
66
- // Read implements io.Reader.
67
- func (m * RawMessage ) Read (p []byte ) (n int , err error ) {
68
- if len (p ) == 0 || p == nil {
69
- return 0 , nil
70
- }
65
+ func (m RawMessage ) String () string {
71
66
if m == nil {
72
- return 0 , io . EOF
67
+ return ""
73
68
}
74
69
75
- n = copy (p , * m )
76
-
77
- return n , nil
70
+ return * (* string )(unsafe .Pointer (& m ))
78
71
}
79
72
73
+ // Read implements io.Reader.
74
+ // func (m *RawMessage) Read(p []byte) (n int, err error) {
75
+ // if len(p) == 0 || p == nil {
76
+ // return 0, nil
77
+ // }
78
+ // if m == nil {
79
+ // return 0, io.EOF
80
+ // }
81
+ //
82
+ // n = copy(p, *m)
83
+ //
84
+ // return n, nil
85
+ // }
86
+
80
87
// MarshalJSON implements json.Marshaler.
81
88
//
82
- // MarshalJSON returns m as the JSON encoding of m.
89
+ // The returns m as the JSON encoding of m.
83
90
func (m RawMessage ) MarshalJSON () ([]byte , error ) {
84
- if & m == nil {
85
- return []byte ( "null" ), nil
91
+ if m == nil {
92
+ return []byte { 110 , 117 , 108 , 108 }, nil // null
86
93
}
87
94
88
95
return m , nil
89
96
}
90
97
91
98
// UnmarshalJSON implements json.Unmarshaler.
92
99
//
93
- // UnmarshalJSON sets *m to a copy of data.
100
+ // The sets *m to a copy of data.
94
101
func (m * RawMessage ) UnmarshalJSON (data []byte ) error {
95
102
if m == nil {
96
- return errors .New ("json .RawMessage: UnmarshalJSON on nil pointer" )
103
+ return errors .New ("jsonrpc2 .RawMessage: UnmarshalJSON on nil pointer" )
97
104
}
98
105
99
106
* m = append ((* m )[0 :0 ], data ... )
100
107
101
108
return nil
102
109
}
103
110
111
+ // var _ io.Reader = (*RawMessage)(nil)
112
+ var _ json.Marshaler = (* RawMessage )(nil )
113
+ var _ json.Unmarshaler = (* RawMessage )(nil )
114
+
104
115
// Request is a request message to describe a request between the client and the server.
105
116
//
106
117
// Every processed request must send a response back to the sender of the request.
0 commit comments