BinaryBufferLib 0.1.4
dotnet add package BinaryBufferLib --version 0.1.4
NuGet\Install-Package BinaryBufferLib -Version 0.1.4
<PackageReference Include="BinaryBufferLib" Version="0.1.4" />
<PackageVersion Include="BinaryBufferLib" Version="0.1.4" />
<PackageReference Include="BinaryBufferLib" />
paket add BinaryBufferLib --version 0.1.4
#r "nuget: BinaryBufferLib, 0.1.4"
#:package BinaryBufferLib@0.1.4
#addin nuget:?package=BinaryBufferLib&version=0.1.4
#tool nuget:?package=BinaryBufferLib&version=0.1.4
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 aReadOnlyMemory<byte>and allows bytes and binary types to be read.FixedBufferandFixedBufferReader: Smaller, simpler ref structs wrapping(ReadOnly)Span<byte>s that are closely analogous toDynamicBuffer/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 withLength,Position, andSeek- Additional list-like features such as
CapacityandEnsurceCapacity(DynamicBufferonly),this[] DynamicBufferimplements theIBufferWriter<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 asIEnumerablesis only supported forBufferReader)
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
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
Streamversions that provide the same features in the form of wrappers around a providedStream- A source generator to automatically create read/write code for custom structures
- Implement Try versions of functions that don't throw on failure
| Product | Versions 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. |
-
.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.