AnyBitStream 1.0.20
dotnet add package AnyBitStream --version 1.0.20
NuGet\Install-Package AnyBitStream -Version 1.0.20
<PackageReference Include="AnyBitStream" Version="1.0.20" />
paket add AnyBitStream --version 1.0.20
#r "nuget: AnyBitStream, 1.0.20"
// Install AnyBitStream as a Cake Addin
#addin nuget:?package=AnyBitStream&version=1.0.20
// Install AnyBitStream as a Cake Tool
#tool nuget:?package=AnyBitStream&version=1.0.20
AnyBitStream
Work with bits efficiently in a stream using standard streams and extending BinaryReader/BinaryWriter.
Description
AnyBitStream is an efficient stream based class for working with data at the bit level. It supports non-standard numeric types such as Int2
to Int7
, Int10,Int12,Int24,Int48
and is perfect for working with network protocols or general bit-packing operations.
Installation
Install AnyBitStream from the Package Manager Console:
PM> Install-Package AnyBitStream
Usage
using AnyBitStream;
var buffer = new byte[64] { // some byte data };
var stream = new BitStream(buffer);
var reader = new BitStreamReader(stream);
// read a 12 byte header
var header = new MyHeader {
Marker = reader.ReadInt4(),
ContinuityId = reader.ReadInt3(),
IsValid = reader.ReadBit(),
Length = reader.ReadInt32()
};
// read in some bytes
var data = reader.ReadBytes(header.Length);
Unaligned vs Aligned bytes
By default, the BitStream
will not allow unaligned data to be read/written. For example, if you've read 5 bits and then try to read a byte an exception will be thrown. Because you tried to read a byte that doesn't reside on a byte boundary (8 bits) it doesn't want to give you potentially bad data. However sometimes this behavior is desired with certain bit packing formats.
To enable reading/writing unaligned data:
// via constructor(s) on the stream
var stream = new BitStream(true);
var stream = new BitStream(buffer, writable: true, allowUnalignedOperations: true);
// via property
stream.AllowUnalignedOperations = true;
// also available via the reader/writers
var reader = new BitStreamReader(stream, leaveOpen: true, allowUnalignedOperations: true);
var writer = new BitStreamWriter(stream, leaveOpen: true, allowUnalignedOperations: true);
See more on reading unaligned streams in the wiki.
Product | Versions |
---|---|
.NET | net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows |
.NET Core | netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1 |
.NET Standard | netstandard2.0 netstandard2.1 |
.NET Framework | net461 net462 net463 net47 net471 net472 net48 net481 |
MonoAndroid | monoandroid |
MonoMac | monomac |
MonoTouch | monotouch |
Tizen | tizen40 tizen60 |
Xamarin.iOS | xamarinios |
Xamarin.Mac | xamarinmac |
Xamarin.TVOS | xamarintvos |
Xamarin.WatchOS | xamarinwatchos |
-
.NETFramework 4.6.1
- No dependencies.
-
.NETFramework 4.6.2
- No dependencies.
-
.NETFramework 4.8
- No dependencies.
-
.NETStandard 2.0
- No dependencies.
-
net5.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.
Work with bits efficiently in a stream using standard streams and extending BinaryReader/BinaryWriter.