# MemoryBinaryReader

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

## Definition

* **Type:** Class
* **Namespace:** [Unity.Entities.Serialization](/engine/7000.0/script-reference/unity/entities/serialization.md)
* **Assembly:** UnityEngine.EntitiesModule
* **Implements:** [BinaryReader](/engine/7000.0/script-reference/unity/entities/serialization/binaryreader.md), [IDisposable](https://learn.microsoft.com/dotnet/api/system.idisposable)

```csharp
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](/engine/7000.0/script-reference/unity/entities/serialization/burstablememorybinaryreader.md) in order to be used in a burst compiled context.

## Examples

```csharp
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)](/engine/7000.0/script-reference/unity/entities/serialization/memorybinaryreader/ctor.md) | Initializes and returns an instance of MemoryBinaryReader. |

## Properties

| Property                                                                                                | Description                                                       |
| ------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
| [Position](/engine/7000.0/script-reference/unity/entities/serialization/memorybinaryreader/position.md) | Gets or sets the current read position of the MemoryBinaryReader. |

## Methods

| Method                                                                                                    | Description                                                                                         |
| --------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| [Dispose](/engine/7000.0/script-reference/unity/entities/serialization/memorybinaryreader/dispose.md)     | Disposes the MemoryBinaryReader.                                                                    |
| [ReadBytes](/engine/7000.0/script-reference/unity/entities/serialization/memorybinaryreader/readbytes.md) | Reads the specified number of bytes and advances the current read position by that number of bytes. |

## Operators

| Operator                                                                                                                      | Description                                                          |
| ----------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
| [BurstableMemoryBinaryReader](/engine/7000.0/script-reference/unity/entities/serialization/memorybinaryreader/op-explicit.md) | Converts this MemoryBinaryReader into a BurstableMemoryBinaryReader. |
