Initial WIP commit
Some checks failed
Deploy to Gitea Releases / deploy-to-gitea-releases (push) Failing after 9s
Some checks failed
Deploy to Gitea Releases / deploy-to-gitea-releases (push) Failing after 9s
This commit is contained in:
26
Service/HardwarePipeSerializer.cs
Normal file
26
Service/HardwarePipeSerializer.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using PipeMethodCalls;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace HardwareMonitorStatusWindow.Service;
|
||||
|
||||
public class HardwarePipeSerializer : IPipeSerializer
|
||||
{
|
||||
private static readonly JsonSerializerOptions JsonSerializerOptions = new()
|
||||
{
|
||||
NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals
|
||||
};
|
||||
|
||||
public object? Deserialize(byte[] data, Type type)
|
||||
{
|
||||
return JsonSerializer.Deserialize(data, type, JsonSerializerOptions);
|
||||
}
|
||||
|
||||
public byte[] Serialize(object o)
|
||||
{
|
||||
using var memoryStream = new MemoryStream();
|
||||
using var utf8JsonWriter = new Utf8JsonWriter(memoryStream);
|
||||
JsonSerializer.Serialize(utf8JsonWriter, o, JsonSerializerOptions);
|
||||
return memoryStream.ToArray();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user