Skip to content

Commit 69e45c4

Browse files
Update Serializer to allow writing directly to a stream
1 parent 96b3d82 commit 69e45c4

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/CompilerServices/ISerializer.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
namespace Oxide.CompilerServices;
1+
using System.IO;
2+
3+
namespace Oxide.CompilerServices;
24

35
public interface ISerializer
46
{
7+
public void SerializeToStream<T>(MemoryStream memoryStream, T type, int bufferSize) where T : class;
8+
59
public byte[] Serialize<T>(T type) where T : class;
610

711
public T Deserialize<T>(byte[] data) where T : class;

src/CompilerServices/Serializer.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ public Serializer()
1717
_encoding = new UTF8Encoding(false);
1818
}
1919

20+
public void SerializeToStream<T>(MemoryStream memoryStream, T type, int bufferSize) where T : class
21+
{
22+
using StreamWriter streamWriter = new(memoryStream, _encoding, bufferSize, leaveOpen: true);
23+
24+
_jsonSerializer.Serialize(streamWriter, type);
25+
26+
streamWriter.Flush();
27+
}
28+
2029
public byte[] Serialize<T>(T type) where T : class
2130
{
2231
using MemoryStream memoryStream = new();

0 commit comments

Comments
 (0)