001b945ea1
TODO: Update SceneTreeView after adding new objects
35 lines
885 B
C#
35 lines
885 B
C#
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
|
|
{
|
|
private JsonSerializerOptions options = new()
|
|
{
|
|
IncludeFields = true
|
|
};
|
|
|
|
public object Deserialize(byte[] data, Type type)
|
|
{
|
|
|
|
var obj = JsonSerializer.Deserialize(data, type, options) ?? throw new InvalidDataException($"Can not deserialize to type: {type} ");
|
|
return obj;
|
|
}
|
|
|
|
public byte[] Serialize(object o)
|
|
{
|
|
|
|
using var memoryStream = new MemoryStream();
|
|
using var utf8JsonWriter = new Utf8JsonWriter(memoryStream);
|
|
JsonSerializer.Serialize(utf8JsonWriter, o, options);
|
|
var data = memoryStream.ToArray();
|
|
return data;
|
|
}
|
|
}
|