MsgPack.PackerUnpackerStreamOptions Class Reference

Represents options for stream on Packer/Unpacker creation. More...

Public Member Functions

 PackerUnpackerStreamOptions ()
 Initializes a new instance of the PackerUnpackerStreamOptions class. More...
 

Properties

bool WithBuffering [get, set]
 Gets or sets a value indicating whether stream should be wrapped with buffering stream. More...
 
int? BufferSize [get, set]
 Gets or sets the size of the buffer of wrapping stream in bytes used when WithBuffering is true. More...
 
bool OwnsStream [get, set]
 Gets or sets a value indicating whether Packer/Unpacker will dispose underlying stream when their Dispose(Boolean) method are called with true value. More...
 

Detailed Description

Represents options for stream on Packer/Unpacker creation.

Constructor & Destructor Documentation

◆ PackerUnpackerStreamOptions()

MsgPack.PackerUnpackerStreamOptions.PackerUnpackerStreamOptions ( )

Initializes a new instance of the PackerUnpackerStreamOptions class.

Property Documentation

◆ BufferSize

int? MsgPack.PackerUnpackerStreamOptions.BufferSize
getset

Gets or sets the size of the buffer of wrapping stream in bytes used when WithBuffering is true.

The size of the buffer of wrapping stream in bytes used when WithBuffering is true. The default is 64K. If you attempt to set 0 or negative value, then the value will be set to 1.

◆ OwnsStream

bool MsgPack.PackerUnpackerStreamOptions.OwnsStream
getset

Gets or sets a value indicating whether Packer/Unpacker will dispose underlying stream when their Dispose(Boolean) method are called with true value.

true if Packer/Unpacker will dispose underlying stream when their Dispose(Boolean) method are called with true value; otherwise, false.

◆ WithBuffering

bool MsgPack.PackerUnpackerStreamOptions.WithBuffering
getset

Gets or sets a value indicating whether stream should be wrapped with buffering stream.

true if stream should be wrapped with buffering stream; otherwise, false.

This option is important to improve asynchronous operation performance because deserialization tend to be chatty, so many tiny asynchrnous operation are issued and then numerous context switching may occurred. Wrapping with buffering stream mitigate context switching because it should avoid asynchronous operation as long as it has buffered value.

Current built-in Unpacker implementation uses BufferedStream for buffering, and avoid buffering for following in-memory or stream with buffering feature:

  • System.IO.BufferedStream itself.
  • System.IO.MemoryStream.
  • System.IO.UnmanagedMemoryStream.
  • System.IO.FileStream which has own internal buffer.

Logically, it is preferred that you should wrap with System.IO.BufferedStream yourself for underlying stream for wrapper stream such as System.IO.Compression.DeflateStream, System.Security.Cryptography.CryptoStream, etc.

See also
BufferSize

The documentation for this class was generated from the following file:
  • MsgPackSources/PackerUnpackerStreamOptions.cs