diff options
author | Israel Lot <israel.lot@gmail.com> | 2021-12-15 18:02:21 +0300 |
---|---|---|
committer | Israel Lot <israel.lot@gmail.com> | 2021-12-15 18:17:04 +0300 |
commit | e4fad534b2bec20e760dc5909292e63dcf26de64 (patch) | |
tree | 25f301b99b4cfd9a06b63d7e550105ead8374bbf /src | |
parent | 773e61920a408582517bae35f3ccb9fb3e29a13c (diff) |
Add CompressionMinLength parameter to MessagePackSerializerOptions
Add CompressionMinLength field to unpublished api spec
Diffstat (limited to 'src')
7 files changed, 43 insertions, 9 deletions
diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.Json.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.Json.cs index 1d604957..38e39985 100644 --- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.Json.cs +++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.Json.cs @@ -171,7 +171,7 @@ namespace MessagePack } scratchWriter.Flush(); - ToLZ4BinaryCore(scratchRental.Value, ref writer, options.Compression); + ToLZ4BinaryCore(scratchRental.Value, ref writer, options.Compression, options.CompressionMinLength); } } else diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.cs index 0e0188cf..56f838f8 100644 --- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.cs +++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.cs @@ -18,7 +18,6 @@ namespace MessagePack [System.Diagnostics.CodeAnalysis.SuppressMessage("ApiDesign", "RS0026:Do not add multiple public overloads with optional parameters", Justification = "Each overload has sufficiently unique required parameters.")] public static partial class MessagePackSerializer { - private const int LZ4NotCompressionSizeInLz4BlockType = 64; private const int MaxHintSize = 1024 * 1024; /// <summary> @@ -85,7 +84,7 @@ namespace MessagePack MessagePackWriter scratchWriter = writer.Clone(scratch); options.Resolver.GetFormatterWithVerify<T>().Serialize(ref scratchWriter, value, options); scratchWriter.Flush(); - ToLZ4BinaryCore(scratch, ref writer, options.Compression); + ToLZ4BinaryCore(scratch, ref writer, options.Compression, options.CompressionMinLength); } } else @@ -555,11 +554,11 @@ namespace MessagePack return false; } - private static void ToLZ4BinaryCore(in ReadOnlySequence<byte> msgpackUncompressedData, ref MessagePackWriter writer, MessagePackCompression compression) + private static void ToLZ4BinaryCore(in ReadOnlySequence<byte> msgpackUncompressedData, ref MessagePackWriter writer, MessagePackCompression compression, int minCompressionSize) { if (compression == MessagePackCompression.Lz4Block) { - if (msgpackUncompressedData.Length < LZ4NotCompressionSizeInLz4BlockType) + if (msgpackUncompressedData.Length < minCompressionSize) { writer.WriteRaw(msgpackUncompressedData); return; diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializerOptions.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializerOptions.cs index ebf1ca43..9087790b 100644 --- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializerOptions.cs +++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializerOptions.cs @@ -41,6 +41,7 @@ namespace MessagePack protected internal MessagePackSerializerOptions(IFormatterResolver resolver) { this.Resolver = resolver ?? throw new ArgumentNullException(nameof(resolver)); + this.CompressionMinLength = 64; } /// <summary> @@ -57,6 +58,7 @@ namespace MessagePack this.Resolver = copyFrom.Resolver; this.Compression = copyFrom.Compression; + this.CompressionMinLength = copyFrom.CompressionMinLength; this.OldSpec = copyFrom.OldSpec; this.OmitAssemblyVersion = copyFrom.OmitAssemblyVersion; this.AllowAssemblyVersionMismatch = copyFrom.AllowAssemblyVersionMismatch; @@ -82,6 +84,14 @@ namespace MessagePack public MessagePackCompression Compression { get; private set; } /// <summary> + /// Gets the min sequence length allowed for compression. + /// </summary> + /// <remarks> + /// Sequences with length less then this value will skip block compression. + /// </remarks> + public int CompressionMinLength { get; private set; } + + /// <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> @@ -195,6 +205,23 @@ 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.</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; + } + + var result = this.Clone(); + result.CompressionMinLength = compressionMinLength; + 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> diff --git a/src/MessagePack/net5.0/PublicAPI.Unshipped.txt b/src/MessagePack/net5.0/PublicAPI.Unshipped.txt index 1447ef0d..dca33bb1 100644 --- a/src/MessagePack/net5.0/PublicAPI.Unshipped.txt +++ b/src/MessagePack/net5.0/PublicAPI.Unshipped.txt @@ -9,6 +9,8 @@ MessagePack.Formatters.InterfaceReadOnlySetFormatter<T>.InterfaceReadOnlySetForm MessagePack.MessagePackReader.MessagePackReader() -> void MessagePack.MessagePackSerializerOptions.SequencePool.get -> MessagePack.SequencePool MessagePack.MessagePackSerializerOptions.WithPool(MessagePack.SequencePool pool) -> MessagePack.MessagePackSerializerOptions +MessagePack.MessagePackSerializerOptions.WithCompressionMinLength(int compressionMinLength) -> MessagePack.MessagePackSerializerOptions +MessagePack.MessagePackSerializerOptions.CompressionMinLength.get -> int MessagePack.MessagePackStreamReader.MessagePackStreamReader(System.IO.Stream stream, bool leaveOpen, MessagePack.SequencePool sequencePool) -> void MessagePack.MessagePackStreamReader.ReadArrayHeaderAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask<int> MessagePack.MessagePackStreamReader.ReadMapHeaderAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask<int> @@ -25,4 +27,4 @@ virtual MessagePack.MessagePackStreamReader.Dispose(bool disposing) -> void MessagePack.Formatters.GenericEnumerableFormatter<TElement, TCollection> MessagePack.Formatters.GenericEnumerableFormatter<TElement, TCollection>.GenericEnumerableFormatter() -> void MessagePack.Formatters.GenericReadOnlyDictionaryFormatter<TKey, TValue, TDictionary> -MessagePack.Formatters.GenericReadOnlyDictionaryFormatter<TKey, TValue, TDictionary>.GenericReadOnlyDictionaryFormatter() -> void
\ No newline at end of file +MessagePack.Formatters.GenericReadOnlyDictionaryFormatter<TKey, TValue, TDictionary>.GenericReadOnlyDictionaryFormatter() -> void diff --git a/src/MessagePack/netcoreapp2.1/PublicAPI.Unshipped.txt b/src/MessagePack/netcoreapp2.1/PublicAPI.Unshipped.txt index f053d3cd..b2746b1b 100644 --- a/src/MessagePack/netcoreapp2.1/PublicAPI.Unshipped.txt +++ b/src/MessagePack/netcoreapp2.1/PublicAPI.Unshipped.txt @@ -4,6 +4,8 @@ MessagePack.FormatterNotRegisteredException.FormatterNotRegisteredException(Syst MessagePack.MessagePackReader.MessagePackReader() -> void MessagePack.MessagePackSerializerOptions.SequencePool.get -> MessagePack.SequencePool MessagePack.MessagePackSerializerOptions.WithPool(MessagePack.SequencePool pool) -> MessagePack.MessagePackSerializerOptions +MessagePack.MessagePackSerializerOptions.WithCompressionMinLength(int compressionMinLength) -> MessagePack.MessagePackSerializerOptions +MessagePack.MessagePackSerializerOptions.CompressionMinLength.get -> int MessagePack.MessagePackStreamReader.MessagePackStreamReader(System.IO.Stream stream, bool leaveOpen, MessagePack.SequencePool sequencePool) -> void MessagePack.MessagePackWriter.MessagePackWriter() -> void MessagePack.SequencePool @@ -17,4 +19,4 @@ virtual MessagePack.MessagePackStreamReader.Dispose(bool disposing) -> void MessagePack.Formatters.GenericEnumerableFormatter<TElement, TCollection> MessagePack.Formatters.GenericEnumerableFormatter<TElement, TCollection>.GenericEnumerableFormatter() -> void MessagePack.Formatters.GenericReadOnlyDictionaryFormatter<TKey, TValue, TDictionary> -MessagePack.Formatters.GenericReadOnlyDictionaryFormatter<TKey, TValue, TDictionary>.GenericReadOnlyDictionaryFormatter() -> void
\ No newline at end of file +MessagePack.Formatters.GenericReadOnlyDictionaryFormatter<TKey, TValue, TDictionary>.GenericReadOnlyDictionaryFormatter() -> void diff --git a/src/MessagePack/netcoreapp3.1/PublicAPI.Unshipped.txt b/src/MessagePack/netcoreapp3.1/PublicAPI.Unshipped.txt index 73b4e7c0..8b63c2e9 100644 --- a/src/MessagePack/netcoreapp3.1/PublicAPI.Unshipped.txt +++ b/src/MessagePack/netcoreapp3.1/PublicAPI.Unshipped.txt @@ -4,6 +4,8 @@ MessagePack.FormatterNotRegisteredException.FormatterNotRegisteredException(Syst MessagePack.MessagePackReader.MessagePackReader() -> void MessagePack.MessagePackSerializerOptions.SequencePool.get -> MessagePack.SequencePool MessagePack.MessagePackSerializerOptions.WithPool(MessagePack.SequencePool pool) -> MessagePack.MessagePackSerializerOptions +MessagePack.MessagePackSerializerOptions.WithCompressionMinLength(int compressionMinLength) -> MessagePack.MessagePackSerializerOptions +MessagePack.MessagePackSerializerOptions.CompressionMinLength.get -> int MessagePack.MessagePackStreamReader.MessagePackStreamReader(System.IO.Stream stream, bool leaveOpen, MessagePack.SequencePool sequencePool) -> void MessagePack.MessagePackStreamReader.ReadArrayHeaderAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask<int> MessagePack.MessagePackStreamReader.ReadMapHeaderAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask<int> @@ -19,4 +21,4 @@ virtual MessagePack.MessagePackStreamReader.Dispose(bool disposing) -> void MessagePack.Formatters.GenericEnumerableFormatter<TElement, TCollection> MessagePack.Formatters.GenericEnumerableFormatter<TElement, TCollection>.GenericEnumerableFormatter() -> void MessagePack.Formatters.GenericReadOnlyDictionaryFormatter<TKey, TValue, TDictionary> -MessagePack.Formatters.GenericReadOnlyDictionaryFormatter<TKey, TValue, TDictionary>.GenericReadOnlyDictionaryFormatter() -> void
\ No newline at end of file +MessagePack.Formatters.GenericReadOnlyDictionaryFormatter<TKey, TValue, TDictionary>.GenericReadOnlyDictionaryFormatter() -> void diff --git a/src/MessagePack/netstandard2.0/PublicAPI.Unshipped.txt b/src/MessagePack/netstandard2.0/PublicAPI.Unshipped.txt index 73b4e7c0..8b63c2e9 100644 --- a/src/MessagePack/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/MessagePack/netstandard2.0/PublicAPI.Unshipped.txt @@ -4,6 +4,8 @@ MessagePack.FormatterNotRegisteredException.FormatterNotRegisteredException(Syst MessagePack.MessagePackReader.MessagePackReader() -> void MessagePack.MessagePackSerializerOptions.SequencePool.get -> MessagePack.SequencePool MessagePack.MessagePackSerializerOptions.WithPool(MessagePack.SequencePool pool) -> MessagePack.MessagePackSerializerOptions +MessagePack.MessagePackSerializerOptions.WithCompressionMinLength(int compressionMinLength) -> MessagePack.MessagePackSerializerOptions +MessagePack.MessagePackSerializerOptions.CompressionMinLength.get -> int MessagePack.MessagePackStreamReader.MessagePackStreamReader(System.IO.Stream stream, bool leaveOpen, MessagePack.SequencePool sequencePool) -> void MessagePack.MessagePackStreamReader.ReadArrayHeaderAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask<int> MessagePack.MessagePackStreamReader.ReadMapHeaderAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask<int> @@ -19,4 +21,4 @@ virtual MessagePack.MessagePackStreamReader.Dispose(bool disposing) -> void MessagePack.Formatters.GenericEnumerableFormatter<TElement, TCollection> MessagePack.Formatters.GenericEnumerableFormatter<TElement, TCollection>.GenericEnumerableFormatter() -> void MessagePack.Formatters.GenericReadOnlyDictionaryFormatter<TKey, TValue, TDictionary> -MessagePack.Formatters.GenericReadOnlyDictionaryFormatter<TKey, TValue, TDictionary>.GenericReadOnlyDictionaryFormatter() -> void
\ No newline at end of file +MessagePack.Formatters.GenericReadOnlyDictionaryFormatter<TKey, TValue, TDictionary>.GenericReadOnlyDictionaryFormatter() -> void |