Merge branch 'development' of github.com:freeflowuniverse/herolib into development
* 'development' of github.com:freeflowuniverse/herolib: feat: Improve ZinitClient and JSON-RPC client
This commit is contained in:
@@ -54,7 +54,7 @@ pub fn (mut c ZinitClient) discover() !string {
|
||||
request := jsonrpc.new_request_generic('rpc.discover', []string{})
|
||||
|
||||
// Send the request and get the raw response
|
||||
raw_response := c.rpc_client.rpc_client.transport.send(request.encode(), jsonrpc.SendParams{
|
||||
raw_response := c.rpc_client.transport.send(request.encode(), jsonrpc.SendParams{
|
||||
timeout: 5 // Increase timeout to 5 seconds
|
||||
})!
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
module jsonrpc
|
||||
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
// IRPCTransportClient defines the interface for transport mechanisms used by the JSON-RPC client.
|
||||
@@ -27,11 +28,10 @@ pub:
|
||||
retry int
|
||||
}
|
||||
|
||||
|
||||
// Client implements a JSON-RPC 2.0 client that can send requests and process responses.
|
||||
// It uses a pluggable transport layer that implements the IRPCTransportClient interface.
|
||||
pub struct Client {
|
||||
mut:
|
||||
pub mut:
|
||||
// The transport implementation used to send requests and receive responses
|
||||
transport IRPCTransportClient
|
||||
}
|
||||
@@ -50,7 +50,6 @@ pub fn new_client(transport IRPCTransportClient) &Client {
|
||||
return &cl
|
||||
}
|
||||
|
||||
|
||||
// send sends a JSON-RPC request with parameters of type T and expects a response with result of type D.
|
||||
// This method handles the full request-response cycle including validation and error handling.
|
||||
//
|
||||
@@ -69,7 +68,6 @@ pub fn (mut c Client) send[T, D](request RequestGeneric[T], params SendParams) !
|
||||
console.print_debug('Sending request: ${request.encode()}')
|
||||
response_json := c.transport.send(request.encode(), params)!
|
||||
|
||||
|
||||
// Decode the response JSON into a strongly-typed response object
|
||||
response := decode_response_generic[D](response_json) or {
|
||||
return error('Unable to decode response.\n- Response: ${response_json}\n- Error: ${err}')
|
||||
|
||||
Reference in New Issue
Block a user