Skip to main content

Class NetworkReader

Bit writer, writes values to a buffer on a bit level Use to reduce memory allocation

Inheritance
System.Object
Inherited Members
Show
Syntax
public class NetworkReader : IDisposable

Constructors

NetworkReader()

Declaration
public NetworkReader()

Properties

BitLength

Size of buffer that is being read from

Declaration
public int BitLength { get; }

BitPosition

Current bit position for reading from buffer

Declaration
public int BitPosition { get; }

BytePosition

Current rounded up to nearest multiple of 8

Declaration
public int BytePosition { get; }

Methods

Finalize()

Declaration
protected void Finalize()

Dispose(Boolean)

Declaration
protected virtual void Dispose(bool disposing)
Parameters
TypeNameDescription
System.Booleandisposingtrue if called from IDisposable

Dispose()

Declaration
public void Dispose()

Reset(ArraySegment<Byte>)

Declaration
public void Reset(ArraySegment<byte> segment)
Parameters
TypeNameDescription
System.ArraySegment<System.Byte>segment

Reset(Byte[])

Declaration
public void Reset(byte[] array)
Parameters
TypeNameDescription
System.Byte[]array

Reset(Byte[], Int32, Int32)

Declaration
public void Reset(byte[] array, int position, int length)
Parameters
TypeNameDescription
System.Byte[]array
System.Int32position
System.Int32length

CanRead()

Can read atleast 1 bit

Declaration
public bool CanRead()
Returns
TypeDescription
System.Boolean

CanReadBits(Int32)

Can atleast readCount bits

Declaration
public bool CanReadBits(int readCount)
Parameters
TypeNameDescription
System.Int32readCount
Returns
TypeDescription
System.Boolean

CanReadBytes(Int32)

Can atleast readCount bytes

Declaration
public bool CanReadBytes(int readCount)
Parameters
TypeNameDescription
System.Int32readCount
Returns
TypeDescription
System.Boolean

PadToByte()

Declaration
public void PadToByte()

ReadBoolean()

Declaration
public bool ReadBoolean()
Returns
TypeDescription
System.Boolean

ReadBooleanAsUlong()

Writes first bit of value to buffer

Declaration
public ulong ReadBooleanAsUlong()
Returns
TypeDescription
System.UInt64

ReadSByte()

Declaration
public sbyte ReadSByte()
Returns
TypeDescription
System.SByte

ReadByte()

Declaration
public byte ReadByte()
Returns
TypeDescription
System.Byte

ReadInt16()

Declaration
public short ReadInt16()
Returns
TypeDescription
System.Int16

ReadUInt16()

Declaration
public ushort ReadUInt16()
Returns
TypeDescription
System.UInt16

ReadInt32()

Declaration
public int ReadInt32()
Returns
TypeDescription
System.Int32

ReadUInt32()

Declaration
public uint ReadUInt32()
Returns
TypeDescription
System.UInt32

ReadInt64()

Declaration
public long ReadInt64()
Returns
TypeDescription
System.Int64

ReadUInt64()

Declaration
public ulong ReadUInt64()
Returns
TypeDescription
System.UInt64

ReadSingle()

Declaration
public float ReadSingle()
Returns
TypeDescription
System.Single

ReadDouble()

Declaration
public double ReadDouble()
Returns
TypeDescription
System.Double

Read(Int32)

Declaration
public ulong Read(int bits)
Parameters
TypeNameDescription
System.Int32bits
Returns
TypeDescription
System.UInt64

ReadAtPosition(Int32, Int32)

Reads n bits from buffer at bitPosition

Declaration
public ulong ReadAtPosition(int bits, int bitPosition)
Parameters
TypeNameDescription
System.Int32bitsnumber of bits in value to write
System.Int32bitPositionwhere to write bits
Returns
TypeDescription
System.UInt64

Skip(Int32)

Declaration
public void Skip(int bits)
Parameters
TypeNameDescription
System.Int32bits

MoveBitPosition(Int32)

Moves the internal bit position For most usecases it is safer to use WARNING: When reading from earlier position make sure to move position back to end of buffer after reading

Declaration
public void MoveBitPosition(int newPosition)
Parameters
TypeNameDescription
System.Int32newPosition

PadAndCopy<T>(out T)

Moves position to nearest byte then copies struct from that position

Declaration
public void PadAndCopy<T>(out T value)
where T : struct
Parameters
TypeNameDescription
Tvalue

ReadBytes(Byte[], Int32, Int32)

Moves position to nearest byte then copies bytes from that position

Declaration
public void ReadBytes(byte[] array, int offset, int length)
Parameters
TypeNameDescription
System.Byte[]array
System.Int32offset
System.Int32length

ReadBytesSegment(Int32)

Declaration
public ArraySegment<byte> ReadBytesSegment(int count)
Parameters
TypeNameDescription
System.Int32count
Returns
TypeDescription
System.ArraySegment<System.Byte>