<commit_before>﻿using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace Flood.RPC
{
    public abstract class RPCProxy : RPCStub
    {
        public RPCPeer Peer { get; private set; }
        public int RemoteId { get; private set; }

        private RPCCallProcessor callProcessor;

        /// Maps a Event id to a Delegate id.
        private Dictionary<int, int> eventIdsDelegates;

        protected RPCProxy(RPCPeer peer, int remoteId, int id)
            : base(id)
        {
            Peer = peer;
            RemoteId = remoteId;

            callProcessor = new RPCCallProcessor();

            eventIdsDelegates = new Dictionary<int, int>();
        }

        protected void Subscribe<T>(int eventId, Delegate del)
            where T : RPCDelegateImpl, new()
        {
            var rpcDelegate = CreateDelegateImpl<T>(Peer, RemoteId, del);
            var data = RPCData.Create(this, RPCDataType.EventSubscribe);
            data.Serializer.WriteI32(eventId);
            data.Serializer.WriteI32(rpcDelegate.Id);
            data.Dispatch();

            eventIdsDelegates.Add(eventId, rpcDelegate.Id);
        }

        protected void Unsubscribe(int eventId)
        {
            var delegateId = eventIdsDelegates[eventId];

            var data = RPCData.Create(this, RPCDataType.EventUnsubscribe);
            data.Serializer.WriteI32(eventId);
            data.Serializer.WriteI32(delegateId);
            data.Dispatch();

            delegates.Remove(delegateId);
            eventIdsDelegates.Remove(eventId);
        }

        internal void ProcessReply(RPCData.Reply reply)
        {
            callProcessor.ProcessReply(reply);
        }

        public RPCData.Call CreateCall(int methodId)
        {
            return callProcessor.CreateCall(methodId, Peer, Id, RemoteId, false);
        }

        public Task<RPCData> DispatchCall(RPCData.Call call)
        {
            return callProcessor.DispatchCall(call);
        }
    }
}<commit_msg>Updated RPCCallProcessor usage in RPCProxy Methods.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace Flood.RPC
{
    public abstract class RPCProxy : RPCStub
    {
        public RPCPeer Peer { get; private set; }
        public int RemoteId { get; private set; }

        private RPCCallProcessor callProcessor;

        /// Maps a Event id to a Delegate id.
        private Dictionary<int, int> eventIdsDelegates;

        protected RPCProxy(RPCPeer peer, int remoteId, int id)
            : base(id)
        {
            Peer = peer;
            RemoteId = remoteId;

            callProcessor = new RPCCallProcessor();

            eventIdsDelegates = new Dictionary<int, int>();
        }

        protected void Subscribe<T>(int eventId, Delegate del)
            where T : RPCDelegateImpl, new()
        {
            var rpcDelegate = CreateDelegateImpl<T>(Peer, RemoteId, del);
            var data = RPCData.Create(this, RPCDataType.EventSubscribe);
            data.Serializer.WriteI32(eventId);
            data.Serializer.WriteI32(rpcDelegate.Id);
            data.Dispatch();

            eventIdsDelegates.Add(eventId, rpcDelegate.Id);
        }

        protected void Unsubscribe(int eventId)
        {
            var delegateId = eventIdsDelegates[eventId];

            var data = RPCData.Create(this, RPCDataType.EventUnsubscribe);
            data.Serializer.WriteI32(eventId);
            data.Serializer.WriteI32(delegateId);
            data.Dispatch();

            delegates.Remove(delegateId);
            eventIdsDelegates.Remove(eventId);
        }

        public RPCData.Call CreateCall(int methodId)
        {
            var callId = callProcessor.GetNextCallId();
            return new RPCData.Call(callId, methodId, Peer, Id, RemoteId);
        }

        internal void ProcessReply(RPCData.Reply reply)
        {
            callProcessor.SetResult(reply.Id, reply.Data);
        }

        public Task<RPCData> DispatchCall(RPCData.Call call)
        {
            return callProcessor.DispatchCall(call.Id, call.Data);
        }
    }
}
{'fraction_non_alphanumeric': 0.08720514653323802, 'fraction_numerical': 0.003812246842983083, 'mean_word_length': 2.0981549815498153, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5543712', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1133, 'n_words': 255}