using NativeBuffering;
using System.Diagnostics;

var entity = new Entity(
    collection1: new Foobar[] { new Foobar(1, "foo"), new Foobar(2, "bar") },
    collection2: new double[] { 1.1, 2.2 });
var bytes = new byte[entity.CalculateSize()];
var context = new BufferedObjectWriteContext(bytes);
entity.Write(context);

unsafe
{
    fixed (byte* p = bytes)
    {
        var entityMessage = EntityBufferedMessage.Parse(new NativeBuffer(bytes));
        var foobar = entityMessage.Collection1[0];
        Debug.Assert(foobar.Foo == 1);
        Debug.Assert(foobar.Bar == "foo");

        foobar = entityMessage.Collection1[1];
        Debug.Assert(foobar.Foo == 2);
        Debug.Assert(foobar.Bar == "bar");

        Debug.Assert(entityMessage.Collection2[0] == 1.1);
        Debug.Assert(entityMessage.Collection2[1] == 2.2);
    }
}