fixes, hopefully
This commit is contained in:
parent
7495e34ade
commit
cbc24e7672
13 changed files with 449 additions and 78 deletions
|
|
@ -1,5 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using GsDChat.Core.Models;
|
||||
|
||||
namespace GsDChat.Core.Protocol;
|
||||
|
|
@ -28,7 +29,16 @@ public static class MessageTypes
|
|||
|
||||
public class NetworkEnvelope
|
||||
{
|
||||
private static readonly JsonSerializerOptions s_jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
||||
};
|
||||
|
||||
[JsonPropertyName("type")]
|
||||
public string Type { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("payload")]
|
||||
public string Payload { get; set; } = "{}";
|
||||
|
||||
public static NetworkEnvelope Create<T>(string type, T payload)
|
||||
|
|
@ -36,13 +46,13 @@ public class NetworkEnvelope
|
|||
return new NetworkEnvelope
|
||||
{
|
||||
Type = type,
|
||||
Payload = JsonSerializer.Serialize(payload)
|
||||
Payload = JsonSerializer.Serialize(payload, s_jsonOptions)
|
||||
};
|
||||
}
|
||||
|
||||
public T? Unpack<T>()
|
||||
{
|
||||
return JsonSerializer.Deserialize<T>(Payload);
|
||||
return JsonSerializer.Deserialize<T>(Payload, s_jsonOptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue