From 19c4e8477470ea1ed3654ffc67f544112f4d7e9e Mon Sep 17 00:00:00 2001 From: LPeter1997 Date: Sat, 30 Sep 2023 19:31:55 +0200 Subject: [PATCH] Update JsonRpcConnection.cs --- src/Draco.JsonRpc/JsonRpcConnection.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Draco.JsonRpc/JsonRpcConnection.cs b/src/Draco.JsonRpc/JsonRpcConnection.cs index 2b6f637e37..418c6fe1a2 100644 --- a/src/Draco.JsonRpc/JsonRpcConnection.cs +++ b/src/Draco.JsonRpc/JsonRpcConnection.cs @@ -40,9 +40,22 @@ public abstract class JsonRpcConnection private readonly CancellationTokenSource shutdownTokenSource = new(); + private readonly Dictionary methodHandlers = new(); + private int lastMessageId = 0; private readonly ConcurrentDictionary pendingIncomingRequests = new(); + /// + /// Registers an RPC handler method. + /// + /// The handler method info. + /// The method invocation target. + public void AddRpcMethod(MethodInfo handlerMethod, object? target) + { + var handler = new JsonRpcMethodHandler(handlerMethod, target); + this.methodHandlers.Add(handler.MethodName, handler); + } + private int NextMessageId() => Interlocked.Increment(ref this.lastMessageId); private async Task ReadMessage()