Skip to content

Commit 0c4d152

Browse files
Update compiler communication to use System.Text.Json instead of Json.NET
1 parent 2f0caeb commit 0c4d152

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

src/Common/Constants.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ namespace Oxide.CSharp.Common
88
{
99
internal static class Constants
1010
{
11-
internal static readonly Serializer Serializer = new();
1211
internal static readonly UTF8Encoding CompilerEncoding = new(false);
1312

1413
internal const string CompilerDownloadUrl = "https://downloads.oxidemod.com/artifacts/Oxide.Compiler/{0}/";

src/CompilerService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using Oxide.Plugins;
2121
using Oxide.Pooling;
2222
using References::Mono.Unix.Native;
23+
using System.Text.Json;
2324

2425
namespace Oxide.CSharp
2526
{
@@ -343,7 +344,7 @@ private void OnMessageReceived(CompilerMessage message)
343344
}
344345
}
345346

346-
CompilationResult? compilationResult = Constants.Serializer.Deserialize<CompilationResult>(message.Data);
347+
CompilationResult? compilationResult = JsonSerializer.Deserialize<CompilationResult>(message.Data);
347348
if (compilationResult?.Data == null || compilationResult.Data.Length == 0)
348349
{
349350
compilation.Completed();
@@ -615,7 +616,7 @@ private void EnqueueCompilation(Compilation compilation)
615616
{
616617
Id = compilation.id,
617618
Type = MessageType.Data,
618-
Data = Constants.Serializer.Serialize(compilerData),
619+
Data = JsonSerializer.SerializeToUtf8Bytes(compilerData),
619620
};
620621

621622
if (_ready)

src/CompilerStream/MessageBrokerService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Oxide.Core;
99
using Oxide.CSharp.Common;
1010
using Oxide.Pooling;
11+
using System.Text.Json;
1112

1213
namespace Oxide.CSharp.CompilerStream
1314
{
@@ -96,7 +97,7 @@ private void WriteMessage(CompilerMessage message)
9697
using StreamWriter streamWriter = new(memoryStream, Constants.CompilerEncoding, DefaultMaxBufferSize);
9798
try
9899
{
99-
Constants.Serializer.GetJsonSerializer().Serialize(streamWriter, message);
100+
JsonSerializer.Serialize(memoryStream, message);
100101

101102
streamWriter.Flush();
102103

@@ -142,7 +143,7 @@ private void WriteMessage(CompilerMessage message)
142143
read += OnRead(messageBuffer, read, length - read);
143144
}
144145

145-
return Constants.Serializer.Deserialize<CompilerMessage>(messageBuffer);
146+
return JsonSerializer.Deserialize<CompilerMessage>(messageBuffer);
146147
}
147148
finally
148149
{

0 commit comments

Comments
 (0)