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/MessagePackSerializerOptions.cs')
-rw-r--r--src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializerOptions.cs68
1 files changed, 67 insertions, 1 deletions
diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializerOptions.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializerOptions.cs
index bc1557b0..de2bb4b8 100644
--- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializerOptions.cs
+++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializerOptions.cs
@@ -42,7 +42,7 @@ namespace MessagePack
/// <summary>
/// Initializes a new instance of the <see cref="MessagePackSerializerOptions"/> class.
/// </summary>
- protected internal MessagePackSerializerOptions(IFormatterResolver resolver)
+ public MessagePackSerializerOptions(IFormatterResolver resolver)
{
this.Resolver = resolver ?? throw new ArgumentNullException(nameof(resolver));
}
@@ -61,6 +61,8 @@ namespace MessagePack
this.Resolver = copyFrom.Resolver;
this.Compression = copyFrom.Compression;
+ this.CompressionMinLength = copyFrom.CompressionMinLength;
+ this.SuggestedContiguousMemorySize = copyFrom.SuggestedContiguousMemorySize;
this.OldSpec = copyFrom.OldSpec;
this.OmitAssemblyVersion = copyFrom.OmitAssemblyVersion;
this.AllowAssemblyVersionMismatch = copyFrom.AllowAssemblyVersionMismatch;
@@ -86,6 +88,26 @@ namespace MessagePack
public MessagePackCompression Compression { get; private set; }
/// <summary>
+ /// Gets the length a serialized msgpack result must equal or exceed before <see cref="Compression"/> is applied.
+ /// </summary>
+ /// <value>The default value is 64.</value>
+ /// <remarks>
+ /// When compression is <em>not</em> applied due to a short serialized result, deserialization will still succeed
+ /// even if <see cref="Compression"/> is set to something other than <see cref="MessagePackCompression.None"/>.
+ /// </remarks>
+ public int CompressionMinLength { get; private set; } = 64;
+
+ /// <summary>
+ /// Gets the size of contiguous memory blocks in bytes that may be allocated for buffering purposes.
+ /// </summary>
+ /// <value>The default value is 1MB.</value>
+ /// <remarks>
+ /// Larger values may perform a bit faster, but may result in adding a runtime perf tax due to using the
+ /// <see href="https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/large-object-heap">Large Object Heap</see>.
+ /// </remarks>
+ public int SuggestedContiguousMemorySize { get; private set; } = 1024 * 1024;
+
+ /// <summary>
/// Gets a value indicating whether to serialize with <see cref="MessagePackWriter.OldSpec"/> set to some value
/// causing messagepack spec compliance to be explicitly set to the old or new format.
/// </summary>
@@ -199,6 +221,50 @@ namespace MessagePack
}
/// <summary>
+ /// Gets a copy of these options with the <see cref="CompressionMinLength"/> property set to a new value.
+ /// </summary>
+ /// <param name="compressionMinLength">The new value for the <see cref="CompressionMinLength"/> property. Must be a positive integer.</param>
+ /// <returns>The new instance; or the original if the value is unchanged.</returns>
+ public MessagePackSerializerOptions WithCompressionMinLength(int compressionMinLength)
+ {
+ if (this.CompressionMinLength == compressionMinLength)
+ {
+ return this;
+ }
+
+ if (compressionMinLength <= 0)
+ {
+ throw new ArgumentOutOfRangeException(nameof(compressionMinLength));
+ }
+
+ var result = this.Clone();
+ result.CompressionMinLength = compressionMinLength;
+ return result;
+ }
+
+ /// <summary>
+ /// Gets a copy of these options with the <see cref="SuggestedContiguousMemorySize"/> property set to a new value.
+ /// </summary>
+ /// <param name="suggestedContiguousMemorySize">The new value for the <see cref="SuggestedContiguousMemorySize"/> property. Must be at least 256.</param>
+ /// <returns>The new instance; or the original if the value is unchanged.</returns>
+ public MessagePackSerializerOptions WithSuggestedContiguousMemorySize(int suggestedContiguousMemorySize)
+ {
+ if (this.SuggestedContiguousMemorySize == suggestedContiguousMemorySize)
+ {
+ return this;
+ }
+
+ if (suggestedContiguousMemorySize < 256)
+ {
+ throw new ArgumentOutOfRangeException(nameof(suggestedContiguousMemorySize), "This should be at least 256");
+ }
+
+ var result = this.Clone();
+ result.SuggestedContiguousMemorySize = suggestedContiguousMemorySize;
+ return result;
+ }
+
+ /// <summary>
/// Gets a copy of these options with the <see cref="OldSpec"/> property set to a new value.
/// </summary>
/// <param name="oldSpec">The new value for the <see cref="OldSpec"/>.</param>