docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class DataStreamExtensions

    Extension methods for DataStream.

    Inheritance
    object
    DataStreamExtensions
    Namespace: Unity.Collections.LowLevel.Unsafe
    Assembly: Unity.Collections.dll
    Syntax
    public static class DataStreamExtensions

    Methods

    Create(byte*, int)

    Initializes a new instance of the DataStreamWriter struct with externally owned memory

    Declaration
    public static DataStreamWriter Create(byte* data, int length)
    Parameters
    Type Name Description
    byte* data

    Pointer to the data

    int length

    Length of the data

    Returns
    Type Description
    DataStreamWriter

    A new instance of the DataStreamWriter

    GetUnsafeReadOnlyPtr(ref DataStreamReader)

    Get a pointer to the stream's data. Note that the pointer always points at the beginning of the data, no matter how much was read from the stream.

    Declaration
    public static void* GetUnsafeReadOnlyPtr(this ref DataStreamReader reader)
    Parameters
    Type Name Description
    DataStreamReader reader

    Data stream reader.

    Returns
    Type Description
    void*

    A pointer to the stream's data.

    Remarks

    Performs a job safety check for read-only access.

    ReadBytesUnsafe(ref DataStreamReader, byte*, int)

    Read and copy data to the memory location pointed to, an error will be logged if the length will put the reader out of bounds on the current read pointer.

    Declaration
    public static void ReadBytesUnsafe(this ref DataStreamReader reader, byte* data, int length)
    Parameters
    Type Name Description
    DataStreamReader reader

    Data stream reader.

    byte* data

    Pointer to the data.

    int length

    Number of bytes to read.

    ReadFixedStringUnsafe(ref DataStreamReader, byte*, int)

    Reads a 2-byte length value from the current stream, reads the specified number of bytes to the buffer and advances the current position of the stream by the length of the string.

    Declaration
    public static ushort ReadFixedStringUnsafe(this ref DataStreamReader reader, byte* data, int maxLength)
    Parameters
    Type Name Description
    DataStreamReader reader

    Data stream reader.

    byte* data

    Buffer to write the string bytes to.

    int maxLength

    Max number of bytes allowed to be read into the buffer.

    Returns
    Type Description
    ushort

    The number of bytes written to the data buffer.

    ReadPackedFixedStringDeltaUnsafe(ref DataStreamReader, byte*, int, byte*, ushort, StreamCompressionModel)

    Writes a delta FixedString value to the data stream using a StreamCompressionModel.

    If the value cannot be written HasFailedReads will return true.

    Declaration
    public static ushort ReadPackedFixedStringDeltaUnsafe(this ref DataStreamReader reader, byte* data, int maxLength, byte* baseData, ushort baseLength, StreamCompressionModel model)
    Parameters
    Type Name Description
    DataStreamReader reader

    Data stream reader.

    byte* data

    Pointer to a packed fixed string.

    int maxLength

    Max number of bytes allowed to be read into the pointer.

    byte* baseData

    Pointer to the previous value, used to compute the diff.

    ushort baseLength

    The length of the previous value.

    StreamCompressionModel model

    StreamCompressionModel model for writing value in a packed manner.

    Returns
    Type Description
    ushort

    Whether the write was successful

    WriteBytesUnsafe(ref DataStreamWriter, byte*, int)

    Appends a specified number of bytes from the buffer to the data stream.

    Declaration
    public static bool WriteBytesUnsafe(this ref DataStreamWriter writer, byte* data, int bytes)
    Parameters
    Type Name Description
    DataStreamWriter writer

    Data stream writer.

    byte* data

    Pointer to the data.

    int bytes

    A positive number of bytes to write.

    Returns
    Type Description
    bool

    Whether the write was successful

    In This Article
    Back to top
    Copyright © 2024 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)