use own PipeSerializer
SendToVisualizerAsync uses await
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
using PipeMethodCalls;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace NamedPipes;
|
||||
|
||||
/// <summary>
|
||||
/// Serializes pipe method call information with System.Text.Json.
|
||||
/// </summary>
|
||||
public class PipeSerializer : IPipeSerializer
|
||||
{
|
||||
public object Deserialize(byte[] data, Type type)
|
||||
{
|
||||
return JsonSerializer.Deserialize(data, type) ?? throw new InvalidDataException($"Can not deserialize to type: {type} ");
|
||||
}
|
||||
|
||||
public byte[] Serialize(object o)
|
||||
{
|
||||
using (var memoryStream = new MemoryStream())
|
||||
using (var utf8JsonWriter = new Utf8JsonWriter(memoryStream))
|
||||
{
|
||||
JsonSerializer.Serialize(utf8JsonWriter, o);
|
||||
return memoryStream.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user