menu_bookDocumentation

Binary Serialization: BlobData for Large GameResource Data Storage

calendar_today May 20, 2026 schedule ~1 min read person PatrickJr verified 50

When JSON files grow too large in s&box, you can store data as a binary blob using the BlobData class. This works with GameResource assets and provides custom serialization control.

Creating a Binary Blob

CSHARP
[AssetType( Name = "My CustomResource", Extension = "res", Category = "other" )]
public partial class CustomResource : GameResource
{
    public string Title { get; set; }
    public MyBigData Data = new();
}

public class MyBigData : BlobData
{
    public List<float> Data { get; set; } = [];

    public override void Serialize( ref Writer writer )
    {
        writer.Stream.Write( Data.Count );
        foreach ( var instance in Data )
        {
            writer.Stream.Write( instance );
        }
    }

    public override void Deserialize( ref Reader reader )
    {
        var instanceCount = reader.Stream.Read<int>();
        for ( int i = 0; i < instanceCount; i++ )
        {
            Data.Add( reader.Stream.Read<float>() );
        }
    }
}

Considerations

Binary files are not human-readable. For dynamic lists, write the count first so deserialization knows how many elements to read. Plan your binary layout carefully since changes require migration logic.
Was this helpful?