Detailed Description

This class is a wrapper for any block of bytes. It allows values to be read from the stream one at a time. Works best with streams created by BinaryIO.Writer.

Inheritance diagram for BinaryIO.Reader:
Loonim.TextureReader

Public Member Functions

 Reader (Stream stream)
 Creates a new reader for the given stream. More...
 
 Reader (byte[] src)
 Creates a new reader for the given block of bytes. More...
 
byte[] ReadImageBytes ()
 Reads the bytes of a texture from the stream. More...
 
void Skip (int count)
 
int PeekByte ()
 Gets the value of the next byte in the stream. More...
 
virtual long MarkStart ()
 The current starting location. More...
 
long PackedInt ()
 Reads a packed integer from the stream. Not the opposite of More...
 
float ReadInt16F (float low, float width)
 Reads a compressed floating point value from the stream. Compressed floats are stored as a ushort. Their value represents a percentage of a range (i.e. it gets divided by the max ushort value 64k), where 64k = 100% (the top of the range, low + width). More...
 
ulong ReadUInt48 ()
 
ulong ReadUInt40 ()
 
long ReadInt40 ()
 
uint ReadUInt24 ()
 Reads a 3 byte unsigned integer from the stream. More...
 
int ReadInt24 ()
 Reads a 3 byte integer from the stream. More...
 
ulong ReadCompressed ()
 Reads a compressed integer - the opposite of Writer.WriteCompressed. More...
 
long ReadCompressedSigned ()
 Reads a signed compressed number. More...
 
override string ReadString ()
 Reads a string from the stream; it has no length limit. More...
 
string ReadString (int length)
 Reads a string with the given length from the stream. More...
 
string ReadZeroString ()
 Reads a string that is terminated with the null character. No length limit but slower to read. More...
 
string ReadLongString ()
 Reads a long string from the stream. Maximum length of 2GB. More...
 
float ReadRange (bool[] data, int start, int count, float min, float max)
 Reverses Writer.WriteRange. Converts a compressed float stored in a block of bits back into a floating point. More...
 
float ReadRange (int value, int valueMax, float min, float max)
 Reverses Writer.WriteRange. Converts a compressed float back into a floating point. More...
 
float UnmapRotation ()
 Unmaps a single byte rotation. More...
 
long BytesLeft ()
 Gets how many bytes are left in this stream, if it can be known. More...
 
bool More (int manyMore)
 Checks if there are at least the given number of bytes more in this stream. More...
 
bool More ()
 Checks if there are any more bytes in this stream. More...
 
long GetPosition ()
 Gets the current position in the stream this reader is at. More...
 
bool[] ReadBitsFrom (byte byteValue)
 Reads the bits from the given byte as a block of booleans. More...
 
int ReadFromBits (bool[] bits)
 Converts the given block of bits into an integer. More...
 
int ReadFromBits (bool[] bits, int start, int length)
 Converts the given portion of a block of bits into an integer. More...
 
bool[] ReadBits (int bytes)
 Reads the given number of bytes from the stream into a set of bits. More...
 
void Seek (long to)
 
void Seek (int to, SeekOrigin origin)
 Seek the stream to the given location. More...
 

Static Public Member Functions

static int ValueMax (int bitCount)
 Returns the maximum number that x bits can hold. More...
 
static int CompressedSize (ulong l)
 How many bytes the given value would create if written out. More...
 

Public Attributes

long Length
 The length of the stream. More...
 

Static Public Attributes

static Encoding TextEncoding =Encoding.UTF8
 The text encoding in use. More...
 

Properties

virtual int DataIndex [get]
 The current data index. More...
 
bool IsMore [get]
 Checks if there are any more bytes in this stream. More...
 
long Position [get, set]
 

Constructor & Destructor Documentation

BinaryIO.Reader.Reader ( Stream  stream)
inline

Creates a new reader for the given stream.

Parameters
streamA stream to read from.
BinaryIO.Reader.Reader ( byte[]  src)
inline

Creates a new reader for the given block of bytes.

Parameters
srcThe source block of bytes to read from.

Member Function Documentation

long BinaryIO.Reader.BytesLeft ( )
inline

Gets how many bytes are left in this stream, if it can be known.

Returns
The bytes left.
static int BinaryIO.Reader.CompressedSize ( ulong  l)
inlinestatic

How many bytes the given value would create if written out.

long BinaryIO.Reader.GetPosition ( )
inline

Gets the current position in the stream this reader is at.

Returns
The current stream position.
virtual long BinaryIO.Reader.MarkStart ( )
inlinevirtual

The current starting location.

bool BinaryIO.Reader.More ( int  manyMore)
inline

Checks if there are at least the given number of bytes more in this stream.

Returns
True if there is more bytes; false otherwise.
bool BinaryIO.Reader.More ( )
inline

Checks if there are any more bytes in this stream.

Returns
True if there is more bytes; false otherwise.
long BinaryIO.Reader.PackedInt ( )
inline

Reads a packed integer from the stream. Not the opposite of

Returns
The packed integer.
int BinaryIO.Reader.PeekByte ( )
inline

Gets the value of the next byte in the stream.

Returns
The value of the byte; -1 if the reader is past the end of the stream.
bool [] BinaryIO.Reader.ReadBits ( int  bytes)
inline

Reads the given number of bytes from the stream into a set of bits.

Parameters
bytesThe number of bytes to read from the stream.
Returns
The bytes as a block of bits.
bool [] BinaryIO.Reader.ReadBitsFrom ( byte  byteValue)
inline

Reads the bits from the given byte as a block of booleans.

Parameters
byteValueThe byte to read the bits from.
Returns
A block of 8 booleans. Lowest bit is at the highest index.
ulong BinaryIO.Reader.ReadCompressed ( )
inline

Reads a compressed integer - the opposite of Writer.WriteCompressed.

long BinaryIO.Reader.ReadCompressedSigned ( )
inline

Reads a signed compressed number.

int BinaryIO.Reader.ReadFromBits ( bool[]  bits)
inline

Converts the given block of bits into an integer.

Parameters
bitsThe bits to read from. The highest index is the lowest bit.
Returns
The bits converted into an integer.
int BinaryIO.Reader.ReadFromBits ( bool[]  bits,
int  start,
int  length 
)
inline

Converts the given portion of a block of bits into an integer.

Parameters
bitsThe bits to read from. The highest index is the lowest bit.
startThe index of where to start. This is the location of the highest bit of the value.
lengthHow many bits represent this value.
Returns
The bits converted into an integer.
byte [] BinaryIO.Reader.ReadImageBytes ( )
inline

Reads the bytes of a texture from the stream.

float BinaryIO.Reader.ReadInt16F ( float  low,
float  width 
)
inline

Reads a compressed floating point value from the stream. Compressed floats are stored as a ushort. Their value represents a percentage of a range (i.e. it gets divided by the max ushort value 64k), where 64k = 100% (the top of the range, low + width).

Parameters
lowThe bottom of the float range this was compressed into.
widthThis value is high-low; the width of the range.
Returns
The decompressed float.
int BinaryIO.Reader.ReadInt24 ( )
inline

Reads a 3 byte integer from the stream.

Returns
A 3 byte integer.
long BinaryIO.Reader.ReadInt40 ( )
inline
string BinaryIO.Reader.ReadLongString ( )
inline

Reads a long string from the stream. Maximum length of 2GB.

Returns
A string read from the stream.
float BinaryIO.Reader.ReadRange ( bool[]  data,
int  start,
int  count,
float  min,
float  max 
)
inline

Reverses Writer.WriteRange. Converts a compressed float stored in a block of bits back into a floating point.

Parameters
dataThe bits the value is held in.
startThe starting bit index.
countThe number of bits the value is stored in.
minThe minimum value of the range.
maxThe maximum value of the range.
Returns
The uncompressed floating point value.
float BinaryIO.Reader.ReadRange ( int  value,
int  valueMax,
float  min,
float  max 
)
inline

Reverses Writer.WriteRange. Converts a compressed float back into a floating point.

Parameters
valueThe compressed float.
valueMaxThe maximum number that value can be.
minThe minimum value of the range.
maxThe maximum value of the range.
Returns
The uncompressed floating point value.
override string BinaryIO.Reader.ReadString ( )
inline

Reads a string from the stream; it has no length limit.

Returns
The string that was read.
string BinaryIO.Reader.ReadString ( int  length)
inline

Reads a string with the given length from the stream.

Parameters
lengthThe length of the string.
Returns
The string read from the stream.
uint BinaryIO.Reader.ReadUInt24 ( )
inline

Reads a 3 byte unsigned integer from the stream.

Returns
A 3 byte unsigned integer.
ulong BinaryIO.Reader.ReadUInt40 ( )
inline
ulong BinaryIO.Reader.ReadUInt48 ( )
inline
string BinaryIO.Reader.ReadZeroString ( )
inline

Reads a string that is terminated with the null character. No length limit but slower to read.

Returns
The string read from the stream.
void BinaryIO.Reader.Seek ( long  to)
inline
void BinaryIO.Reader.Seek ( int  to,
SeekOrigin  origin 
)
inline

Seek the stream to the given location.

Parameters
toThe location to seek to.
originWhere your location is relative to.
void BinaryIO.Reader.Skip ( int  count)
inline
float BinaryIO.Reader.UnmapRotation ( )
inline

Unmaps a single byte rotation.

Returns
The unmapped rotation in degrees.
static int BinaryIO.Reader.ValueMax ( int  bitCount)
inlinestatic

Returns the maximum number that x bits can hold.

Parameters
bitCountThe number of bits.
Returns
The maximum unsigned value that many bits can hold.

Member Data Documentation

long BinaryIO.Reader.Length

The length of the stream.

Encoding BinaryIO.Reader.TextEncoding =Encoding.UTF8
static

The text encoding in use.

Property Documentation

virtual int BinaryIO.Reader.DataIndex
get

The current data index.

bool BinaryIO.Reader.IsMore
get

Checks if there are any more bytes in this stream.

Returns
True if there is more bytes; false otherwise.
long BinaryIO.Reader.Position
getset