My Project
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Properties | List of all members
ZionBandwidthOptimizer.BitPacking.BitPacker Class Reference

A first-in-first-out (FIFO) bit packer that stores data in 4-byte chunks and can be manipulated on a bit level. More...

Public Member Functions

void LoadWritePos (int write, int original)
 
void SaveWritePos (out int write, out int original)
 
void LoadReadPos (int read)
 
void SaveReadPos (out int read)
 
 BitPacker (int capacity=DEFAULT_CAPACITY, int stringCapacity=STRING_CAPACITY, int growMultiplier=GROW_MULTIPLIER, int growAddition=GROW_ADDITION)
 Constructor.
 
void Clear ()
 Resets the position cursors of the bit packer. Does not overwrite values.
 
int PackNonAlloc (byte[] buffer)
 Packs the content of the bit packer into the provided buffer and returns the size of the packed data in bytes. The size of the buffer should be at least the total original size of the data written into the bit packer.
 
byte[] Pack ()
 Packs the content of the bit packer into a byte buffer.
 
byte[] PackWithHeader ()
 
void UnpackWithHeader (byte[] buffer)
 
void Unpack (byte[] buffer, int length)
 Unpacks the provided byte buffer and loads the data into the bit packer overwriting the current content.
 
void IncreaseOriginalSize (int bytes)
 Increases original size counter.
 
void Write (int numBits, uint value)
 Takes the lower numBits from the value and stores them in the bit packer.
 
uint Read (int numBits)
 Reads the next numBits from the bit packer.
 
uint Peek (int numBits)
 Peeks at the next numBits from the bit packer.
 
uint Peek (int numBits, int offsetBits)
 Peeks at the next numBits from the bit packer using and offset.
 
void Insert (int position, int numBits, uint value)
 Inserts data at a given position into the bit packer.
 
void WriteBool (bool value)
 Writes a boolean value into the bit packer.
 
bool ReadBool ()
 Reads a boolean value from the bit packer.
 
bool PeekBool ()
 Peeks at the next boolean value from the bit packer.
 
void WriteByte (byte value)
 Writes a byte value into the bit packer.
 
byte ReadByte ()
 Reads a byte value from the bit packer.
 
byte PeekByte ()
 Peeks at the next byte value from the bit packer.
 
void WriteInt (int value)
 Writes an integer value into the bit packer.
 
int ReadInt ()
 Reads an integer value from the bit packer.
 
int PeekInt ()
 Peeks at the next integer value from the bit packer.
 
void WriteUInt (uint value)
 Writes an unsigned integer value into the bit packer.
 
uint ReadUInt ()
 Reads an unsigned integer value from the bit packer.
 
uint PeekUInt ()
 Peeks at the next unsigned integer value from the bit packer.
 
void WriteFloat (float value)
 Writes a single-precision floating-point value into the bit packer.
 
float ReadFloat ()
 Reads a single-precision floating-point value from the bit packer.
 
float PeekFloat ()
 Peeks at the next single-precision floating-point value from the bit packer.
 
void WriteDouble (double value)
 Writes a double-precision floating-point value into the bit packer.
 
double ReadDouble ()
 Reads a double-precision floating-point value from the bit packer.
 
double PeekDouble ()
 Peeks at the next double-precision floating-point value from the bit packer.
 
void WriteLong (long value)
 Writes a long value into the bit packer.
 
long ReadLong ()
 Reads a long value from the bit packer.
 
long PeekLong ()
 Peeks at the next long value from the bit packer.
 
void WriteULong (ulong value)
 Writes an unsigned long value into the bit packer.
 
ulong ReadULong ()
 Reads an unsigned long value from the bit packer.
 
ulong PeekULong ()
 Peeks at the next unsigned long value from the bit packer.
 
void WriteBytes (byte[] value, int offset=0)
 Writes a byte array into the bit packer.
 
void WriteBytes (byte[] value, int offset, int numBytes)
 Writes a byte array into the bit packer.
 
byte[] ReadBytes (int offset, int numBytes)
 Reads a byte array from the bit packer.
 
void ReadBytes (byte[] value, int offset, int numBytes)
 Reads a byte array from the bit packer.
 
byte[] PeekBytes (int offset, int numBytes)
 Peeks at the next numBytes from the bit packer.
 
void PeekBytes (byte[] value, int offset, int numBytes)
 Peeks at the next numBytes from the bit packer.
 
void WriteStringASCII (string value)
 Writes an ASCII string into the bit packer.
 
string ReadStringASCII ()
 Reads an ASCII string from the bit packer.
 
string PeekStringASCII ()
 Peeks at the next ASCII string from the bit packer.
 
void WriteStringUTF8 (string value)
 Writes an UTF8 string into the bit packer.
 
string ReadStringUTF8 ()
 Reads an UTF8 string from the bit packer.
 
string PeekStringUTF8 ()
 Peeks at the next UTF8 string from the bit packer.
 
void WriteAll< T > (IList< T > collection, int offset=0)
 Writes all items of the collection into the bit packer.
 
void WriteAll< T > (IList< T > collection, int offset, int numElements)
 Writes all items of the collection into the bit packer.
 
byte WriteAllToSize< T > (int maxTotalBytes, int maxIndividualBytes, IList< T > collection, int offset=0)
 Writes items of the collection into the bit packer that satisfy the specified size constraints. Max 255 elements.
 
byte WriteAllToSize< T > (int maxTotalBytes, int maxIndividualBytes, IList< T > collection, int offset, int numElements)
 Writes items of the collection into the bit packer that satisfy the specified size constraints. Max 255 elements.
 
T[] ReadAll< T > ()
 Reads all items and allocates an array for them.
 
uint ReadAllNonAlloc< T > (T[] collection, int offset=0)
 Reads all items into a preallocated array and returns the item count.
 
override string ToString ()
 

Public Attributes

Dictionary< string, CompressorIntints = new Dictionary<string, CompressorInt>()
 
Dictionary< string, CompressorFloatfloats = new Dictionary<string, CompressorFloat>()
 

Properties

int ReadPos [get]
 
int WritePos [get]
 
int PackedBits [get]
 Size of the packed data in bits.
 
int PackedBytes [get]
 Size of the packed data in bytes.
 
int OriginalBits [get]
 Size of the original data in bits.
 
int OriginalBytes [get, set]
 Size of the original data in bytes.
 
int SavedBytes [get]
 Number of bytes saved by the bit packer.
 
float SavedPercentage [get]
 Percentage saved by the bit packer.
 
bool IsFinished [get]
 Returns true if the read position reaches the end of the data.
 

Detailed Description

A first-in-first-out (FIFO) bit packer that stores data in 4-byte chunks and can be manipulated on a bit level.

Constructor & Destructor Documentation

◆ BitPacker()

ZionBandwidthOptimizer.BitPacking.BitPacker.BitPacker ( int  capacity = DEFAULT_CAPACITY,
int  stringCapacity = STRING_CAPACITY,
int  growMultiplier = GROW_MULTIPLIER,
int  growAddition = GROW_ADDITION 
)
inline

Constructor.

Parameters
capacitySize of the bit packer in 4 byte data chunks.
stringCapacityMaximum length of the string that can be written into the bit packer.
growMultiplierMultipler that is used when the internal data structure is expanded.
growAdditionConstant that is used when the internal data structure is expanded.

Member Function Documentation

◆ ReadAll< T >()

T[] ZionBandwidthOptimizer.BitPacking.BitPacker.ReadAll< T > ( )
inline

Reads all items and allocates an array for them.

Type Constraints
T :IBitSerializable 
T :new() 

◆ ReadAllNonAlloc< T >()

uint ZionBandwidthOptimizer.BitPacking.BitPacker.ReadAllNonAlloc< T > ( T[]  collection,
int  offset = 0 
)
inline

Reads all items into a preallocated array and returns the item count.

Type Constraints
T :IBitSerializable 
T :new() 

◆ WriteAll< T >() [1/2]

void ZionBandwidthOptimizer.BitPacking.BitPacker.WriteAll< T > ( IList< T >  collection,
int  offset,
int  numElements 
)
inline

Writes all items of the collection into the bit packer.

Type Constraints
T :IBitSerializable 

◆ WriteAll< T >() [2/2]

void ZionBandwidthOptimizer.BitPacking.BitPacker.WriteAll< T > ( IList< T >  collection,
int  offset = 0 
)
inline

Writes all items of the collection into the bit packer.

Type Constraints
T :IBitSerializable 

◆ WriteAllToSize< T >() [1/2]

byte ZionBandwidthOptimizer.BitPacking.BitPacker.WriteAllToSize< T > ( int  maxTotalBytes,
int  maxIndividualBytes,
IList< T >  collection,
int  offset,
int  numElements 
)
inline

Writes items of the collection into the bit packer that satisfy the specified size constraints. Max 255 elements.

Type Constraints
T :IBitSerializable 

◆ WriteAllToSize< T >() [2/2]

byte ZionBandwidthOptimizer.BitPacking.BitPacker.WriteAllToSize< T > ( int  maxTotalBytes,
int  maxIndividualBytes,
IList< T >  collection,
int  offset = 0 
)
inline

Writes items of the collection into the bit packer that satisfy the specified size constraints. Max 255 elements.

Type Constraints
T :IBitSerializable 

The documentation for this class was generated from the following file: