Struct DataStreamReader | Unity Transport | 0.3.1-preview.4
docs.unity3d.com
    Show / Hide Table of Contents

    Struct DataStreamReader

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

    Namespace: Unity.Networking.Transport
    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
    Type Name Description
    NativeArray<Byte> array

    Properties

    HasFailedReads

    Declaration
    public bool HasFailedReads { get; }
    Property Value
    Type Description
    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
    Type Description
    Boolean

    Length

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

    Declaration
    public int Length { get; }
    Property Value
    Type Description
    Int32

    Methods

    GetBitsRead()

    Declaration
    public int GetBitsRead()
    Returns
    Type Description
    Int32

    GetBytesRead()

    Declaration
    public int GetBytesRead()
    Returns
    Type Description
    Int32

    ReadByte()

    Declaration
    public byte ReadByte()
    Returns
    Type Description
    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
    Type Name Description
    NativeArray<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
    Type Name Description
    Byte* data
    Int32 length
    Exceptions
    Type Condition
    ArgumentOutOfRangeException

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

    ReadFloat()

    Declaration
    public float ReadFloat()
    Returns
    Type Description
    Single

    ReadInt()

    Declaration
    public int ReadInt()
    Returns
    Type Description
    Int32

    ReadIntNetworkByteOrder()

    Declaration
    public int ReadIntNetworkByteOrder()
    Returns
    Type Description
    Int32

    ReadPackedFloat(NetworkCompressionModel)

    Declaration
    public float ReadPackedFloat(NetworkCompressionModel model)
    Parameters
    Type Name Description
    NetworkCompressionModel model
    Returns
    Type Description
    Single

    ReadPackedFloatDelta(Single, NetworkCompressionModel)

    Declaration
    public float ReadPackedFloatDelta(float baseline, NetworkCompressionModel model)
    Parameters
    Type Name Description
    Single baseline
    NetworkCompressionModel model
    Returns
    Type Description
    Single

    ReadPackedInt(NetworkCompressionModel)

    Declaration
    public int ReadPackedInt(NetworkCompressionModel model)
    Parameters
    Type Name Description
    NetworkCompressionModel model
    Returns
    Type Description
    Int32

    ReadPackedIntDelta(Int32, NetworkCompressionModel)

    Declaration
    public int ReadPackedIntDelta(int baseline, NetworkCompressionModel model)
    Parameters
    Type Name Description
    Int32 baseline
    NetworkCompressionModel model
    Returns
    Type Description
    Int32

    ReadPackedStringDelta(NativeString64, NetworkCompressionModel)

    Declaration
    public NativeString64 ReadPackedStringDelta(NativeString64 baseline, NetworkCompressionModel model)
    Parameters
    Type Name Description
    NativeString64 baseline
    NetworkCompressionModel model
    Returns
    Type Description
    NativeString64

    ReadPackedUInt(NetworkCompressionModel)

    Declaration
    public uint ReadPackedUInt(NetworkCompressionModel model)
    Parameters
    Type Name Description
    NetworkCompressionModel model
    Returns
    Type Description
    UInt32

    ReadPackedUIntDelta(UInt32, NetworkCompressionModel)

    Declaration
    public uint ReadPackedUIntDelta(uint baseline, NetworkCompressionModel model)
    Parameters
    Type Name Description
    UInt32 baseline
    NetworkCompressionModel model
    Returns
    Type Description
    UInt32

    ReadShort()

    Declaration
    public short ReadShort()
    Returns
    Type Description
    Int16

    ReadShortNetworkByteOrder()

    Declaration
    public short ReadShortNetworkByteOrder()
    Returns
    Type Description
    Int16

    ReadString()

    Declaration
    public NativeString64 ReadString()
    Returns
    Type Description
    NativeString64

    ReadUInt()

    Declaration
    public uint ReadUInt()
    Returns
    Type Description
    UInt32

    ReadUIntNetworkByteOrder()

    Declaration
    public uint ReadUIntNetworkByteOrder()
    Returns
    Type Description
    UInt32

    ReadULong()

    Declaration
    public ulong ReadULong()
    Returns
    Type Description
    UInt64

    ReadUShort()

    Declaration
    public ushort ReadUShort()
    Returns
    Type Description
    UInt16

    ReadUShortNetworkByteOrder()

    Declaration
    public ushort ReadUShortNetworkByteOrder()
    Returns
    Type Description
    UInt16
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023