Fixed a few json settings (such as dates deserializing to UTC), and use cached jsonserializers in more places.
This commit is contained in:
@@ -10,6 +10,7 @@ using System;
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
@@ -402,7 +403,11 @@ namespace Discord.Net.WebSockets
|
|||||||
protected override async Task ProcessMessage(string json)
|
protected override async Task ProcessMessage(string json)
|
||||||
{
|
{
|
||||||
await base.ProcessMessage(json).ConfigureAwait(false);
|
await base.ProcessMessage(json).ConfigureAwait(false);
|
||||||
var msg = JsonConvert.DeserializeObject<WebSocketMessage>(json);
|
|
||||||
|
WebSocketMessage msg;
|
||||||
|
using (var reader = new JsonTextReader(new StringReader(json)))
|
||||||
|
msg = _serializer.Deserialize(reader, typeof(WebSocketMessage)) as WebSocketMessage;
|
||||||
|
|
||||||
var opCode = (OpCodes)msg.Operation;
|
var opCode = (OpCodes)msg.Operation;
|
||||||
switch (opCode)
|
switch (opCode)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,22 +1,23 @@
|
|||||||
using Discord.Logging;
|
using Discord.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Discord.Net.Rest
|
namespace Discord.Net.Rest
|
||||||
{
|
{
|
||||||
public class JsonRestClient : RestClient
|
public class JsonRestClient : RestClient
|
||||||
{
|
{
|
||||||
private JsonSerializerSettings _deserializeSettings;
|
private JsonSerializer _serializer;
|
||||||
|
|
||||||
public JsonRestClient(DiscordConfig config, string baseUrl, Logger logger)
|
public JsonRestClient(DiscordConfig config, string baseUrl, Logger logger)
|
||||||
: base(config, baseUrl, logger)
|
: base(config, baseUrl, logger)
|
||||||
{
|
{
|
||||||
_deserializeSettings = new JsonSerializerSettings();
|
_serializer = new JsonSerializer();
|
||||||
#if TEST_RESPONSES
|
#if TEST_RESPONSES
|
||||||
_deserializeSettings.CheckAdditionalContent = true;
|
_serializer.CheckAdditionalContent = true;
|
||||||
_deserializeSettings.MissingMemberHandling = MissingMemberHandling.Error;
|
_serializer.MissingMemberHandling = MissingMemberHandling.Error;
|
||||||
#else
|
#else
|
||||||
_deserializeSettings.CheckAdditionalContent = false;
|
_serializer.CheckAdditionalContent = false;
|
||||||
_deserializeSettings.MissingMemberHandling = MissingMemberHandling.Ignore;
|
_serializer.MissingMemberHandling = MissingMemberHandling.Ignore;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +32,8 @@ namespace Discord.Net.Rest
|
|||||||
if (string.IsNullOrEmpty(json))
|
if (string.IsNullOrEmpty(json))
|
||||||
throw new Exception("API check failed: Response is empty.");
|
throw new Exception("API check failed: Response is empty.");
|
||||||
#endif
|
#endif
|
||||||
return JsonConvert.DeserializeObject<T>(json, _deserializeSettings);
|
using (var reader = new JsonTextReader(new StringReader(json)))
|
||||||
|
return (T)_serializer.Deserialize(reader, typeof(T));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using Newtonsoft.Json;
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@@ -103,7 +104,11 @@ namespace Discord.Net.WebSockets
|
|||||||
protected override async Task ProcessMessage(string json)
|
protected override async Task ProcessMessage(string json)
|
||||||
{
|
{
|
||||||
base.ProcessMessage(json).GetAwaiter().GetResult(); //This is just a CompletedTask, and we need to avoid asyncs in here
|
base.ProcessMessage(json).GetAwaiter().GetResult(); //This is just a CompletedTask, and we need to avoid asyncs in here
|
||||||
var msg = JsonConvert.DeserializeObject<WebSocketMessage>(json);
|
|
||||||
|
WebSocketMessage msg;
|
||||||
|
using (var reader = new JsonTextReader(new StringReader(json)))
|
||||||
|
msg = _serializer.Deserialize(reader, typeof(WebSocketMessage)) as WebSocketMessage;
|
||||||
|
|
||||||
if (msg.Sequence.HasValue)
|
if (msg.Sequence.HasValue)
|
||||||
_lastSequence = msg.Sequence.Value;
|
_lastSequence = msg.Sequence.Value;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user