Class MemoryBinaryReader
Provides a reader to read primitive types from a binary buffer in memory.
Implements
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
Burstable
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 |
---|---|
Memory |
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. |
Read |
Reads the specified number of bytes and advances the current read position by that number of bytes. |
Operators
Name | Description |
---|---|
explicit operator Burstable |
Converts this MemoryBinaryReader into a BurstableMemoryBinaryReader. |