mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-08-13 17:33:02 +00:00
4e2dc564dd
Updated WebSocket message routing improving performance for scenarios with multiple different subscriptions and topics Added AddCommaSeparated helper for Enum value arrays to ParameterCollection Improved EnumConverter performance and removed string allocation for happy path Fixed CreateParamString extension method for ArrayParametersSerialization.Json Fixed Shared GetOrderBookOptions and GetRecentTradeOptions base validations not being called
37 lines
1.0 KiB
C#
37 lines
1.0 KiB
C#
using System.Collections.Generic;
|
|
#if NET8_0_OR_GREATER
|
|
using System.Collections.Frozen;
|
|
#endif
|
|
|
|
namespace CryptoExchange.Net.Sockets.Default.Routing
|
|
{
|
|
internal abstract class ProcessorRouter
|
|
{
|
|
public abstract RouteCollection? GetRoutes(string identifier);
|
|
}
|
|
|
|
internal abstract class ProcessorRouter<T> : ProcessorRouter
|
|
where T : RouteCollection
|
|
{
|
|
#if NET8_0_OR_GREATER
|
|
private FrozenDictionary<string, T> _routeMap;
|
|
#else
|
|
private Dictionary<string, T> _routeMap;
|
|
#endif
|
|
|
|
public ProcessorRouter(IEnumerable<MessageRoute> routes)
|
|
{
|
|
var map = BuildFromRoutes(routes);
|
|
#if NET8_0_OR_GREATER
|
|
_routeMap = map.ToFrozenDictionary();
|
|
#else
|
|
_routeMap = map;
|
|
#endif
|
|
}
|
|
|
|
public abstract Dictionary<string, T> BuildFromRoutes(IEnumerable<MessageRoute> routes);
|
|
|
|
public override RouteCollection? GetRoutes(string identifier) => _routeMap.TryGetValue(identifier, out var routes) ? routes : null;
|
|
}
|
|
}
|