1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2025-06-09 00:46:19 +00:00
This commit is contained in:
JKorf 2023-12-12 21:38:40 +01:00
parent 12d5783625
commit c931a60cb7
3 changed files with 22 additions and 18 deletions

View File

@ -23,7 +23,7 @@ namespace CryptoExchange.Net.Converters
public abstract MessageInterpreterPipeline InterpreterPipeline { get; }
/// <inheritdoc />
public BaseParsedMessage? ReadJson(WebSocketMessageType websocketMessageType, Stream stream, Dictionary<string, Type> processors, bool outputOriginalData)
public BaseParsedMessage? ReadJson(WebSocketMessageType websocketMessageType, Stream stream, SocketListenerManager listenerManager, bool outputOriginalData)
{
// Start reading the data
// Once we reach the properties that identify the message we save those in a dict
@ -73,9 +73,13 @@ namespace CryptoExchange.Net.Converters
var identity = InterpreterPipeline.GetIdentity(accessor);
if (identity != null)
{
if (processors.TryGetValue(identity, out var type))
var result = listenerManager.IdToType(identity);
if (result == null)
{
var idInstance = InterpreterPipeline.ObjectInitializer(token, type);
}
var idInstance = InterpreterPipeline.ObjectInitializer(token, result!);
if (outputOriginalData)
{
stream.Position = 0;
@ -86,7 +90,6 @@ namespace CryptoExchange.Net.Converters
idInstance.Parsed = true;
return idInstance;
}
}
else
{
// Message not identified

View File

@ -312,7 +312,7 @@ namespace CryptoExchange.Net.Sockets
/// <returns></returns>
protected virtual async Task HandleStreamMessage(WebSocketMessageType type, Stream stream)
{
var result = ApiClient.StreamConverter.ReadJson(type, stream, _listenerManager.GetMapping(), ApiClient.ApiOptions.OutputOriginalData ?? ApiClient.ClientOptions.OutputOriginalData);
var result = ApiClient.StreamConverter.ReadJson(type, stream, _listenerManager, ApiClient.ApiOptions.OutputOriginalData ?? ApiClient.ClientOptions.OutputOriginalData);
if(result == null)
{
// Not able to parse at all

View File

@ -5,13 +5,11 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace CryptoExchange.Net.Sockets
{
internal class SocketListenerManager
public class SocketListenerManager
{
private ILogger _logger;
private int _socketId;
@ -29,10 +27,13 @@ namespace CryptoExchange.Net.Sockets
_socketId = socketId;
}
public Dictionary<string, Type> GetMapping()
public Type? IdToType(string id)
{
lock (this)
return _typeMap;
lock (_lock)
{
_typeMap.TryGetValue(id, out var type);
return type;
}
}
public List<string> GetListenIds()