Salar.BinaryBuffers
3.0.0
See the version list below for details.
dotnet add package Salar.BinaryBuffers --version 3.0.0
NuGet\Install-Package Salar.BinaryBuffers -Version 3.0.0
<PackageReference Include="Salar.BinaryBuffers" Version="3.0.0" />
paket add Salar.BinaryBuffers --version 3.0.0
#r "nuget: Salar.BinaryBuffers, 3.0.0"
// Install Salar.BinaryBuffers as a Cake Addin #addin nuget:?package=Salar.BinaryBuffers&version=3.0.0 // Install Salar.BinaryBuffers as a Cake Tool #tool nuget:?package=Salar.BinaryBuffers&version=3.0.0
BinaryBuffers
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 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
instead of creating a new one and have less allocations!
Benchmarks
Benchmarks shows up to 59% improvement in writing and 32% in reading.
BinaryBufferReader | ||||
---|---|---|---|---|
Method | Mean | Error | StdDev | Ratio |
BinaryReader_ReadInt |
38.96 ms | 0.198 ms | 0.185 ms | baseline |
BufferReader_ReadInt |
26.51 ms | 0.125 ms | 0.104 ms | -32% |
BinaryReader_ReadDecimal |
45.29 ms | 0.169 ms | 0.158 ms | baseline |
BufferReader_ReadDecimal |
43.49 ms | 0.296 ms | 0.247 ms | -4% |
BinaryReader_ReadFloat |
22.66 ms | 0.049 ms | 0.044 ms | baseline |
BufferReader_ReadFloat |
15.91 ms | 0.071 ms | 0.067 ms | -30% |
BinaryBufferWriter | ||||
---|---|---|---|---|
Method | Mean | Error | StdDev | Ratio |
BinaryWriter_WriteInt |
67.97 ms | 0.361 ms | 0.337 ms | baseline |
BufferWriter_WriteInt |
34.68 ms | 0.225 ms | 0.210 ms | -49% |
BinaryWriter_WriteDecimal |
42.65 ms | 0.290 ms | 0.271 ms | baseline |
BufferWriter_WriteDecimal |
17.30 ms | 0.028 ms | 0.022 ms | -59% |
BinaryWriter_WriteFloat |
34.63 ms | 0.114 ms | 0.101 ms | baseline |
BufferWriter_WriteFloat |
18.53 ms | 0.093 ms | 0.087 ms | -46% |
Performance tests were generated using .NET 6.0.11 on:
AMD Ryzen 9 5900X, 1 CPU, 24 logical and 12 physical cores
Product | Versions 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. |
-
.NETStandard 2.0
- System.Memory (>= 4.5.5)
-
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.
* Improved the performance of the readers
* Added BufferReaderBase as the base of readers
* Added `StreamBufferReader` as a drop in replacement for `BinaryReader` and to widen the support of input types.
* Added `ResetBuffer` to `BinaryBufferReader` which is to reset the underlying buffer and helps reuse `BinaryBufferReader` instead of creating a new one.