docs.unity.cn
    Show / Hide Table of Contents

    Class MemoryBinaryReader

    Provides a reader to read primitive types from a binary buffer in memory.

    Inheritance
    Object
    MemoryBinaryReader
    Namespace: Unity.Entities.Serialization
    Syntax
    public class MemoryBinaryReader : BinaryReader, IDisposable
    Remarks

    This class can be used to deserialize, for example, blob assets.

    By default, the MemoryBinaryReader can't be Burst-compiled. It can be cast into BurstableMemoryBinaryReader in order to be used in a burst compiled context.

    Examples
         struct MyData
         {
             public float embeddedFloat;
             public BlobString str;
         }
         public void ReadBlobAsset(void* buffer, int length, int version)
         {
             unsafe
             {
                 var reader = new MemoryBinaryReader(writer.Data, writer.Length);
                 var result = BlobAssetReference<MyData>.TryRead(reader, version, out var blobResult);
                 ref MyData value = ref blobResult.Value;
                 Debug.Log($"blob float = {value.embeddedFloat}");
                 blobResult.Dispose();
             }
         }

    Constructors

    Name Description
    MemoryBinaryReader(Byte*, Int64)

    Initializes and returns an instance of MemoryBinaryReader.

    Properties

    Name Description
    Position

    Gets or sets the current read position of the MemoryBinaryReader.

    Methods

    Name Description
    Dispose()

    Disposes the MemoryBinaryReader.

    ReadBytes(Void*, Int32)

    Reads the specified number of bytes and advances the current read position by that number of bytes.

    Operators

    Name Description
    Explicit(MemoryBinaryReader to BurstableMemoryBinaryReader)

    Converts this MemoryBinaryReader into a BurstableMemoryBinaryReader.

    Extension Methods

    BlobAssetSerializeExtensions.Read<T>(BinaryReader)
    BinaryReaderExtensions.ReadByte(BinaryReader)
    BinaryReaderExtensions.ReadInt(BinaryReader)
    BinaryReaderExtensions.ReadULong(BinaryReader)
    BinaryReaderExtensions.ReadBytes(BinaryReader, NativeArray<Byte>, Int32, Int32)
    BinaryReaderExtensions.ReadArray<T>(BinaryReader, NativeArray<T>, Int32)
    Back to top Copyright © 2023 Unity Technologies — Terms of use
    Generated by DocFX
    on Wednesday, June 21, 2023