Detailed Description

This class is a wrapper for writing to a block of bytes.

Inheritance diagram for BinaryIO.Writer:

Public Member Functions

 Writer ()
 Creates a new writer. This can be as long as you want it to be. More...
 
 Writer (Stream stream)
 Creates a new writer to the given stream. More...
 
 Writer (int size)
 Creates a fixed length writer. It can't write more data than the given number of bytes. More...
 
long Position ()
 Gets the current position the writer is at in the stream. More...
 
void Seek (long point)
 Seeks to the given position in the stream relative to the start. More...
 
void Seek (long to, SeekOrigin about)
 Seeks to the given position in the stream. More...
 
void WriteByte (byte b)
 Writes the given byte to the stream. More...
 
string Debug ()
 Debugs this writer. Returns bytes as text. More...
 
void WriteCompressed (ulong l)
 Writes a number compressed into the stream, taking a minimum of a single byte. More...
 
void WriteCompressedSigned (long value)
 Writes an unsigned number compressed into the stream, taking a minimum of a single byte. More...
 
void WriteInt24 (int number)
 
void WriteInt40 (long number)
 
void WriteInt48 (long number)
 
void WriteInt56 (long number)
 
void WriteUInt24 (uint number)
 
void WriteUInt40 (ulong number)
 
void WriteUInt48 (ulong number)
 
void WriteUInt56 (ulong number)
 
override void Write (string str)
 
void WriteString (string str)
 Writes a string to the stream of any length. More...
 
void WriteLongString (string str)
 Writes a long string to the stream. Maximum length of 4GB. More...
 
virtual byte[] GetResult ()
 Gets the content written to the stream as a block of bytes. More...
 
void WriteMessage (Writer writer)
 
void Write (Writer writer)
 
void WriteRange (bool[] data, float value, int start, int count, float min, float max)
 Writes the given floating point value to the given portion of a block of bits. The floating point value is mapped into a range first - between min and max. Note that this does not write the bits to the stream. More...
 
int WriteRange (float value, int count, float min, float max)
 Maps the given floating point value into a range - between min and max. More...
 
void WriteToBits (bool[] bits, int input, int start, int length)
 Writes the given input number to the given portion of a block of bits. More...
 
void WriteBits (bool[] bits)
 Writes the given block of bits to the stream. Must be a multiple of 8. More...
 
void WriteRoundBits (bool[] bits)
 Writes the given block of bits to the stream. It can be any length. More...
 
int ReadFromBits (bool[] bits, int start, int length)
 Converts the given portion of a block of bits into an integer. More...
 
void SeekToEnd ()
 Seeks to the end of the stream. More...
 
int WriteNetHeader (byte type)
 Writes a network header to this writer, returning it's size. More...
 
long StartPackageUInt16 ()
 Starts off a section that has a number representing its size in bytes before it. This size has a maximum of 64kb as it's stored as a ushort. More...
 
void EndPackageUInt16 (long location)
 Ends a section that has a number representing the sections size in bytes before it. More...
 
long StartPackageInt32 ()
 Starts off a section that has a number representing its size in bytes before it. This size has a maximum of 2GB as it's stored as an int. More...
 
void EndPackageInt32 (long location)
 Ends a section that has a number representing the sections size in bytes before it. More...
 
void EndBlock (long location)
 Ends a block noted with the given value from StartBlock. When you call this, you must then write your length value and then call EndBlockLength. More...
 
void EndBlockLength ()
 Call when your done writing the length of a block. See StartBlock. More...
 
long StartBlock (int byteCount)
 Starts a block. That's a section in the stream of unknown length which must have the length written at the start of it. More...
 
long Length ()
 Gets the current length of the stream. More...
 
void MapRotation (float rotation)
 Maps a rotation into a single byte then writes it to the stream. More...
 

Static Public Member Functions

static int CompressedSize (ulong l)
 How many bytes the given value would create if written out. More...
 

Static Public Attributes

static byte[] EmptyInt16 =new byte[2]
 A block of bytes that represents 0 as a short. More...
 
static byte[] EmptyInt32 =new byte[4]
 A block of bytes that represents 0 as an int. More...
 

Package Attributes

const byte NetVerify =69
 The verification byte. ASCII 'E'. Also in NetworkClient.Message More...
 

Constructor & Destructor Documentation

BinaryIO.Writer.Writer ( )
inline

Creates a new writer. This can be as long as you want it to be.

BinaryIO.Writer.Writer ( Stream  stream)
inline

Creates a new writer to the given stream.

Parameters
streamThe stream to write to.
BinaryIO.Writer.Writer ( int  size)
inline

Creates a fixed length writer. It can't write more data than the given number of bytes.

Parameters
sizeThe maximum size of the writer in bytes.

Member Function Documentation

static int BinaryIO.Writer.CompressedSize ( ulong  l)
inlinestatic

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

string BinaryIO.Writer.Debug ( )
inline

Debugs this writer. Returns bytes as text.

void BinaryIO.Writer.EndBlock ( long  location)
inline

Ends a block noted with the given value from StartBlock. When you call this, you must then write your length value and then call EndBlockLength.

Parameters
locationThe value from StartBlock which defines where the block is.
void BinaryIO.Writer.EndBlockLength ( )
inline

Call when your done writing the length of a block. See StartBlock.

void BinaryIO.Writer.EndPackageInt32 ( long  location)
inline

Ends a section that has a number representing the sections size in bytes before it.

Parameters
locationThe value you received from StartPackageInt32.
void BinaryIO.Writer.EndPackageUInt16 ( long  location)
inline

Ends a section that has a number representing the sections size in bytes before it.

Parameters
locationThe value you received from StartPackageUInt16.
virtual byte [] BinaryIO.Writer.GetResult ( )
inlinevirtual

Gets the content written to the stream as a block of bytes.

Returns
The block of bytes.
long BinaryIO.Writer.Length ( )
inline

Gets the current length of the stream.

Returns
The length ot the stream.
void BinaryIO.Writer.MapRotation ( float  rotation)
inline

Maps a rotation into a single byte then writes it to the stream.

Parameters
rotationThe rotation to write (in degrees).
long BinaryIO.Writer.Position ( )
inline

Gets the current position the writer is at in the stream.

Returns
The position in the stream.
int BinaryIO.Writer.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.
void BinaryIO.Writer.Seek ( long  point)
inline

Seeks to the given position in the stream relative to the start.

Parameters
pointThe location to seek to.
void BinaryIO.Writer.Seek ( long  to,
SeekOrigin  about 
)
inline

Seeks to the given position in the stream.

Parameters
toThe location to seek to.
aboutThe position that the given location is relative to.
void BinaryIO.Writer.SeekToEnd ( )
inline

Seeks to the end of the stream.

long BinaryIO.Writer.StartBlock ( int  byteCount)
inline

Starts a block. That's a section in the stream of unknown length which must have the length written at the start of it.

Parameters
byteCountThe number of bytes to leave for the length.
Returns
A value you must pass to EndBlock.
long BinaryIO.Writer.StartPackageInt32 ( )
inline

Starts off a section that has a number representing its size in bytes before it. This size has a maximum of 2GB as it's stored as an int.

Returns
A number you should pass to EndPackageInt32 when your done.
long BinaryIO.Writer.StartPackageUInt16 ( )
inline

Starts off a section that has a number representing its size in bytes before it. This size has a maximum of 64kb as it's stored as a ushort.

Returns
A number you should pass to EndPackageUInt16 when your done.
override void BinaryIO.Writer.Write ( string  str)
inline
void BinaryIO.Writer.Write ( Writer  writer)
inline
void BinaryIO.Writer.WriteBits ( bool[]  bits)
inline

Writes the given block of bits to the stream. Must be a multiple of 8.

Parameters
bitsThe bits to write. 8 bits are grouped together and written as a byte.
void BinaryIO.Writer.WriteByte ( byte  b)
inline

Writes the given byte to the stream.

Parameters
bThe byte to write.
void BinaryIO.Writer.WriteCompressed ( ulong  l)
inline

Writes a number compressed into the stream, taking a minimum of a single byte.

Parameters
lThe number to write.
void BinaryIO.Writer.WriteCompressedSigned ( long  value)
inline

Writes an unsigned number compressed into the stream, taking a minimum of a single byte.

Parameters
valueThe number to write.
void BinaryIO.Writer.WriteInt24 ( int  number)
inline
void BinaryIO.Writer.WriteInt40 ( long  number)
inline
void BinaryIO.Writer.WriteInt48 ( long  number)
inline
void BinaryIO.Writer.WriteInt56 ( long  number)
inline
void BinaryIO.Writer.WriteLongString ( string  str)
inline

Writes a long string to the stream. Maximum length of 4GB.

Parameters
strThe string to write.
void BinaryIO.Writer.WriteMessage ( Writer  writer)
inline
int BinaryIO.Writer.WriteNetHeader ( byte  type)
inline

Writes a network header to this writer, returning it's size.

Parameters
typeThe message type.
headerThe header block.
verifyTrue if a verification 'E' should be added.
Returns
The size of the header.
void BinaryIO.Writer.WriteRange ( bool[]  data,
float  value,
int  start,
int  count,
float  min,
float  max 
)
inline

Writes the given floating point value to the given portion of a block of bits. The floating point value is mapped into a range first - between min and max. Note that this does not write the bits to the stream.

Parameters
dataThe bits that the value will be written to.
valueThe floating point value that will be written.
startThe starting index in the bit array for this value.
countThe number of bits this value can take up. More results in higher accuracy.
minThe minimum value of the range.
maxThe maximum value of the range.
int BinaryIO.Writer.WriteRange ( float  value,
int  count,
float  min,
float  max 
)
inline

Maps the given floating point value into a range - between min and max.

Parameters
valueThe floating point value that will be mapped.
countThe number of bits the mapped value can use. More results in higher accuracy.
minThe minimum value of the range.
maxThe maximum value of the range.
Returns
The mapped float value.
void BinaryIO.Writer.WriteRoundBits ( bool[]  bits)
inline

Writes the given block of bits to the stream. It can be any length.

Parameters
bitsThe bits to write. 8 bits are grouped together and written as a byte.
void BinaryIO.Writer.WriteString ( string  str)
inline

Writes a string to the stream of any length.

Parameters
strThe string to write.
void BinaryIO.Writer.WriteToBits ( bool[]  bits,
int  input,
int  start,
int  length 
)
inline

Writes the given input number to the given portion of a block of bits.

Parameters
bitsThe bits to write the number to.
inputThe number to write to the bits.
startThe start location in the bit array to write the number to.
lengthThe number of bits to use to write the number to.
void BinaryIO.Writer.WriteUInt24 ( uint  number)
inline
void BinaryIO.Writer.WriteUInt40 ( ulong  number)
inline
void BinaryIO.Writer.WriteUInt48 ( ulong  number)
inline
void BinaryIO.Writer.WriteUInt56 ( ulong  number)
inline

Member Data Documentation

byte [] BinaryIO.Writer.EmptyInt16 =new byte[2]
static

A block of bytes that represents 0 as a short.

byte [] BinaryIO.Writer.EmptyInt32 =new byte[4]
static

A block of bytes that represents 0 as an int.

const byte BinaryIO.Writer.NetVerify =69
package

The verification byte. ASCII 'E'. Also in NetworkClient.Message