docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class MemoryBinaryReader

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

    Inheritance
    object
    MemoryBinaryReader
    Implements
    BinaryReader
    Namespace: Unity.Entities.Serialization
    Assembly: Unity.Entities.dll
    Syntax
    public class MemoryBinaryReader : BinaryReader
    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*, long)

    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*, int)

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

    Operators

    Name Description
    explicit operator BurstableMemoryBinaryReader(MemoryBinaryReader)

    Converts this MemoryBinaryReader into a BurstableMemoryBinaryReader.

    Extension Methods

    BlobAssetSerializeExtensions.Read<T>(BinaryReader)
    BinaryReaderExtensions.ReadArray<T>(BinaryReader, NativeArray<T>, int)
    BinaryReaderExtensions.ReadByte(BinaryReader)
    BinaryReaderExtensions.ReadBytes(BinaryReader, NativeArray<byte>, int, int)
    BinaryReaderExtensions.ReadInt(BinaryReader)
    BinaryReaderExtensions.ReadULong(BinaryReader)
    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)