Struct DataStreamReader | Unity Transport | 0.5.0-preview.5
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(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.

    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

    ReadFixedString(Byte*, Int32)

    Declaration
    public ushort ReadFixedString(byte *data, int maxLength)
    Parameters
    Type Name Description
    Byte* data
    Int32 maxLength
    Returns
    Type Description
    UInt16

    ReadFixedString128()

    Declaration
    public FixedString128 ReadFixedString128()
    Returns
    Type Description
    FixedString128

    ReadFixedString32()

    Declaration
    public FixedString32 ReadFixedString32()
    Returns
    Type Description
    FixedString32

    ReadFixedString4096()

    Declaration
    public FixedString4096 ReadFixedString4096()
    Returns
    Type Description
    FixedString4096

    ReadFixedString512()

    Declaration
    public FixedString512 ReadFixedString512()
    Returns
    Type Description
    FixedString512

    ReadFixedString64()

    Declaration
    public FixedString64 ReadFixedString64()
    Returns
    Type Description
    FixedString64

    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

    ReadPackedFixedString128Delta(FixedString128, NetworkCompressionModel)

    Declaration
    public FixedString128 ReadPackedFixedString128Delta(FixedString128 baseline, NetworkCompressionModel model)
    Parameters
    Type Name Description
    FixedString128 baseline
    NetworkCompressionModel model
    Returns
    Type Description
    FixedString128

    ReadPackedFixedString32Delta(FixedString32, NetworkCompressionModel)

    Declaration
    public FixedString32 ReadPackedFixedString32Delta(FixedString32 baseline, NetworkCompressionModel model)
    Parameters
    Type Name Description
    FixedString32 baseline
    NetworkCompressionModel model
    Returns
    Type Description
    FixedString32

    ReadPackedFixedString4096Delta(FixedString4096, NetworkCompressionModel)

    Declaration
    public FixedString4096 ReadPackedFixedString4096Delta(FixedString4096 baseline, NetworkCompressionModel model)
    Parameters
    Type Name Description
    FixedString4096 baseline
    NetworkCompressionModel model
    Returns
    Type Description
    FixedString4096

    ReadPackedFixedString512Delta(FixedString512, NetworkCompressionModel)

    Declaration
    public FixedString512 ReadPackedFixedString512Delta(FixedString512 baseline, NetworkCompressionModel model)
    Parameters
    Type Name Description
    FixedString512 baseline
    NetworkCompressionModel model
    Returns
    Type Description
    FixedString512

    ReadPackedFixedString64Delta(FixedString64, NetworkCompressionModel)

    Declaration
    public FixedString64 ReadPackedFixedString64Delta(FixedString64 baseline, NetworkCompressionModel model)
    Parameters
    Type Name Description
    FixedString64 baseline
    NetworkCompressionModel model
    Returns
    Type Description
    FixedString64

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

    Declaration
    public ushort ReadPackedFixedStringDelta(byte *data, int maxLength, byte *baseData, ushort baseLength, NetworkCompressionModel model)
    Parameters
    Type Name Description
    Byte* data
    Int32 maxLength
    Byte* baseData
    UInt16 baseLength
    NetworkCompressionModel model
    Returns
    Type Description
    UInt16

    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

    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

    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