Skip to main content

Unity.Networking.Transport.DataStreamReader

The DataStreamReader class is the counterpart of the DataStreamWriter class and can be be used to deserialize data which was prepared with it.

Inherited Members#

ValueType.Equals(Object)

ValueType.GetHashCode()

ValueType.ToString()

Object.Equals(Object, Object)

Object.GetType()

Object.ReferenceEquals(Object, Object)

Namespace: System.Dynamic.ExpandoObject#
Assembly: transport.dll#
Syntax#
public struct DataStreamReader
Remarks#

Simple usage example:

using (var dataWriter = new DataStreamWriter(16, Allocator.Persistent))
{
dataWriter.Write(42);
dataWriter.Write(1234);
// Length is the actual amount of data inside the writer,
// Capacity is the total amount.
var dataReader = new DataStreamReader(dataWriter, 0, dataWriter.Length);
var context = default(DataStreamReader.Context);
var myFirstInt = dataReader.ReadInt(ref context);
var mySecondInt = dataReader.ReadInt(ref context);
}

The DataStreamReader carries the position of the read pointer inside the struct, taking a copy of the reader will also copy the read position. This includes passing the reader to a method by value instead of by ref.

See the DataStreamWriter class for more information and examples.

DataStreamReader(NativeArray\<Byte>)#

Declaration#

public DataStreamReader(NativeArray<byte> array)

Parameters#

TypeNameDescription
NativeArray\<System.Byte>array

DataStreamReader(Byte*, Int32)#

Declaration#

public DataStreamReader(byte *data, int length)

Parameters#

TypeNameDescription
System.Byte*data
System.Int32length

#

HasFailedReads#

Declaration#

public readonly bool HasFailedReads { get; }

Property Value#

TypeDescription
System.Boolean

IsCreated#

True if the reader has been pointed to a valid buffer space. This would be false if the reader was created with no arguments.

Declaration#

public readonly bool IsCreated { get; }

Property Value#

TypeDescription
System.Boolean

IsLittleEndian#

Declaration#

public readonly bool IsLittleEndian { get; }

Property Value#

TypeDescription
System.Boolean

Length#

The total size of the buffer space this reader is working with.

Declaration#

public readonly int Length { get; }

Property Value#

TypeDescription
System.Int32

#

GetBitsRead()#

Declaration#

public int GetBitsRead()

Returns#

TypeDescription
System.Int32

GetBytesRead()#

Declaration#

public int GetBytesRead()

Returns#

TypeDescription
System.Int32

ReadByte()#

Declaration#

public byte ReadByte()

Returns#

TypeDescription
System.Byte

ReadBytes(NativeArray\<Byte>)#

Read and copy data into the given NativeArray of bytes, an exception will be thrown if not enough bytes are available.

Declaration#

public void ReadBytes(NativeArray<byte> array)

Parameters#

TypeNameDescription
NativeArray\<System.Byte>array

ReadBytes(Byte*, Int32)#

Read and copy data to the memory location pointed to, an exception will be thrown if it does not fit.

Declaration#

public void ReadBytes(byte *data, int length)

Parameters#

TypeNameDescription
System.Byte*data
System.Int32length

Exceptions#

TypeCondition
System.ArgumentOutOfRangeExceptionThrown if the length will put the reader out of bounds based on the current read pointer position.

ReadFixedString(Byte*, Int32)#

Declaration#

public ushort ReadFixedString(byte *data, int maxLength)

Parameters#

TypeNameDescription
System.Byte*data
System.Int32maxLength

Returns#

TypeDescription
System.UInt16

ReadFixedString128()#

Declaration#

public FixedString128Bytes ReadFixedString128()

Returns#

TypeDescription
FixedString128Bytes

ReadFixedString32()#

Declaration#

public FixedString32Bytes ReadFixedString32()

Returns#

TypeDescription
FixedString32Bytes

ReadFixedString4096()#

Declaration#

public FixedString4096Bytes ReadFixedString4096()

Returns#

TypeDescription
FixedString4096Bytes

ReadFixedString512()#

Declaration#

public FixedString512Bytes ReadFixedString512()

Returns#

TypeDescription
FixedString512Bytes

ReadFixedString64()#

Declaration#

public FixedString64Bytes ReadFixedString64()

Returns#

TypeDescription
FixedString64Bytes

ReadFloat()#

Declaration#

public float ReadFloat()

Returns#

TypeDescription
System.Single

ReadInt()#

Declaration#

public int ReadInt()

Returns#

TypeDescription
System.Int32

ReadIntNetworkByteOrder()#

Declaration#

public int ReadIntNetworkByteOrder()

Returns#

TypeDescription
System.Int32

ReadLong()#

Declaration#

public long ReadLong()

Returns#

TypeDescription
System.Int64

ReadPackedFixedString128Delta(FixedString128Bytes, NetworkCompressionModel)#

Declaration#

public FixedString128Bytes ReadPackedFixedString128Delta(FixedString128Bytes baseline, NetworkCompressionModel model)

Parameters#

TypeNameDescription
FixedString128Bytesbaseline
NetworkCompressionModelmodel

Returns#

TypeDescription
FixedString128Bytes

ReadPackedFixedString32Delta(FixedString32Bytes, NetworkCompressionModel)#

Declaration#

public FixedString32Bytes ReadPackedFixedString32Delta(FixedString32Bytes baseline, NetworkCompressionModel model)

Parameters#

TypeNameDescription
FixedString32Bytesbaseline
NetworkCompressionModelmodel

Returns#

TypeDescription
FixedString32Bytes

ReadPackedFixedString4096Delta(FixedString4096Bytes, NetworkCompressionModel)#

Declaration#

public FixedString4096Bytes ReadPackedFixedString4096Delta(FixedString4096Bytes baseline, NetworkCompressionModel model)

Parameters#

TypeNameDescription
FixedString4096Bytesbaseline
NetworkCompressionModelmodel

Returns#

TypeDescription
FixedString4096Bytes

ReadPackedFixedString512Delta(FixedString512Bytes, NetworkCompressionModel)#

Declaration#

public FixedString512Bytes ReadPackedFixedString512Delta(FixedString512Bytes baseline, NetworkCompressionModel model)

Parameters#

TypeNameDescription
FixedString512Bytesbaseline
NetworkCompressionModelmodel

Returns#

TypeDescription
FixedString512Bytes

ReadPackedFixedString64Delta(FixedString64Bytes, NetworkCompressionModel)#

Declaration#

public FixedString64Bytes ReadPackedFixedString64Delta(FixedString64Bytes baseline, NetworkCompressionModel model)

Parameters#

TypeNameDescription
FixedString64Bytesbaseline
NetworkCompressionModelmodel

Returns#

TypeDescription
FixedString64Bytes

ReadPackedFixedStringDelta(Byte*, Int32, Byte*, UInt16, NetworkCompressionModel)#

Declaration#

public ushort ReadPackedFixedStringDelta(byte *data, int maxLength, byte *baseData, ushort baseLength, NetworkCompressionModel model)

Parameters#

TypeNameDescription
System.Byte*data
System.Int32maxLength
System.Byte*baseData
System.UInt16baseLength
NetworkCompressionModelmodel

Returns#

TypeDescription
System.UInt16

ReadPackedFloat(NetworkCompressionModel)#

Declaration#

public float ReadPackedFloat(NetworkCompressionModel model)

Parameters#

TypeNameDescription
NetworkCompressionModelmodel

Returns#

TypeDescription
System.Single

ReadPackedFloatDelta(Single, NetworkCompressionModel)#

Declaration#

public float ReadPackedFloatDelta(float baseline, NetworkCompressionModel model)

Parameters#

TypeNameDescription
System.Singlebaseline
NetworkCompressionModelmodel

Returns#

TypeDescription
System.Single

ReadPackedInt(NetworkCompressionModel)#

Declaration#

public int ReadPackedInt(NetworkCompressionModel model)

Parameters#

TypeNameDescription
NetworkCompressionModelmodel

Returns#

TypeDescription
System.Int32

ReadPackedIntDelta(Int32, NetworkCompressionModel)#

Declaration#

public int ReadPackedIntDelta(int baseline, NetworkCompressionModel model)

Parameters#

TypeNameDescription
System.Int32baseline
NetworkCompressionModelmodel

Returns#

TypeDescription
System.Int32

ReadPackedLong(NetworkCompressionModel)#

Declaration#

public long ReadPackedLong(NetworkCompressionModel model)

Parameters#

TypeNameDescription
NetworkCompressionModelmodel

Returns#

TypeDescription
System.Int64

ReadPackedLongDelta(Int64, NetworkCompressionModel)#

Declaration#

public long ReadPackedLongDelta(long baseline, NetworkCompressionModel model)

Parameters#

TypeNameDescription
System.Int64baseline
NetworkCompressionModelmodel

Returns#

TypeDescription
System.Int64

ReadPackedUInt(NetworkCompressionModel)#

Declaration#

public uint ReadPackedUInt(NetworkCompressionModel model)

Parameters#

TypeNameDescription
NetworkCompressionModelmodel

Returns#

TypeDescription
System.UInt32

ReadPackedUIntDelta(UInt32, NetworkCompressionModel)#

Declaration#

public uint ReadPackedUIntDelta(uint baseline, NetworkCompressionModel model)

Parameters#

TypeNameDescription
System.UInt32baseline
NetworkCompressionModelmodel

Returns#

TypeDescription
System.UInt32

ReadPackedULong(NetworkCompressionModel)#

Declaration#

public ulong ReadPackedULong(NetworkCompressionModel model)

Parameters#

TypeNameDescription
NetworkCompressionModelmodel

Returns#

TypeDescription
System.UInt64

ReadPackedULongDelta(UInt64, NetworkCompressionModel)#

Declaration#

public ulong ReadPackedULongDelta(ulong baseline, NetworkCompressionModel model)

Parameters#

TypeNameDescription
System.UInt64baseline
NetworkCompressionModelmodel

Returns#

TypeDescription
System.UInt64

ReadRawBits(Int32)#

Declaration#

public uint ReadRawBits(int numbits)

Parameters#

TypeNameDescription
System.Int32numbits

Returns#

TypeDescription
System.UInt32

ReadShort()#

Declaration#

public short ReadShort()

Returns#

TypeDescription
System.Int16

ReadShortNetworkByteOrder()#

Declaration#

public short ReadShortNetworkByteOrder()

Returns#

TypeDescription
System.Int16

ReadUInt()#

Declaration#

public uint ReadUInt()

Returns#

TypeDescription
System.UInt32

ReadUIntNetworkByteOrder()#

Declaration#

public uint ReadUIntNetworkByteOrder()

Returns#

TypeDescription
System.UInt32

ReadULong()#

Declaration#

public ulong ReadULong()

Returns#

TypeDescription
System.UInt64

ReadUShort()#

Declaration#

public ushort ReadUShort()

Returns#

TypeDescription
System.UInt16

ReadUShortNetworkByteOrder()#

Declaration#

public ushort ReadUShortNetworkByteOrder()

Returns#

TypeDescription
System.UInt16

SeekSet(Int32)#

Declaration#

public void SeekSet(int pos)

Parameters#

TypeNameDescription
System.Int32pos