Добавлен транспорт TCP
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -16,7 +17,12 @@ if (args.Length < 2)
|
||||
|
||||
var protocol = args[0];
|
||||
var serialization = args[1];
|
||||
IClient? client = protocol == "http" ? new HttpClientWrapper(serialization == "json" ? ConvertJsonResponse : ConvertMessagePackResponse) : null;
|
||||
IClient? client = protocol switch
|
||||
{
|
||||
"http" => new HttpClientWrapper(serialization == "json" ? ConvertJsonResponse : ConvertMessagePackResponse),
|
||||
"tcp" => new TcpClientWrapper(serialization == "json" ? ConvertBytesJson : ConvertBytesMessagePack),
|
||||
_ => null
|
||||
};
|
||||
|
||||
client?.Start();
|
||||
System.Console.WriteLine("Client started:");
|
||||
@@ -51,3 +57,16 @@ static async Task<Data?> ConvertMessagePackResponse(HttpResponseMessage response
|
||||
var msgPackData = MessagePackSerializer.Deserialize<MessagePackData>(bytes);
|
||||
return msgPackData?.ToData();
|
||||
}
|
||||
|
||||
static Task<Data?> ConvertBytesJson(byte[] bytes)
|
||||
{
|
||||
var json = Encoding.UTF8.GetString(bytes);
|
||||
var jsonData = JsonSerializer.Deserialize<JsonData>(json);
|
||||
return Task.FromResult(jsonData?.ToData());
|
||||
}
|
||||
|
||||
static Task<Data?> ConvertBytesMessagePack(byte[] bytes)
|
||||
{
|
||||
var msgPackData = MessagePackSerializer.Deserialize<MessagePackData>(bytes);
|
||||
return Task.FromResult(msgPackData?.ToData());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user