mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-14 05:34:48 +00:00
Import SocketIO code
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace SocketIOClient.JsonSerializer
|
||||
{
|
||||
class ByteArrayConverter : JsonConverter<byte[]>
|
||||
{
|
||||
public ByteArrayConverter()
|
||||
{
|
||||
Bytes = new List<byte[]>();
|
||||
}
|
||||
|
||||
|
||||
public List<byte[]> Bytes { get; }
|
||||
|
||||
public override byte[] Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
byte[] bytes = null;
|
||||
if (reader.TokenType == JsonTokenType.StartObject)
|
||||
{
|
||||
reader.Read();
|
||||
if (reader.TokenType == JsonTokenType.PropertyName && reader.GetString() == "_placeholder")
|
||||
{
|
||||
reader.Read();
|
||||
if (reader.TokenType == JsonTokenType.True && reader.GetBoolean())
|
||||
{
|
||||
reader.Read();
|
||||
if (reader.TokenType == JsonTokenType.PropertyName && reader.GetString() == "num")
|
||||
{
|
||||
reader.Read();
|
||||
int num = reader.GetInt32();
|
||||
bytes = Bytes[num];
|
||||
reader.Read();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, byte[] value, JsonSerializerOptions options)
|
||||
{
|
||||
Bytes.Add(value);
|
||||
writer.WriteStartObject();
|
||||
writer.WritePropertyName("_placeholder");
|
||||
writer.WriteBooleanValue(true);
|
||||
writer.WritePropertyName("num");
|
||||
writer.WriteNumberValue(Bytes.Count - 1);
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user