@@ -153,17 +153,16 @@ func NewConn(ctx context.Context, s Stream, options ...Options) *Conn {
153
153
154
154
// Call sends a request over the connection and then waits for a response.
155
155
func (c * Conn ) Call (ctx context.Context , method string , params , result interface {}) error {
156
- rawdata , err := gojay . Marshal (params )
156
+ jsonParams , err := marshalToEmbedded (params )
157
157
if err != nil {
158
158
return xerrors .Errorf ("failed to marshalling call parameters: %v" , err )
159
159
}
160
- jsonParams := gojay .EmbeddedJSON (rawdata )
161
160
id := ID {Number : c .seq .Add (1 )}
162
161
163
162
req := & Request {
164
163
ID : & id ,
165
164
Method : method ,
166
- Params : & jsonParams ,
165
+ Params : jsonParams ,
167
166
}
168
167
169
168
// marshal the request now it is complete
@@ -231,18 +230,14 @@ func (c *Conn) Reply(ctx context.Context, req *Request, result interface{}, err
231
230
}
232
231
233
232
elapsed := time .Since (handling .start )
234
- var jsonParams gojay.EmbeddedJSON
233
+ var jsonParams * gojay.EmbeddedJSON
235
234
if err == nil {
236
- rawdata , err := gojay .Marshal (result )
237
- if err != nil {
238
- return xerrors .Errorf ("failed to marshalling call parameters: %v" , err )
239
- }
240
- jsonParams = gojay .EmbeddedJSON (rawdata )
235
+ jsonParams , err = marshalToEmbedded (result )
241
236
}
242
237
243
238
resp := & Response {
244
239
ID : req .ID ,
245
- Result : & jsonParams ,
240
+ Result : jsonParams ,
246
241
}
247
242
248
243
if err != nil {
@@ -301,3 +296,13 @@ func (d Direction) String() string {
301
296
panic ("unreachable" )
302
297
}
303
298
}
299
+
300
+ func marshalToEmbedded (obj interface {}) (* gojay.EmbeddedJSON , error ) {
301
+ data , err := gojay .Marshal (obj )
302
+ if err != nil {
303
+ return nil , err
304
+ }
305
+ raw := gojay .EmbeddedJSON (data )
306
+
307
+ return & raw , nil
308
+ }
0 commit comments