Skip to content

Commit 785882c

Browse files
committed
Change default buffer size for byte array based serialization.
1 parent a99bfed commit 785882c

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

src/MsgPack/Serialization/MessagePackSerializer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public abstract partial class MessagePackSerializer : IMessagePackSingleObjectSe
3939
{
4040
internal static readonly UnpackerOptions DefaultUnpackerOptions = new UnpackerOptions { ValidationLevel = UnpackerValidationLevel.None };
4141

42+
internal const int BufferSize = 256;
43+
4244
private readonly SerializationContext _ownerContext;
4345

4446
/// <summary>

src/MsgPack/Serialization/MessagePackSerializer`1.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ protected internal virtual Task UnpackToAsyncCore( Unpacker unpacker, T collecti
869869
public byte[] PackSingleObject( T objectTree )
870870
{
871871
// Packer does not have finalizer, so just avoiding unpacker disposing prevents stream closing.
872-
var packer = Packer.Create( new byte[ 64 * 1024 ], this.PackerCompatibilityOptions );
872+
var packer = Packer.Create( BufferManager.NewByteBuffer( BufferSize ), this.PackerCompatibilityOptions );
873873

874874
this.PackTo( packer, objectTree );
875875
return packer.GetResultBytes();
@@ -916,7 +916,7 @@ public Task<byte[]> PackSingleObjectAsync( T objectTree )
916916
public async Task<byte[]> PackSingleObjectAsync( T objectTree, CancellationToken cancellationToken )
917917
{
918918
// Packer does not have finalizer, so just avoiding unpacker disposing prevents stream closing.
919-
var packer = Packer.Create( new byte[ 64 * 1024 ], this.PackerCompatibilityOptions );
919+
var packer = Packer.Create( BufferManager.NewByteBuffer( BufferSize ), this.PackerCompatibilityOptions );
920920

921921
await this.PackToAsync( packer, objectTree, cancellationToken ).ConfigureAwait( false );
922922
return packer.GetResultBytes();

0 commit comments

Comments
 (0)