{!See https://docs.google.com/document/d/1takg_GmIBBKKTj-GHZCwzxohpQz7Bhekivkk72kYMtE/edit for reference implementation of OneTrust, dataLayer and GTM} {!OneTrust Cookies Consent} {!OneTrust Cookies Consent end} {!dataLayer initialization push} {!dataLayer initialization push end} {!Google Tag Manager} {!Google Tag Manager end} Struct DataStreamReader | Collections | 2.3.0-pre.3
docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct DataStreamReader

    Writes data in an endian format to deserialize data.

    Namespace: Unity.Collections
    Assembly: solution.dll
    Syntax
    [MovedFrom(true, "Unity.Networking.Transport", null, null)]
    public struct DataStreamReader
    Remarks

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

    DataStreamWriter writes this data in the endian format native to the current machine architecture.
    For network byte order use the so named methods.
    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);
    }

    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.

    DataStreamWriter IsLittleEndian

    Constructors

    Name Description
    DataStreamReader(NativeArray<byte>)

    Initializes a new instance of the DataStreamReader struct with a NativeArray<byte>

    Properties

    Name Description
    HasFailedReads

    If there is a read failure this returns true. A read failure might happen if this attempts to read more than there is capacity for.

    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.

    IsLittleEndian

    Show the byte order in which the current computer architecture stores data.

    Length

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

    Methods

    Name Description
    GetBitsRead()

    Gets the number of bits read from the data stream.

    GetBytesRead()

    Gets the number of bytes read from the data stream.

    ReadByte()

    Reads an unsigned byte from the current stream and advances the current position of the stream by one byte.

    ReadBytes(NativeArray<byte>)

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

    ReadDouble()

    Reads a 8-byte floating point value from the current stream and advances the current position of the stream by four bytes.

    ReadFixedString(NativeArray<byte>)

    Read and copy data into the given NativeArray of bytes, an error will be logged if not enough bytes are available in the array.

    ReadFixedString128()

    Reads a FixedString128Bytes value from the current stream and advances the current position of the stream by the length of the string.

    ReadFixedString32()

    Reads a FixedString32Bytes value from the current stream and advances the current position of the stream by the length of the string.

    ReadFixedString4096()

    Reads a FixedString4096Bytes value from the current stream and advances the current position of the stream by the length of the string.

    ReadFixedString512()

    Reads a FixedString512Bytes value from the current stream and advances the current position of the stream by the length of the string.

    ReadFixedString64()

    Reads a FixedString64Bytes value from the current stream and advances the current position of the stream by the length of the string.

    ReadFloat()

    Reads a 4-byte floating point value from the current stream and advances the current position of the stream by four bytes.

    ReadInt()

    Reads a 4-byte signed integer from the current stream and advances the current position of the stream by four bytes.

    ReadIntNetworkByteOrder()

    Reads a 4-byte signed integer from the current stream in Big-endian byte order and advances the current position of the stream by four bytes. If the current endianness is in little-endian order, the byte order will be swapped.

    ReadLong()

    Reads an 8-byte signed long from the stream and advances the current position of the stream by eight bytes.

    ReadPackedDouble(StreamCompressionModel)

    Reads a 8-byte floating point value from the data stream using a StreamCompressionModel.

    ReadPackedDoubleDelta(double, StreamCompressionModel)

    Reads a 8-byte floating point value from the data stream.

    If the first bit is 0, the data did not change and baseline will be returned.

    ReadPackedFixedString128Delta(FixedString128Bytes, StreamCompressionModel)

    Reads a FixedString128Bytes delta value to the data stream using a StreamCompressionModel.

    ReadPackedFixedString32Delta(FixedString32Bytes, StreamCompressionModel)

    Reads a FixedString32Bytes delta value to the data stream using a StreamCompressionModel.

    ReadPackedFixedString4096Delta(FixedString4096Bytes, StreamCompressionModel)

    Reads a FixedString4096Bytes delta value to the data stream using a StreamCompressionModel.

    ReadPackedFixedString512Delta(FixedString512Bytes, StreamCompressionModel)

    Reads a FixedString512Bytes delta value to the data stream using a StreamCompressionModel.

    ReadPackedFixedString64Delta(FixedString64Bytes, StreamCompressionModel)

    Reads a FixedString64Bytes delta value to the data stream using a StreamCompressionModel.

    ReadPackedFixedStringDelta(NativeArray<byte>, NativeArray<byte>, StreamCompressionModel)

    Read and copy data into the given NativeArray of bytes, an error will be logged if not enough bytes are available in the array.

    ReadPackedFloat(StreamCompressionModel)

    Reads a 4-byte floating point value from the data stream using a StreamCompressionModel.

    ReadPackedFloatDelta(float, StreamCompressionModel)

    Reads a 4-byte floating point value from the data stream.

    If the first bit is 0, the data did not change and baseline will be returned.

    ReadPackedInt(StreamCompressionModel)

    Reads a 4-byte signed integer value from the data stream using a StreamCompressionModel.
    Negative values de-interleaves from positive values before returning, for example (0, -1, 1, -2, 2) -> (-2, -1, 0, 1, 2)

    ReadPackedIntDelta(int, StreamCompressionModel)

    Reads a 4-byte signed integer delta value from the data stream using a StreamCompressionModel.

    ReadPackedLong(StreamCompressionModel)

    Reads an 8-byte signed long value from the data stream using a StreamCompressionModel.
    Negative values de-interleaves from positive values before returning, for example (0, -1, 1, -2, 2) -> (-2, -1, 0, 1, 2)

    ReadPackedLongDelta(long, StreamCompressionModel)

    Reads an 8-byte signed long delta value from the data stream using a StreamCompressionModel.

    ReadPackedUInt(StreamCompressionModel)

    Reads a 4-byte unsigned integer from the current stream using a StreamCompressionModel and advances the current position the number of bits depending on the model.

    ReadPackedUIntDelta(uint, StreamCompressionModel)

    Reads a 4-byte unsigned integer delta value from the data stream using a StreamCompressionModel.

    ReadPackedULong(StreamCompressionModel)

    Reads an 8-byte unsigned long value from the data stream using a StreamCompressionModel.

    ReadPackedULongDelta(ulong, StreamCompressionModel)

    Reads an 8-byte unsigned long delta value from the data stream using a StreamCompressionModel.

    ReadRawBits(int)

    Reads a specified number of bits from the data stream.

    ReadShort()

    Reads a 2-byte signed short from the current stream and advances the current position of the stream by two bytes.

    ReadShortNetworkByteOrder()

    Reads a 2-byte signed short from the current stream in Big-endian byte order and advances the current position of the stream by two bytes. If the current endianness is in little-endian order, the byte order will be swapped.

    ReadUInt()

    Reads a 4-byte unsigned integer from the current stream and advances the current position of the stream by four bytes.

    ReadUIntNetworkByteOrder()

    Reads a 4-byte unsigned integer from the current stream in Big-endian byte order and advances the current position of the stream by four bytes. If the current endianness is in little-endian order, the byte order will be swapped.

    ReadULong()

    Reads an 8-byte unsigned long from the stream and advances the current position of the stream by eight bytes.

    ReadUShort()

    Reads a 2-byte unsigned short from the current stream and advances the current position of the stream by two bytes.

    ReadUShortNetworkByteOrder()

    Reads a 2-byte unsigned short from the current stream in Big-endian byte order and advances the current position of the stream by two bytes. If the current endianness is in little-endian order, the byte order will be swapped.

    SeekSet(int)

    Sets the current position of this stream to the given value. An error will be logged if pos is outside the length of the stream.
    In addition this will reset the bit index and the bit buffer.

    Extension Methods

    DataStreamExtensions.GetUnsafeReadOnlyPtr(ref DataStreamReader)
    DataStreamExtensions.ReadBytesUnsafe(ref DataStreamReader, byte*, int)
    DataStreamExtensions.ReadFixedStringUnsafe(ref DataStreamReader, byte*, int)
    DataStreamExtensions.ReadPackedFixedStringDeltaUnsafe(ref DataStreamReader, byte*, int, byte*, ushort, StreamCompressionModel)
    In This Article
    Back to top
    Copyright © 2023 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)