diff --git a/Aetheria.Shared/Aetheria.Shared.csproj b/Aetheria.Shared/Aetheria.Shared.csproj
index d67dba1e4..3783e7469 100644
--- a/Aetheria.Shared/Aetheria.Shared.csproj
+++ b/Aetheria.Shared/Aetheria.Shared.csproj
@@ -3,7 +3,7 @@
Compiles ServerShared and its dependencies from source with no Unity defines, so a successful build is the
check that the simulation stays independent of the engine. Tools and test harnesses reference this project. -->
-
+
netstandard2.1
9.0
disable
@@ -18,7 +18,6 @@
-
@@ -27,7 +26,5 @@
-
-
diff --git a/Assets/Plugins/MessagePack.meta b/Assets/Plugins/MessagePack.meta
deleted file mode 100644
index 1afdd561d..000000000
--- a/Assets/Plugins/MessagePack.meta
+++ /dev/null
@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: 78d7ac1a75fbd3f4d91b72ac2de5f552
-folderAsset: yes
-DefaultImporter:
- externalObjects: {}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Plugins/MessagePack/Annotations.meta b/Assets/Plugins/MessagePack/Annotations.meta
deleted file mode 100644
index aa53ddd27..000000000
--- a/Assets/Plugins/MessagePack/Annotations.meta
+++ /dev/null
@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: 258cef354b8273b4ca696ab53c01327a
-folderAsset: yes
-DefaultImporter:
- externalObjects: {}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Plugins/MessagePack/Annotations/Attributes.cs b/Assets/Plugins/MessagePack/Annotations/Attributes.cs
deleted file mode 100644
index a30280823..000000000
--- a/Assets/Plugins/MessagePack/Annotations/Attributes.cs
+++ /dev/null
@@ -1,81 +0,0 @@
-// Copyright (c) All contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System;
-
-#pragma warning disable SA1649 // File name should match first type name
-
-namespace MessagePack
-{
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = true)]
- public class MessagePackObjectAttribute : Attribute
- {
- public bool KeyAsPropertyName { get; private set; }
-
- public MessagePackObjectAttribute(bool keyAsPropertyName = false)
- {
- this.KeyAsPropertyName = keyAsPropertyName;
- }
- }
-
- [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
- public class KeyAttribute : Attribute
- {
- public int? IntKey { get; private set; }
-
- public string StringKey { get; private set; }
-
- public KeyAttribute(int x)
- {
- this.IntKey = x;
- }
-
- public KeyAttribute(string x)
- {
- this.StringKey = x;
- }
- }
-
- [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
- public class IgnoreMemberAttribute : Attribute
- {
- }
-
- [AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
- public class UnionAttribute : Attribute
- {
- public int Key { get; private set; }
-
- public Type SubType { get; private set; }
-
- public UnionAttribute(int key, Type subType)
- {
- this.Key = key;
- this.SubType = subType;
- }
- }
-
- [AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = true)]
- public class SerializationConstructorAttribute : Attribute
- {
- }
-
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface | AttributeTargets.Enum | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
- public class MessagePackFormatterAttribute : Attribute
- {
- public Type FormatterType { get; private set; }
-
- public object[] Arguments { get; private set; }
-
- public MessagePackFormatterAttribute(Type formatterType)
- {
- this.FormatterType = formatterType;
- }
-
- public MessagePackFormatterAttribute(Type formatterType, params object[] arguments)
- {
- this.FormatterType = formatterType;
- this.Arguments = arguments;
- }
- }
-}
diff --git a/Assets/Plugins/MessagePack/Annotations/Attributes.cs.meta b/Assets/Plugins/MessagePack/Annotations/Attributes.cs.meta
deleted file mode 100644
index 44ea4ea1e..000000000
--- a/Assets/Plugins/MessagePack/Annotations/Attributes.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: db21d74c4f54408a9acd69873192155c
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Plugins/MessagePack/Annotations/IMessagePackSerializationCallbackReceiver.cs b/Assets/Plugins/MessagePack/Annotations/IMessagePackSerializationCallbackReceiver.cs
deleted file mode 100644
index 3b1daf4cc..000000000
--- a/Assets/Plugins/MessagePack/Annotations/IMessagePackSerializationCallbackReceiver.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright (c) All contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-namespace MessagePack
-{
- public interface IMessagePackSerializationCallbackReceiver
- {
- void OnBeforeSerialize();
-
- void OnAfterDeserialize();
- }
-}
diff --git a/Assets/Plugins/MessagePack/Annotations/IMessagePackSerializationCallbackReceiver.cs.meta b/Assets/Plugins/MessagePack/Annotations/IMessagePackSerializationCallbackReceiver.cs.meta
deleted file mode 100644
index c770043be..000000000
--- a/Assets/Plugins/MessagePack/Annotations/IMessagePackSerializationCallbackReceiver.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: ef32599edd0f43366891b8da5d4aed1e
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Plugins/MessagePack/BitOperations.cs b/Assets/Plugins/MessagePack/BitOperations.cs
deleted file mode 100644
index 09b2ca0dc..000000000
--- a/Assets/Plugins/MessagePack/BitOperations.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-//
-
-#if !NETCOREAPP
-
-using System.Runtime.CompilerServices;
-
-// Some routines inspired by the Stanford Bit Twiddling Hacks by Sean Eron Anderson:
-// http://graphics.stanford.edu/~seander/bithacks.html
-
-namespace System.Numerics
-{
- ///
- /// Utility methods for intrinsic bit-twiddling operations.
- /// The methods use hardware intrinsics when available on the underlying platform,
- /// otherwise they use optimized software fallbacks.
- ///
- internal static class BitOperations
- {
- ///
- /// Rotates the specified value left by the specified number of bits.
- /// Similar in behavior to the x86 instruction ROL.
- ///
- /// The value to rotate.
- /// The number of bits to rotate by.
- /// Any value outside the range [0..31] is treated as congruent mod 32.
- /// The rotated value.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static uint RotateLeft(uint value, int offset)
- => (value << offset) | (value >> (32 - offset));
- }
-}
-
-#endif
diff --git a/Assets/Plugins/MessagePack/BitOperations.cs.meta b/Assets/Plugins/MessagePack/BitOperations.cs.meta
deleted file mode 100644
index 589ad79c1..000000000
--- a/Assets/Plugins/MessagePack/BitOperations.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 3c1e411a42f526567af32d094a9de348
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Plugins/MessagePack/BufferWriter.cs b/Assets/Plugins/MessagePack/BufferWriter.cs
deleted file mode 100644
index eba48fb11..000000000
--- a/Assets/Plugins/MessagePack/BufferWriter.cs
+++ /dev/null
@@ -1,260 +0,0 @@
-// // We want to keep this file as-is since it's shared with other repos.
-
-// Copyright (c) .NET Foundation. All rights reserved.
-// Copyright (c) Andrew Arnott. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-using System.Buffers;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace MessagePack
-{
- ///
- /// A fast access struct that wraps .
- ///
- internal ref struct BufferWriter
- {
- ///
- /// The underlying .
- ///
- private IBufferWriter _output;
-
- ///
- /// The result of the last call to , less any bytes already "consumed" with .
- /// Backing field for the property.
- ///
- private Span _span;
-
- ///
- /// The result of the last call to , less any bytes already "consumed" with .
- ///
- private ArraySegment _segment;
-
- ///
- /// The number of uncommitted bytes (all the calls to since the last call to ).
- ///
- private int _buffered;
-
- ///
- /// The total number of bytes written with this writer.
- /// Backing field for the property.
- ///
- private long _bytesCommitted;
-
- private SequencePool _sequencePool;
-
- private SequencePool.Rental _rental;
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// The to be wrapped.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public BufferWriter(IBufferWriter output)
- {
- _buffered = 0;
- _bytesCommitted = 0;
- _output = output ?? throw new ArgumentNullException(nameof(output));
-
- _sequencePool = default;
- _rental = default;
-
- var memory = _output.GetMemoryCheckResult();
- MemoryMarshal.TryGetArray(memory, out _segment);
- _span = memory.Span;
- }
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// The pool from which to draw an if required..
- /// An array to start with so we can avoid accessing the if possible.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal BufferWriter(SequencePool sequencePool, byte[] array)
- {
- _buffered = 0;
- _bytesCommitted = 0;
- _sequencePool = sequencePool ?? throw new ArgumentNullException(nameof(sequencePool));
- _rental = default;
- _output = null;
-
- _segment = new ArraySegment(array);
- _span = _segment.AsSpan();
- }
-
- ///
- /// Gets the result of the last call to .
- ///
- public Span Span => _span;
-
- ///
- /// Gets the total number of bytes written with this writer.
- ///
- public long BytesCommitted => _bytesCommitted;
-
- ///
- /// Gets the underlying this instance.
- ///
- internal IBufferWriter UnderlyingWriter => _output;
-
- internal SequencePool.Rental SequenceRental => _rental;
-
- public Span GetSpan(int sizeHint)
- {
- Ensure(sizeHint);
- return this.Span;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ref byte GetPointer(int sizeHint)
- {
- Ensure(sizeHint);
-
- if (_segment.Array != null)
- {
- return ref _segment.Array[_segment.Offset + _buffered];
- }
- else
- {
- return ref _span.GetPinnableReference();
- }
- }
-
- ///
- /// Calls on the underlying writer
- /// with the number of uncommitted bytes.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Commit()
- {
- var buffered = _buffered;
- if (buffered > 0)
- {
- this.MigrateToSequence();
-
- _bytesCommitted += buffered;
- _buffered = 0;
- _output.Advance(buffered);
- _span = default;
- }
- }
-
- ///
- /// Used to indicate that part of the buffer has been written to.
- ///
- /// The number of bytes written to.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Advance(int count)
- {
- _buffered += count;
- _span = _span.Slice(count);
- }
-
- ///
- /// Copies the caller's buffer into this writer and calls with the length of the source buffer.
- ///
- /// The buffer to copy in.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Write(ReadOnlySpan source)
- {
- if (_span.Length >= source.Length)
- {
- source.CopyTo(_span);
- Advance(source.Length);
- }
- else
- {
- WriteMultiBuffer(source);
- }
- }
-
- ///
- /// Acquires a new buffer if necessary to ensure that some given number of bytes can be written to a single buffer.
- ///
- /// The number of bytes that must be allocated in a single buffer.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Ensure(int count = 1)
- {
- if (_span.Length < count)
- {
- EnsureMore(count);
- }
- }
-
- ///
- /// Gets the span to the bytes written if they were never committed to the underlying buffer writer.
- ///
- ///
- ///
- internal bool TryGetUncommittedSpan(out ReadOnlySpan span)
- {
- if (this._sequencePool != null)
- {
- span = _segment.AsSpan(0, _buffered);
- return true;
- }
-
- span = default;
- return false;
- }
-
- ///
- /// Gets a fresh span to write to, with an optional minimum size.
- ///
- /// The minimum size for the next requested buffer.
- [MethodImpl(MethodImplOptions.NoInlining)]
- private void EnsureMore(int count = 0)
- {
- if (_buffered > 0)
- {
- Commit();
- }
- else
- {
- this.MigrateToSequence();
- }
-
- var memory = _output.GetMemoryCheckResult(count);
- MemoryMarshal.TryGetArray(memory, out _segment);
- _span = memory.Span;
- }
-
- ///
- /// Copies the caller's buffer into this writer, potentially across multiple buffers from the underlying writer.
- ///
- /// The buffer to copy into this writer.
- private void WriteMultiBuffer(ReadOnlySpan source)
- {
- int copiedBytes = 0;
- int bytesLeftToCopy = source.Length;
- while (bytesLeftToCopy > 0)
- {
- if (_span.Length == 0)
- {
- EnsureMore();
- }
-
- var writable = Math.Min(bytesLeftToCopy, _span.Length);
- source.Slice(copiedBytes, writable).CopyTo(_span);
- copiedBytes += writable;
- bytesLeftToCopy -= writable;
- Advance(writable);
- }
- }
-
- private void MigrateToSequence()
- {
- if (this._sequencePool != null)
- {
- // We were writing to our private scratch memory, so we have to copy it into the actual writer.
- _rental = _sequencePool.Rent();
- _output = _rental.Value;
- var realSpan = _output.GetSpan(_buffered);
- _segment.AsSpan(0, _buffered).CopyTo(realSpan);
- _sequencePool = null;
- }
- }
- }
-}
diff --git a/Assets/Plugins/MessagePack/BufferWriter.cs.meta b/Assets/Plugins/MessagePack/BufferWriter.cs.meta
deleted file mode 100644
index a709cf6ca..000000000
--- a/Assets/Plugins/MessagePack/BufferWriter.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 91a2222860edec5ff9ee6e4fe1af7668
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Plugins/MessagePack/ExtensionHeader.cs b/Assets/Plugins/MessagePack/ExtensionHeader.cs
deleted file mode 100644
index 833e7299e..000000000
--- a/Assets/Plugins/MessagePack/ExtensionHeader.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright (c) All contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System;
-
-namespace MessagePack
-{
-#if MESSAGEPACK_INTERNAL
- internal
-#else
- public
-#endif
- struct ExtensionHeader : IEquatable
- {
- public sbyte TypeCode { get; private set; }
-
- public uint Length { get; private set; }
-
- public ExtensionHeader(sbyte typeCode, uint length)
- {
- this.TypeCode = typeCode;
- this.Length = length;
- }
-
- public ExtensionHeader(sbyte typeCode, int length)
- {
- this.TypeCode = typeCode;
- this.Length = (uint)length;
- }
-
- public bool Equals(ExtensionHeader other) => this.TypeCode == other.TypeCode && this.Length == other.Length;
- }
-}
diff --git a/Assets/Plugins/MessagePack/ExtensionHeader.cs.meta b/Assets/Plugins/MessagePack/ExtensionHeader.cs.meta
deleted file mode 100644
index b5af89635..000000000
--- a/Assets/Plugins/MessagePack/ExtensionHeader.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 92a76851178ab369fbc386556cb866ce
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Plugins/MessagePack/ExtensionResult.cs b/Assets/Plugins/MessagePack/ExtensionResult.cs
deleted file mode 100644
index 780d9bbbc..000000000
--- a/Assets/Plugins/MessagePack/ExtensionResult.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (c) All contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System;
-using System.Buffers;
-
-namespace MessagePack
-{
-#if MESSAGEPACK_INTERNAL
- internal
-#else
- public
-#endif
- struct ExtensionResult
- {
- public ExtensionResult(sbyte typeCode, Memory data)
- {
- this.TypeCode = typeCode;
- this.Data = new ReadOnlySequence(data);
- }
-
- public ExtensionResult(sbyte typeCode, ReadOnlySequence data)
- {
- this.TypeCode = typeCode;
- this.Data = data;
- }
-
- public sbyte TypeCode { get; private set; }
-
- public ReadOnlySequence Data { get; private set; }
-
- public ExtensionHeader Header => new ExtensionHeader(this.TypeCode, (uint)this.Data.Length);
- }
-}
diff --git a/Assets/Plugins/MessagePack/ExtensionResult.cs.meta b/Assets/Plugins/MessagePack/ExtensionResult.cs.meta
deleted file mode 100644
index cf5d492b8..000000000
--- a/Assets/Plugins/MessagePack/ExtensionResult.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 153f71ac242b4218d9debb5971c7b5d4
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Plugins/MessagePack/Formatters.meta b/Assets/Plugins/MessagePack/Formatters.meta
deleted file mode 100644
index 541f0d57c..000000000
--- a/Assets/Plugins/MessagePack/Formatters.meta
+++ /dev/null
@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: 4e7629820f4485c4790dbe9265bb2830
-folderAsset: yes
-DefaultImporter:
- externalObjects: {}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Plugins/MessagePack/Formatters/CollectionFormatter.cs b/Assets/Plugins/MessagePack/Formatters/CollectionFormatter.cs
deleted file mode 100644
index 550c7f312..000000000
--- a/Assets/Plugins/MessagePack/Formatters/CollectionFormatter.cs
+++ /dev/null
@@ -1,1074 +0,0 @@
-// Copyright (c) All contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System;
-using System.Buffers;
-using System.Collections;
-using System.Collections.Concurrent;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Diagnostics;
-using System.Linq;
-using System.Runtime.InteropServices;
-
-#pragma warning disable SA1649 // File name should match first type name
-
-namespace MessagePack.Formatters
-{
- public sealed class ArrayFormatter : IMessagePackFormatter
- {
- public void Serialize(ref MessagePackWriter writer, T[] value, MessagePackSerializerOptions options)
- {
- if (value == null)
- {
- writer.WriteNil();
- }
- else
- {
- IMessagePackFormatter formatter = options.Resolver.GetFormatterWithVerify();
-
- writer.WriteArrayHeader(value.Length);
-
- for (int i = 0; i < value.Length; i++)
- {
- writer.CancellationToken.ThrowIfCancellationRequested();
- formatter.Serialize(ref writer, value[i], options);
- }
- }
- }
-
- public T[] Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
- {
- if (reader.TryReadNil())
- {
- return default;
- }
- else
- {
- IMessagePackFormatter formatter = options.Resolver.GetFormatterWithVerify();
-
- var len = reader.ReadArrayHeader();
- var array = new T[len];
- options.Security.DepthStep(ref reader);
- try
- {
- for (int i = 0; i < array.Length; i++)
- {
- reader.CancellationToken.ThrowIfCancellationRequested();
- array[i] = formatter.Deserialize(ref reader, options);
- }
- }
- finally
- {
- reader.Depth--;
- }
-
- return array;
- }
- }
- }
-
- public sealed class ByteArraySegmentFormatter : IMessagePackFormatter>
- {
- public static readonly ByteArraySegmentFormatter Instance = new ByteArraySegmentFormatter();
-
- private ByteArraySegmentFormatter()
- {
- }
-
- public void Serialize(ref MessagePackWriter writer, ArraySegment value, MessagePackSerializerOptions options)
- {
- if (value.Array == null)
- {
- writer.WriteNil();
- }
- else
- {
- writer.Write(value);
- }
- }
-
- public ArraySegment Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
- {
- return reader.ReadBytes() is ReadOnlySequence bytes ? new ArraySegment(bytes.ToArray()) : default;
- }
- }
-
- public sealed class ArraySegmentFormatter : IMessagePackFormatter>
- {
- public void Serialize(ref MessagePackWriter writer, ArraySegment value, MessagePackSerializerOptions options)
- {
- if (value.Array == null)
- {
- writer.WriteNil();
- }
- else
- {
- IMessagePackFormatter formatter = options.Resolver.GetFormatterWithVerify();
-
- writer.WriteArrayHeader(value.Count);
-
- T[] array = value.Array;
- for (int i = 0; i < value.Count; i++)
- {
- writer.CancellationToken.ThrowIfCancellationRequested();
- T item = array[value.Offset + i];
- formatter.Serialize(ref writer, item, options);
- }
- }
- }
-
- public ArraySegment Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
- {
- if (reader.TryReadNil())
- {
- return default;
- }
- else
- {
- T[] array = options.Resolver.GetFormatterWithVerify().Deserialize(ref reader, options);
- return new ArraySegment(array);
- }
- }
- }
-
- // List is popular format, should avoid abstraction.
- public sealed class ListFormatter : IMessagePackFormatter>
- {
- public void Serialize(ref MessagePackWriter writer, List value, MessagePackSerializerOptions options)
- {
- if (value == null)
- {
- writer.WriteNil();
- }
- else
- {
- IMessagePackFormatter formatter = options.Resolver.GetFormatterWithVerify();
-
- var c = value.Count;
- writer.WriteArrayHeader(c);
-
- for (int i = 0; i < c; i++)
- {
- writer.CancellationToken.ThrowIfCancellationRequested();
- formatter.Serialize(ref writer, value[i], options);
- }
- }
- }
-
- public List Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
- {
- if (reader.TryReadNil())
- {
- return default;
- }
- else
- {
- IMessagePackFormatter formatter = options.Resolver.GetFormatterWithVerify();
-
- var len = reader.ReadArrayHeader();
- var list = new List((int)len);
- options.Security.DepthStep(ref reader);
- try
- {
- for (int i = 0; i < len; i++)
- {
- reader.CancellationToken.ThrowIfCancellationRequested();
- list.Add(formatter.Deserialize(ref reader, options));
- }
- }
- finally
- {
- reader.Depth--;
- }
-
- return list;
- }
- }
- }
-
- public abstract class CollectionFormatterBase : IMessagePackFormatter
- where TCollection : IEnumerable
- where TEnumerator : IEnumerator
- {
- public void Serialize(ref MessagePackWriter writer, TCollection value, MessagePackSerializerOptions options)
- {
- if (value == null)
- {
- writer.WriteNil();
- }
- else
- {
- IMessagePackFormatter formatter = options.Resolver.GetFormatterWithVerify();
-
- // Optimize iteration(array is fastest)
- if (value is TElement[] array)
- {
- writer.WriteArrayHeader(array.Length);
-
- foreach (TElement item in array)
- {
- writer.CancellationToken.ThrowIfCancellationRequested();
- formatter.Serialize(ref writer, item, options);
- }
- }
- else
- {
- // knows count or not.
- var seqCount = this.GetCount(value);
- if (seqCount != null)
- {
- writer.WriteArrayHeader(seqCount.Value);
-
- // Unity's foreach struct enumerator causes boxing so iterate manually.
- using (var e = this.GetSourceEnumerator(value))
- {
- while (e.MoveNext())
- {
- writer.CancellationToken.ThrowIfCancellationRequested();
- formatter.Serialize(ref writer, e.Current, options);
- }
- }
- }
- else
- {
- using (var scratchRental = SequencePool.Shared.Rent())
- {
- var scratch = scratchRental.Value;
- MessagePackWriter scratchWriter = writer.Clone(scratch);
- var count = 0;
- using (var e = this.GetSourceEnumerator(value))
- {
- while (e.MoveNext())
- {
- writer.CancellationToken.ThrowIfCancellationRequested();
- count++;
- formatter.Serialize(ref scratchWriter, e.Current, options);
- }
- }
-
- scratchWriter.Flush();
- writer.WriteArrayHeader(count);
- writer.WriteRaw(scratch.AsReadOnlySequence);
- }
- }
- }
- }
- }
-
- public TCollection Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
- {
- if (reader.TryReadNil())
- {
- return default(TCollection);
- }
- else
- {
- IMessagePackFormatter formatter = options.Resolver.GetFormatterWithVerify();
-
- var len = reader.ReadArrayHeader();
-
- TIntermediate list = this.Create(len, options);
- options.Security.DepthStep(ref reader);
- try
- {
- for (int i = 0; i < len; i++)
- {
- reader.CancellationToken.ThrowIfCancellationRequested();
- this.Add(list, i, formatter.Deserialize(ref reader, options), options);
- }
- }
- finally
- {
- reader.Depth--;
- }
-
- return this.Complete(list);
- }
- }
-
- // abstraction for serialize
- protected virtual int? GetCount(TCollection sequence)
- {
- var collection = sequence as ICollection;
- if (collection != null)
- {
- return collection.Count;
- }
- else
- {
- var c2 = sequence as IReadOnlyCollection;
- if (c2 != null)
- {
- return c2.Count;
- }
- }
-
- return null;
- }
-
- // Some collections can use struct iterator, this is optimization path
- protected abstract TEnumerator GetSourceEnumerator(TCollection source);
-
- // abstraction for deserialize
- protected abstract TIntermediate Create(int count, MessagePackSerializerOptions options);
-
- protected abstract void Add(TIntermediate collection, int index, TElement value, MessagePackSerializerOptions options);
-
- protected abstract TCollection Complete(TIntermediate intermediateCollection);
- }
-
- public abstract class CollectionFormatterBase : CollectionFormatterBase, TCollection>
- where TCollection : IEnumerable
- {
- protected override IEnumerator GetSourceEnumerator(TCollection source)
- {
- return source.GetEnumerator();
- }
- }
-
- public abstract class CollectionFormatterBase : CollectionFormatterBase
- where TCollection : IEnumerable
- {
- protected sealed override TCollection Complete(TCollection intermediateCollection)
- {
- return intermediateCollection;
- }
- }
-
- public sealed class GenericCollectionFormatter : CollectionFormatterBase
- where TCollection : ICollection, new()
- {
- protected override TCollection Create(int count, MessagePackSerializerOptions options)
- {
- return new TCollection();
- }
-
- protected override void Add(TCollection collection, int index, TElement value, MessagePackSerializerOptions options)
- {
- collection.Add(value);
- }
- }
-
- public sealed class LinkedListFormatter : CollectionFormatterBase, LinkedList.Enumerator, LinkedList>
- {
- protected override void Add(LinkedList collection, int index, T value, MessagePackSerializerOptions options)
- {
- collection.AddLast(value);
- }
-
- protected override LinkedList Complete(LinkedList intermediateCollection)
- {
- return intermediateCollection;
- }
-
- protected override LinkedList Create(int count, MessagePackSerializerOptions options)
- {
- return new LinkedList();
- }
-
- protected override LinkedList.Enumerator GetSourceEnumerator(LinkedList source)
- {
- return source.GetEnumerator();
- }
- }
-
- public sealed class QueueFormatter : CollectionFormatterBase, Queue.Enumerator, Queue>
- {
- protected override int? GetCount(Queue sequence)
- {
- return sequence.Count;
- }
-
- protected override void Add(Queue collection, int index, T value, MessagePackSerializerOptions options)
- {
- collection.Enqueue(value);
- }
-
- protected override Queue Create(int count, MessagePackSerializerOptions options)
- {
- return new Queue(count);
- }
-
- protected override Queue.Enumerator GetSourceEnumerator(Queue source)
- {
- return source.GetEnumerator();
- }
-
- protected override Queue Complete(Queue intermediateCollection)
- {
- return intermediateCollection;
- }
- }
-
- // should deserialize reverse order.
- public sealed class StackFormatter : CollectionFormatterBase.Enumerator, Stack>
- {
- protected override int? GetCount(Stack sequence)
- {
- return sequence.Count;
- }
-
- protected override void Add(T[] collection, int index, T value, MessagePackSerializerOptions options)
- {
- // add reverse
- collection[collection.Length - 1 - index] = value;
- }
-
- protected override T[] Create(int count, MessagePackSerializerOptions options)
- {
- return new T[count];
- }
-
- protected override Stack.Enumerator GetSourceEnumerator(Stack source)
- {
- return source.GetEnumerator();
- }
-
- protected override Stack Complete(T[] intermediateCollection)
- {
- return new Stack(intermediateCollection);
- }
- }
-
- public sealed class HashSetFormatter : CollectionFormatterBase, HashSet.Enumerator, HashSet>
- {
- protected override int? GetCount(HashSet sequence)
- {
- return sequence.Count;
- }
-
- protected override void Add(HashSet collection, int index, T value, MessagePackSerializerOptions options)
- {
- collection.Add(value);
- }
-
- protected override HashSet Complete(HashSet intermediateCollection)
- {
- return intermediateCollection;
- }
-
- protected override HashSet Create(int count, MessagePackSerializerOptions options)
- {
- return new HashSet(options.Security.GetEqualityComparer());
- }
-
- protected override HashSet.Enumerator GetSourceEnumerator(HashSet source)
- {
- return source.GetEnumerator();
- }
- }
-
- public sealed class ReadOnlyCollectionFormatter : CollectionFormatterBase>
- {
- protected override void Add(T[] collection, int index, T value, MessagePackSerializerOptions options)
- {
- collection[index] = value;
- }
-
- protected override ReadOnlyCollection Complete(T[] intermediateCollection)
- {
- return new ReadOnlyCollection(intermediateCollection);
- }
-
- protected override T[] Create(int count, MessagePackSerializerOptions options)
- {
- return new T[count];
- }
- }
-
- [Obsolete("Use " + nameof(InterfaceListFormatter2) + " instead.")]
- public sealed class InterfaceListFormatter : CollectionFormatterBase>
- {
- protected override void Add(T[] collection, int index, T value, MessagePackSerializerOptions options)
- {
- collection[index] = value;
- }
-
- protected override T[] Create(int count, MessagePackSerializerOptions options)
- {
- return new T[count];
- }
-
- protected override IList Complete(T[] intermediateCollection)
- {
- return intermediateCollection;
- }
- }
-
- [Obsolete("Use " + nameof(InterfaceCollectionFormatter2) + " instead.")]
- public sealed class InterfaceCollectionFormatter : CollectionFormatterBase>
- {
- protected override void Add(T[] collection, int index, T value, MessagePackSerializerOptions options)
- {
- collection[index] = value;
- }
-
- protected override T[] Create(int count, MessagePackSerializerOptions options)
- {
- return new T[count];
- }
-
- protected override ICollection Complete(T[] intermediateCollection)
- {
- return intermediateCollection;
- }
- }
-
- public sealed class InterfaceListFormatter2 : CollectionFormatterBase, IList>
- {
- protected override void Add(List collection, int index, T value, MessagePackSerializerOptions options)
- {
- collection.Add(value);
- }
-
- protected override List Create(int count, MessagePackSerializerOptions options)
- {
- return new List(count);
- }
-
- protected override IList Complete(List intermediateCollection)
- {
- return intermediateCollection;
- }
- }
-
- public sealed class InterfaceCollectionFormatter2 : CollectionFormatterBase, ICollection>
- {
- protected override void Add(List collection, int index, T value, MessagePackSerializerOptions options)
- {
- collection.Add(value);
- }
-
- protected override List Create(int count, MessagePackSerializerOptions options)
- {
- return new List(count);
- }
-
- protected override ICollection Complete(List intermediateCollection)
- {
- return intermediateCollection;
- }
- }
-
- public sealed class InterfaceEnumerableFormatter : CollectionFormatterBase>
- {
- protected override void Add(T[] collection, int index, T value, MessagePackSerializerOptions options)
- {
- collection[index] = value;
- }
-
- protected override T[] Create(int count, MessagePackSerializerOptions options)
- {
- return new T[count];
- }
-
- protected override IEnumerable Complete(T[] intermediateCollection)
- {
- return intermediateCollection;
- }
- }
-
- // [Key, [Array]]
- public sealed class InterfaceGroupingFormatter : IMessagePackFormatter>
- {
- public void Serialize(ref MessagePackWriter writer, IGrouping value, MessagePackSerializerOptions options)
- {
- if (value == null)
- {
- writer.WriteNil();
- }
- else
- {
- writer.WriteArrayHeader(2);
- options.Resolver.GetFormatterWithVerify().Serialize(ref writer, value.Key, options);
- options.Resolver.GetFormatterWithVerify>().Serialize(ref writer, value, options);
- }
- }
-
- public IGrouping Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
- {
- if (reader.TryReadNil())
- {
- return null;
- }
- else
- {
- var count = reader.ReadArrayHeader();
-
- if (count != 2)
- {
- throw new MessagePackSerializationException("Invalid Grouping format.");
- }
-
- options.Security.DepthStep(ref reader);
- try
- {
- TKey key = options.Resolver.GetFormatterWithVerify().Deserialize(ref reader, options);
- IEnumerable value = options.Resolver.GetFormatterWithVerify>().Deserialize(ref reader, options);
- return new Grouping(key, value);
- }
- finally
- {
- reader.Depth--;
- }
- }
- }
- }
-
- public sealed class InterfaceLookupFormatter : CollectionFormatterBase, Dictionary>, ILookup>
- {
- protected override void Add(Dictionary> collection, int index, IGrouping value, MessagePackSerializerOptions options)
- {
- collection.Add(value.Key, value);
- }
-
- protected override ILookup Complete(Dictionary> intermediateCollection)
- {
- return new Lookup(intermediateCollection);
- }
-
- protected override Dictionary> Create(int count, MessagePackSerializerOptions options)
- {
- return new Dictionary>(count);
- }
- }
-
- internal class Grouping : IGrouping
- {
- private readonly TKey key;
- private readonly IEnumerable elements;
-
- public Grouping(TKey key, IEnumerable elements)
- {
- this.key = key;
- this.elements = elements;
- }
-
- public TKey Key
- {
- get
- {
- return this.key;
- }
- }
-
- public IEnumerator GetEnumerator()
- {
- return this.elements.GetEnumerator();
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return this.elements.GetEnumerator();
- }
- }
-
- internal class Lookup : ILookup
- {
- private readonly Dictionary> groupings;
-
- public Lookup(Dictionary> groupings)
- {
- this.groupings = groupings;
- }
-
- public IEnumerable this[TKey key]
- {
- get
- {
- return this.groupings[key];
- }
- }
-
- public int Count
- {
- get
- {
- return this.groupings.Count;
- }
- }
-
- public bool Contains(TKey key)
- {
- return this.groupings.ContainsKey(key);
- }
-
- public IEnumerator> GetEnumerator()
- {
- return this.groupings.Values.GetEnumerator();
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return this.groupings.Values.GetEnumerator();
- }
- }
-
- /* NonGenerics */
-
- public sealed class NonGenericListFormatter : IMessagePackFormatter
- where T : class, IList, new()
- {
- public void Serialize(ref MessagePackWriter writer, T value, MessagePackSerializerOptions options)
- {
- if (value == null)
- {
- writer.WriteNil();
- return;
- }
-
- IMessagePackFormatter