AnyBitStream 1.0.20

Work with bits efficiently in a stream using standard streams and extending BinaryReader/BinaryWriter.

Install-Package AnyBitStream -Version 1.0.20
dotnet add package AnyBitStream --version 1.0.20
<PackageReference Include="AnyBitStream" Version="1.0.20" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AnyBitStream --version 1.0.20
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: AnyBitStream, 1.0.20"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// 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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

AnyBitStream

nuget
nuget
Build status
Codacy Badge

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.

AnyBitStream

nuget
nuget
Build status
Codacy Badge

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.

Release Notes

Work with bits efficiently in a stream using standard streams and extending BinaryReader/BinaryWriter.

  • .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.

Version History

Version Downloads Last updated
1.0.20 102 3/4/2021
1.0.19 109 3/4/2021
1.0.18 60 3/3/2021
1.0.17 56 3/3/2021
1.0.16 53 3/3/2021
1.0.15 65 3/2/2021
1.0.14 63 3/2/2021
1.0.10 53 3/1/2021
1.0.7 66 3/1/2021
1.0.3 52 3/1/2021