MemoryBinaryReader
Provides a reader to read primitive types from a binary buffer in memory.
Read time 1 minuteLast updated a day ago
Definition
- Type: Class
- Namespace: Unity.Entities.Serialization
- Assembly: UnityEngine.EntitiesModule
- Implements: BinaryReader, IDisposable
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
Constructor | Description |
|---|---|
| MemoryBinaryReader(System.Byte*,System.Int64) | Initializes and returns an instance of MemoryBinaryReader. |
Properties
Property | Description |
|---|---|
| Position | Gets or sets the current read position of the MemoryBinaryReader. |
Methods
Method | Description |
|---|---|
| Dispose | Disposes the MemoryBinaryReader. |
| ReadBytes | Reads the specified number of bytes and advances the current read position by that number of bytes. |
Operators
Operator | Description |
|---|---|
| BurstableMemoryBinaryReader | Converts this MemoryBinaryReader into a BurstableMemoryBinaryReader. |