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:
Diffstat (limited to 'src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Formatters/CollectionFormatter.cs')
-rw-r--r--src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Formatters/CollectionFormatter.cs45
1 files changed, 43 insertions, 2 deletions
diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Formatters/CollectionFormatter.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Formatters/CollectionFormatter.cs
index 590719e4..c7cc8272 100644
--- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Formatters/CollectionFormatter.cs
+++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Formatters/CollectionFormatter.cs
@@ -346,7 +346,7 @@ namespace MessagePack.Formatters
}
else
{
- using (var scratchRental = SequencePool.Shared.Rent())
+ using (var scratchRental = options.SequencePool.Rent())
{
var scratch = scratchRental.Value;
MessagePackWriter scratchWriter = writer.Clone(scratch);
@@ -464,6 +464,25 @@ namespace MessagePack.Formatters
}
}
+ public sealed class GenericEnumerableFormatter<TElement, TCollection> : CollectionFormatterBase<TElement, TElement[], TCollection>
+ where TCollection : IEnumerable<TElement>
+ {
+ protected override TElement[] Create(int count, MessagePackSerializerOptions options)
+ {
+ return new TElement[count];
+ }
+
+ protected override void Add(TElement[] collection, int index, TElement value, MessagePackSerializerOptions options)
+ {
+ collection[index] = value;
+ }
+
+ protected override TCollection Complete(TElement[] intermediateCollection)
+ {
+ return (TCollection)Activator.CreateInstance(typeof(TCollection), intermediateCollection);
+ }
+ }
+
public sealed class LinkedListFormatter<T> : CollectionFormatterBase<T, LinkedList<T>, LinkedList<T>.Enumerator, LinkedList<T>>
{
protected override void Add(LinkedList<T> collection, int index, T value, MessagePackSerializerOptions options)
@@ -950,7 +969,7 @@ namespace MessagePack.Formatters
IMessagePackFormatter<object> formatter = options.Resolver.GetFormatterWithVerify<object>();
- using (var scratchRental = SequencePool.Shared.Rent())
+ using (var scratchRental = options.SequencePool.Rent())
{
var scratch = scratchRental.Value;
MessagePackWriter scratchWriter = writer.Clone(scratch);
@@ -1271,6 +1290,28 @@ namespace MessagePack.Formatters
}
}
+#if NET5_0_OR_GREATER
+
+ public sealed class InterfaceReadOnlySetFormatter<T> : CollectionFormatterBase<T, HashSet<T>, IReadOnlySet<T>>
+ {
+ protected override void Add(HashSet<T> collection, int index, T value, MessagePackSerializerOptions options)
+ {
+ collection.Add(value);
+ }
+
+ protected override IReadOnlySet<T> Complete(HashSet<T> intermediateCollection)
+ {
+ return intermediateCollection;
+ }
+
+ protected override HashSet<T> Create(int count, MessagePackSerializerOptions options)
+ {
+ return new HashSet<T>(options.Security.GetEqualityComparer<T>());
+ }
+ }
+
+#endif
+
public sealed class ConcurrentBagFormatter<T> : CollectionFormatterBase<T, System.Collections.Concurrent.ConcurrentBag<T>>
{
protected override int? GetCount(ConcurrentBag<T> sequence)