Skip to content

Commit ca8f6a3

Browse files
committed
jsonrpc2: implements Conn.Notify method
1 parent b29af9b commit ca8f6a3

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

jsonrpc2.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,28 @@ func (c *Conn) Reply(ctx context.Context, req *Request, result interface{}, err
264264
}
265265

266266
// Notify is called to send a notification request over the connection.
267-
func (c *Conn) Notify(ctx context.Context, method string, params interface{}) error { return nil }
267+
func (c *Conn) Notify(ctx context.Context, method string, params interface{}) error {
268+
jsonParams, err := marshalToEmbedded(params)
269+
if err != nil {
270+
return xerrors.Errorf("failed to marshalling notify parameters: %v", err)
271+
}
272+
273+
req := &NotificationMessage{
274+
Method: method,
275+
Params: jsonParams,
276+
}
277+
data, err := gojay.MarshalJSONObject(req)
278+
if err != nil {
279+
return xerrors.Errorf("failed to marshalling notify request: %v", err)
280+
}
281+
282+
c.logger.Info(Send.String(),
283+
zap.String("req.Method", req.Method),
284+
zap.Any("req.Params", req.Params),
285+
)
286+
287+
return c.stream.Write(ctx, data)
288+
}
268289

269290
// Cancel cancels a pending Call on the server side.
270291
func (c *Conn) Cancel(id ID) {}

0 commit comments

Comments
 (0)