forked from ElectronNET/Electron.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSocketIOResponse.cs
More file actions
62 lines (53 loc) · 1.81 KB
/
Copy pathSocketIOResponse.cs
File metadata and controls
62 lines (53 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
namespace SocketIOClient
{
public class SocketIOResponse
{
public SocketIOResponse(IList<JsonElement> array, SocketIO socket)
{
_array = array;
InComingBytes = new List<byte[]>();
SocketIO = socket;
PacketId = -1;
}
readonly IList<JsonElement> _array;
public List<byte[]> InComingBytes { get; }
public SocketIO SocketIO { get; }
public int PacketId { get; set; }
public T GetValue<T>(int index = 0)
{
var element = GetValue(index);
string json = element.GetRawText();
return SocketIO.JsonSerializer.Deserialize<T>(json, InComingBytes);
}
public JsonElement GetValue(int index = 0) => _array[index];
public int Count => _array.Count;
public override string ToString()
{
var builder = new StringBuilder();
builder.Append('[');
foreach (var item in _array)
{
builder.Append(item.GetRawText());
if (_array.IndexOf(item) < _array.Count - 1)
{
builder.Append(',');
}
}
builder.Append(']');
return builder.ToString();
}
public async Task CallbackAsync(params object[] data)
{
await SocketIO.ClientAckAsync(PacketId, CancellationToken.None, data).ConfigureAwait(false);
}
public async Task CallbackAsync(CancellationToken cancellationToken, params object[] data)
{
await SocketIO.ClientAckAsync(PacketId, cancellationToken, data).ConfigureAwait(false);
}
}
}