BinaryBufferLib 0.1.4

dotnet add package BinaryBufferLib --version 0.1.4
                    
NuGet\Install-Package BinaryBufferLib -Version 0.1.4
                    
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="BinaryBufferLib" Version="0.1.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BinaryBufferLib" Version="0.1.4" />
                    
Directory.Packages.props
<PackageReference Include="BinaryBufferLib" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BinaryBufferLib --version 0.1.4
                    
#r "nuget: BinaryBufferLib, 0.1.4"
                    
#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.
#:package BinaryBufferLib@0.1.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BinaryBufferLib&version=0.1.4
                    
Install as a Cake Addin
#tool nuget:?package=BinaryBufferLib&version=0.1.4
                    
Install as a Cake Tool

BinaryBufferLib

A .NET library of lightweight objects for reading and writing binary data that prioritizes convenience. Access is stream-like, allowing for efficient serialization. Numerous value-added features such as automatic conversion between endians and reading and writing enumerables exist.

Overview

Four classes designed for different use cases, forming two pairs:

  • DynamicBuffer: A class with a self-resizing buffer that bytes and binary types can be read from and written to, intended for writing out entire files or variable-sized structures.
  • BufferReader: A struct that wraps a ReadOnlyMemory<byte> and allows bytes and binary types to be read.
  • FixedBuffer and FixedBufferReader: Smaller, simpler ref structs wrapping (ReadOnly)Span<byte>s that are closely analogous to DynamicBuffer/BufferReader, but lack some features that cannot be supported with ref structs. Intended for reading and writing individual, fixed-size structures.

Key features:

  • Stream-like semantics with Length, Position, and Seek
  • Additional list-like features such as Capacity and EnsurceCapacity (DynamicBuffer only), this[]
  • DynamicBuffer implements the IBufferWriter<byte> interface for writing custom types
  • Big, little, and native endian versions of all read/write functions exist
  • Support for built-in integer and floating-point types
  • Support for arrays through type[], (ReadOnly)Span, I(ReadOnly)List, IEnumerable (reading arrays as IEnumerables is only supported for BufferReader)

Current state:

  • 0.x versions are essentially experimental/evaluation, with breaking changes possible in response to user feedback on the design. Once it reaches 1.0 it will follow semantic versioning and maintain a backward compatible API.
  • Needs more documentation
  • Needs more unit tests

Usage

Example

FAQ

Why?

Because every alternative left something to be desired. BinaryPrimitives provided the mechanism for reading, writing, and endian conversion, but is intolerably verbose. BinaryReader/BinaryWriter have the right idea in general, but either require manual endian conversion or place constraints on the format of the data; additionally, they were relatively heavy as they sit on top of a Stream. A number of other packages exist with similar functionality, but all lacked at least one useful feature.

Ultimately BinaryBufferLib was created to answer the question "what is the easiest way to read and write arbitrary binary packets and files with no constraints on the format of that data?"

Why a stream-like interface?

This is generally the most efficient way to read/write objects. The alternative would be to provide an offset to read/write the specified item at, but this becomes very cumbersome very quickly, requiring numerous hard-coded offsets to structure members.

What features might be added in the future?

Some possibilities:

  • A per-buffer property that specifies the default endian so the endian suffixes can be omitted from functions
  • Support for strings
  • Support for specialized formats such as 7-bit integers
  • Stream versions that provide the same features in the form of wrappers around a provided Stream
  • A source generator to automatically create read/write code for custom structures
  • Implement Try versions of functions that don't throw on failure
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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.1

    • No dependencies.
  • net5.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.4 89 11/10/2026
0.1.3 102 11/8/2026
0.1.2 98 11/8/2026
0.1.1 92 11/7/2026
0.1.0 92 11/7/2026