Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/aspnet/MessagePack-CSharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Bunting <6431421+dougbu@users.noreply.github.com>2022-08-22 22:00:36 +0300
committerGitHub <noreply@github.com>2022-08-22 22:00:36 +0300
commitfe9fa0834d18492eb229ff2923024af2c87553f8 (patch)
treeaa041fcc52477e05bebc0df58154151d0673c916 /src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.Json.cs
parent6caf2996c82d2b91528fad41e9c78e09770e73d4 (diff)
parent3d1b75b8a33c65eadf6a6d72a4c26cc2d91a87ec (diff)
Merge pull request #2 from gllebede/masterHEADmaster
MessagePack update
Diffstat (limited to 'src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.Json.cs')
-rw-r--r--src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.Json.cs31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.Json.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.Json.cs
index 091e2a95..38e39985 100644
--- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.Json.cs
+++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.Json.cs
@@ -21,7 +21,9 @@ namespace MessagePack
/// <exception cref="MessagePackSerializationException">Thrown if an error occurs during serialization.</exception>
public static void SerializeToJson<T>(TextWriter textWriter, T obj, MessagePackSerializerOptions options = null, CancellationToken cancellationToken = default)
{
- using (var sequenceRental = SequencePool.Shared.Rent())
+ options = options ?? DefaultOptions;
+
+ using (var sequenceRental = options.SequencePool.Rent())
{
var msgpackWriter = new MessagePackWriter(sequenceRental.Value)
{
@@ -85,7 +87,7 @@ namespace MessagePack
{
if (options.Compression.IsCompression())
{
- using (var scratchRental = SequencePool.Shared.Rent())
+ using (var scratchRental = options.SequencePool.Rent())
{
if (TryDecompress(ref reader, scratchRental.Value))
{
@@ -133,7 +135,9 @@ namespace MessagePack
/// </summary>
public static byte[] ConvertFromJson(string str, MessagePackSerializerOptions options = null, CancellationToken cancellationToken = default)
{
- using (var scratchRental = SequencePool.Shared.Rent())
+ options = options ?? DefaultOptions;
+
+ using (var scratchRental = options.SequencePool.Rent())
{
var writer = new MessagePackWriter(scratchRental.Value)
{
@@ -155,30 +159,31 @@ namespace MessagePack
public static void ConvertFromJson(TextReader reader, ref MessagePackWriter writer, MessagePackSerializerOptions options = null)
{
options = options ?? DefaultOptions;
+
if (options.Compression.IsCompression())
{
- using (var scratchRental = SequencePool.Shared.Rent())
+ using (var scratchRental = options.SequencePool.Rent())
{
MessagePackWriter scratchWriter = writer.Clone(scratchRental.Value);
using (var jr = new TinyJsonReader(reader, false))
{
- FromJsonCore(jr, ref scratchWriter);
+ FromJsonCore(jr, ref scratchWriter, options);
}
scratchWriter.Flush();
- ToLZ4BinaryCore(scratchRental.Value, ref writer, options.Compression);
+ ToLZ4BinaryCore(scratchRental.Value, ref writer, options.Compression, options.CompressionMinLength);
}
}
else
{
using (var jr = new TinyJsonReader(reader, false))
{
- FromJsonCore(jr, ref writer);
+ FromJsonCore(jr, ref writer, options);
}
}
}
- private static uint FromJsonCore(TinyJsonReader jr, ref MessagePackWriter writer)
+ private static uint FromJsonCore(TinyJsonReader jr, ref MessagePackWriter writer, MessagePackSerializerOptions options)
{
uint count = 0;
while (jr.Read())
@@ -189,10 +194,10 @@ namespace MessagePack
break;
case TinyJsonToken.StartObject:
// Set up a scratch area to serialize the collection since we don't know its length yet, which must be written first.
- using (var scratchRental = SequencePool.Shared.Rent())
+ using (var scratchRental = options.SequencePool.Rent())
{
MessagePackWriter scratchWriter = writer.Clone(scratchRental.Value);
- var mapCount = FromJsonCore(jr, ref scratchWriter);
+ var mapCount = FromJsonCore(jr, ref scratchWriter, options);
scratchWriter.Flush();
mapCount = mapCount / 2; // remove propertyname string count.
@@ -206,10 +211,10 @@ namespace MessagePack
return count; // break
case TinyJsonToken.StartArray:
// Set up a scratch area to serialize the collection since we don't know its length yet, which must be written first.
- using (var scratchRental = SequencePool.Shared.Rent())
+ using (var scratchRental = options.SequencePool.Rent())
{
MessagePackWriter scratchWriter = writer.Clone(scratchRental.Value);
- var arrayCount = FromJsonCore(jr, ref scratchWriter);
+ var arrayCount = FromJsonCore(jr, ref scratchWriter, options);
scratchWriter.Flush();
writer.WriteArrayHeader(arrayCount);
@@ -299,7 +304,7 @@ namespace MessagePack
WriteJsonString(reader.ReadString(), writer);
break;
case MessagePackType.Binary:
- ArraySegment<byte> segment = ByteArraySegmentFormatter.Instance.Deserialize(ref reader, DefaultOptions);
+ ArraySegment<byte> segment = ByteArraySegmentFormatter.Instance.Deserialize(ref reader, options);
writer.Write("\"" + Convert.ToBase64String(segment.Array, segment.Offset, segment.Count) + "\"");
break;
case MessagePackType.Array: