From 6355144b8c3514cccc5c2ab4f7c4fd8e76a1a9fc Mon Sep 17 00:00:00 2001 From: hozan23 Date: Sun, 23 Jun 2024 15:57:43 +0200 Subject: Fix the issue with message dispatcher and channels Resolved a previous error where each subscription would create a new channel with the fixed buffer size. This caused blocking when the channel buffer was full, preventing the client from handling additional messages. Now, there is a `subscriptions` struct that holds a queue for receiving notifications, ensuring the notify function does not block. --- jsonrpc/message/message.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'jsonrpc/message') diff --git a/jsonrpc/message/message.go b/jsonrpc/message/message.go index ff68da2..b01c05d 100644 --- a/jsonrpc/message/message.go +++ b/jsonrpc/message/message.go @@ -26,7 +26,7 @@ type Request struct { type Response struct { JSONRPC string `json:"jsonrpc"` // JSON-RPC version, typically "2.0". ID *RequestID `json:"id,omitempty"` // Unique identifier matching the request ID, can be null for notifications. - Result *json.RawMessage `json:"result,omitempty"` // Result of the request if it was successful. + Result json.RawMessage `json:"result,omitempty"` // Result of the request if it was successful. Error *Error `json:"error,omitempty"` // Error object if the request failed. } @@ -34,13 +34,13 @@ type Response struct { type Notification struct { JSONRPC string `json:"jsonrpc"` // JSON-RPC version, typically "2.0". Method string `json:"method"` // The name of the method to be invoked. - Params *json.RawMessage `json:"params,omitempty"` // Optional parameters for the method. + Params json.RawMessage `json:"params,omitempty"` // Optional parameters for the method. } // NotificationResult represents the result of a subscription notification. // It includes the result and the subscription ID that triggered the notification. type NotificationResult struct { - Result *json.RawMessage `json:"result,omitempty"` // Result data of the notification. + Result json.RawMessage `json:"result,omitempty"` // Result data of the notification. Subscription SubscriptionID `json:"subscription"` // ID of the subscription that triggered the notification. } @@ -49,7 +49,7 @@ type NotificationResult struct { type Error struct { Code int `json:"code"` // Error code indicating the type of error. Message string `json:"message"` // Human-readable error message. - Data *json.RawMessage `json:"data,omitempty"` // Optional additional data about the error. + Data json.RawMessage `json:"data,omitempty"` // Optional additional data about the error. } func (req *Request) String() string { @@ -57,11 +57,11 @@ func (req *Request) String() string { } func (res *Response) String() string { - return fmt.Sprintf("{JSONRPC: %s, ID: %s, RESULT: %s, ERROR: %v}", res.JSONRPC, *res.ID, *res.Result, res.Error) + return fmt.Sprintf("{JSONRPC: %s, ID: %v, RESULT: %v, ERROR: %v}", res.JSONRPC, res.ID, res.Result, res.Error) } func (nt *Notification) String() string { - return fmt.Sprintf("{JSONRPC: %s, METHOD: %s, PARAMS: %s}", nt.JSONRPC, nt.Method, *nt.Params) + return fmt.Sprintf("{JSONRPC: %s, METHOD: %s, PARAMS: %s}", nt.JSONRPC, nt.Method, nt.Params) } func (err *Error) String() string { -- cgit v1.2.3