Salar.BinaryBuffers 3.3.0

dotnet add package Salar.BinaryBuffers --version 3.3.0                
NuGet\Install-Package Salar.BinaryBuffers -Version 3.3.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Salar.BinaryBuffers" Version="3.3.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Salar.BinaryBuffers --version 3.3.0                
#r "nuget: Salar.BinaryBuffers, 3.3.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Salar.BinaryBuffers as a Cake Addin
#addin nuget:?package=Salar.BinaryBuffers&version=3.3.0

// Install Salar.BinaryBuffers as a Cake Tool
#tool nuget:?package=Salar.BinaryBuffers&version=3.3.0                

BinaryBuffers

logo

NuGet

BinaryBuffers offers a highly performant implementation of BinaryReader and BinaryWriter, working directly on a byte array, thus eliminating the need for an intermediate Stream object.

How to use

BinaryBufferReader and BinaryBufferWriter are the respective names of the reader and writer. Both classes operate on a byte[] as its underlying data buffer.

// Provide a buffer to the reader/writer
var buffer = new byte[100];

// Write to the buffer
var writer = new BinaryBufferWriter(buffer);

writer.Write(2022);
writer.Write(8.11);

// Read from the buffer
var reader = new BinaryBufferReader(buffer);

var year = reader.ReadInt32();
var time = reader.ReadDouble();

Additional Goodies

Use StreamBufferWriter as a drop in replacement for BinaryWriter to gain ~10% improvement in performance.

Use StreamBufferReader as a drop in replacement for BinaryReader. Note that there is no performance benefit in using StreamBufferReader, it just helps widen the use of IBufferReader.

Use ResetBuffer method in BinaryBufferReader and BinaryBufferWriter instead of creating a new one and have less allocations!

Benchmarks

Benchmarks shows up to 92% improvement in writing and 84% in reading.

BinaryBufferReader
Method Mean Error StdDev Ratio
BinaryReader_ReadInt 42.23 ms 0.1487 ms 0.1318 ms baseline
BufferReader_ReadInt 5.53 ms 0.0265 ms 0.0221 ms -89%
BinaryReader_ReadDecimal 48.28 ms 0.2038 ms 0.1906 ms baseline
BufferReader_ReadDecimal 34.75 ms 0.3921 ms 0.3476 ms -28%
BinaryReader_ReadFloat 25.76 ms 0.1012 ms 0.0947 ms baseline
BufferReader_ReadFloat 3.75 ms 0.0209 ms 0.0195 ms -92%
BinaryBufferWriter
Method Mean Error StdDev Ratio
BinaryWriter_WriteInt 62.71 ms 0.5090 ms 0.4761 ms baseline
BufferWriter_WriteInt 11.05 ms 0.0307 ms 0.0240 ms -77%
BinaryWriter_WriteDecimal 42.07 ms 0.1556 ms 0.1455 ms baseline
BufferWriter_WriteDecimal 7.79 ms 0.0191 ms 0.0169 ms -84%
BinaryWriter_WriteFloat 33.38 ms 0.1869 ms 0.1561 ms baseline
BufferWriter_WriteFloat 7.79 ms 0.0191 ms 0.0169 ms -84%

Performance tests were generated using .NET 7.0.5 on:

AMD Ryzen 9 5900X, 1 CPU, 24 logical and 12 physical cores
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Salar.BinaryBuffers:

Package Downloads
Salar.Bois

The most compact, extermly fast binary serializer for .NET Code and .NET Framework. More info: https://github.com/salarcode/Bois

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.3.0 3,077 7/7/2023
3.2.0 9,210 7/1/2023
3.1.0 2,503 11/30/2022
3.0.1 345 11/27/2022
3.0.0 359 11/26/2022
2.0.0 478 7/30/2022
1.1.0 2,519 9/30/2019
1.0.0 525 8/29/2019

* Improved the performance of BinaryBufferWriter.
* Improved the performance of BinaryBufferReader.