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 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. |