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: MLAPI.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.

Constructors#

DataStreamReader(NativeArray<Byte>)#

Declaration#

public DataStreamReader(NativeArray<byte> array)

Parameters#

TypeNameDescription
Unity.Collections.NativeArray<System.Byte>array

Properties#

HasFailedReads#

Declaration#

public 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 bool IsCreated { get; }

Property Value#

TypeDescription
System.Boolean

Length#

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

Declaration#

public int Length { get; }

Property Value#

TypeDescription
System.Int32

Methods#

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(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.

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
Unity.Collections.NativeArray<System.Byte>array

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 FixedString128 ReadFixedString128()

Returns#

TypeDescription
FixedString128

ReadFixedString32()#

Declaration#

public FixedString32 ReadFixedString32()

Returns#

TypeDescription
FixedString32

ReadFixedString4096()#

Declaration#

public FixedString4096 ReadFixedString4096()

Returns#

TypeDescription
FixedString4096

ReadFixedString512()#

Declaration#

public FixedString512 ReadFixedString512()

Returns#

TypeDescription
FixedString512

ReadFixedString64()#

Declaration#

public FixedString64 ReadFixedString64()

Returns#

TypeDescription
FixedString64

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

ReadPackedFixedString128Delta(FixedString128, NetworkCompressionModel)#

Declaration#

public FixedString128 ReadPackedFixedString128Delta(FixedString128 baseline, NetworkCompressionModel model)

Parameters#

TypeNameDescription
FixedString128baseline
NetworkCompressionModelmodel

Returns#

TypeDescription
FixedString128

ReadPackedFixedString32Delta(FixedString32, NetworkCompressionModel)#

Declaration#

public FixedString32 ReadPackedFixedString32Delta(FixedString32 baseline, NetworkCompressionModel model)

Parameters#

TypeNameDescription
FixedString32baseline
NetworkCompressionModelmodel

Returns#

TypeDescription
FixedString32

ReadPackedFixedString4096Delta(FixedString4096, NetworkCompressionModel)#

Declaration#

public FixedString4096 ReadPackedFixedString4096Delta(FixedString4096 baseline, NetworkCompressionModel model)

Parameters#

TypeNameDescription
FixedString4096baseline
NetworkCompressionModelmodel

Returns#

TypeDescription
FixedString4096

ReadPackedFixedString512Delta(FixedString512, NetworkCompressionModel)#

Declaration#

public FixedString512 ReadPackedFixedString512Delta(FixedString512 baseline, NetworkCompressionModel model)

Parameters#

TypeNameDescription
FixedString512baseline
NetworkCompressionModelmodel

Returns#

TypeDescription
FixedString512

ReadPackedFixedString64Delta(FixedString64, NetworkCompressionModel)#

Declaration#

public FixedString64 ReadPackedFixedString64Delta(FixedString64 baseline, NetworkCompressionModel model)

Parameters#

TypeNameDescription
FixedString64baseline
NetworkCompressionModelmodel

Returns#

TypeDescription
FixedString64

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

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

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