docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class MemoryBinaryWriter

    Provides a writer to write primitive types to a binary buffer in memory.

    Inheritance
    object
    MemoryBinaryWriter
    Implements
    BinaryWriter
    Namespace: Unity.Entities.Serialization
    Assembly: Unity.Entities.dll
    Syntax
    public class MemoryBinaryWriter : BinaryWriter
    Remarks

    This class can be used to serialize, for example, blob assets. The resulting binary buffer is stored in memory.

    Examples
      struct MyData
                 {
                     public float embeddedFloat;
                     public BlobString str;
                 }
                 public void WriteBlobAsset()
                 {
                     unsafe
                     {
                         var writer = new MemoryBinaryWriter();
                         var blobBuilder = new BlobBuilder(Allocator.Temp);
                         ref var root = ref blobBuilder.ConstructRoot<MyData>();
                         builder.AllocateString(ref root.str, "Hello World!");
                         root.embeddedFloat = 4;
                         BlobAssetReference<MyData>.Write(writer, blobBuilder, kVersion);
                     }
                 }
    

    Properties

    Name Description
    Data

    A pointer to the data that has been written to memory.

    Length

    The total length of the all written data.

    Position

    Gets or sets the current write position of the MemoryBinaryWriter.

    Methods

    Name Description
    Dispose()

    Disposes the MemoryBinaryWriter.

    WriteBytes(void*, int)

    Writes the specified number of bytes and advances the current write position by that number of bytes.

    Extension Methods

    BlobAssetSerializeExtensions.Write<T>(BinaryWriter, BlobAssetReference<T>)
    BinaryWriterExtensions.Write(BinaryWriter, byte)
    BinaryWriterExtensions.Write(BinaryWriter, byte[])
    BinaryWriterExtensions.Write(BinaryWriter, int)
    BinaryWriterExtensions.Write(BinaryWriter, ulong)
    BinaryWriterExtensions.WriteArray<T>(BinaryWriter, NativeArray<T>)
    BinaryWriterExtensions.WriteList<T>(BinaryWriter, NativeList<T>)
    BinaryWriterExtensions.WriteList<T>(BinaryWriter, NativeList<T>, int, int)
    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)