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
Type | Name | Description |
---|---|---|
System.Boolean | disposing | true if called from IDisposable |
Dispose()
Declaration
public void Dispose()
Reset(ArraySegment<Byte>)
Declaration
public void Reset(ArraySegment<byte> segment)
Parameters
Type | Name | Description |
---|---|---|
System.ArraySegment<System.Byte> | segment |
Reset(Byte[])
Declaration
public void Reset(byte[] array)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | array |
Reset(Byte[], Int32, Int32)
Declaration
public void Reset(byte[] array, int position, int length)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | array | |
System.Int32 | position | |
System.Int32 | length |
CanRead()
Can read atleast 1 bit
Declaration
public bool CanRead()
Returns
Type | Description |
---|---|
System.Boolean |
CanReadBits(Int32)
Can atleast readCount bits
Declaration
public bool CanReadBits(int readCount)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | readCount |
Returns
Type | Description |
---|---|
System.Boolean |
CanReadBytes(Int32)
Can atleast readCount bytes
Declaration
public bool CanReadBytes(int readCount)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | readCount |
Returns
Type | Description |
---|---|
System.Boolean |
PadToByte()
Declaration
public void PadToByte()
ReadBoolean()
Declaration
public bool ReadBoolean()
Returns
Type | Description |
---|---|
System.Boolean |
ReadBooleanAsUlong()
Writes first bit of value to buffer
Declaration
public ulong ReadBooleanAsUlong()
Returns
Type | Description |
---|---|
System.UInt64 |
ReadSByte()
Declaration
public sbyte ReadSByte()
Returns
Type | Description |
---|---|
System.SByte |
ReadByte()
Declaration
public byte ReadByte()
Returns
Type | Description |
---|---|
System.Byte |
ReadInt16()
Declaration
public short ReadInt16()
Returns
Type | Description |
---|---|
System.Int16 |
ReadUInt16()
Declaration
public ushort ReadUInt16()
Returns
Type | Description |
---|---|
System.UInt16 |
ReadInt32()
Declaration
public int ReadInt32()
Returns
Type | Description |
---|---|
System.Int32 |
ReadUInt32()
Declaration
public uint ReadUInt32()
Returns
Type | Description |
---|---|
System.UInt32 |
ReadInt64()
Declaration
public long ReadInt64()
Returns
Type | Description |
---|---|
System.Int64 |
ReadUInt64()
Declaration
public ulong ReadUInt64()
Returns
Type | Description |
---|---|
System.UInt64 |
ReadSingle()
Declaration
public float ReadSingle()
Returns
Type | Description |
---|---|
System.Single |
ReadDouble()
Declaration
public double ReadDouble()
Returns
Type | Description |
---|---|
System.Double |
Read(Int32)
Declaration
public ulong Read(int bits)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | bits |
Returns
Type | Description |
---|---|
System.UInt64 |
ReadAtPosition(Int32, Int32)
Reads n bits from buffer at bitPosition
Declaration
public ulong ReadAtPosition(int bits, int bitPosition)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | bits | number of bits in value to write |
System.Int32 | bitPosition | where to write bits |
Returns
Type | Description |
---|---|
System.UInt64 |
Skip(Int32)
Declaration
public void Skip(int bits)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | bits |
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
Type | Name | Description |
---|---|---|
System.Int32 | newPosition |
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
Type | Name | Description |
---|---|---|
T | value |
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
Type | Name | Description |
---|---|---|
System.Byte[] | array | |
System.Int32 | offset | |
System.Int32 | length |
ReadBytesSegment(Int32)
Declaration
public ArraySegment<byte> ReadBytesSegment(int count)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | count |
Returns
Type | Description |
---|---|
System.ArraySegment<System.Byte> |