public void CanCreateNewFlatBufferFromScratch() { // Second, let's create a FlatBuffer from scratch in C#, and test it also. // We use an initial size of 1 to exercise the reallocation algorithm, // normally a size larger than the typical FlatBuffer you generate would be // better for performance. var fbb = new FlatBufferBuilder(1); // We set up the same values as monsterdata.json: var str = fbb.CreateString("MyMonster"); var test1 = fbb.CreateString("test1"); var test2 = fbb.CreateString("test2"); Monster.StartInventoryVector(fbb, 5); for (int i = 4; i >= 0; i--) { fbb.AddByte((byte)i); } var inv = fbb.EndVector(); var fred = fbb.CreateString("Fred"); Monster.StartMonster(fbb); Monster.AddName(fbb, fred); var mon2 = Monster.EndMonster(fbb); Monster.StartTest4Vector(fbb, 2); MyGame.Example.Test.CreateTest(fbb, (short)10, (sbyte)20); MyGame.Example.Test.CreateTest(fbb, (short)30, (sbyte)40); var test4 = fbb.EndVector(); Monster.StartTestarrayofstringVector(fbb, 2); fbb.AddOffset(test2); fbb.AddOffset(test1); var testArrayOfString = fbb.EndVector(); Monster.StartMonster(fbb); Monster.AddPos(fbb, Vec3.CreateVec3(fbb, 1.0f, 2.0f, 3.0f, 3.0, Color.Green, (short)5, (sbyte)6)); Monster.AddHp(fbb, (short)80); Monster.AddName(fbb, str); Monster.AddInventory(fbb, inv); Monster.AddTestType(fbb, (byte)1); Monster.AddTest(fbb, mon2); Monster.AddTest4(fbb, test4); Monster.AddTestarrayofstring(fbb, testArrayOfString); var mon = Monster.EndMonster(fbb); fbb.Finish(mon); // Dump to output directory so we can inspect later, if needed using (var ms = new MemoryStream(fbb.DataBuffer().Data, fbb.DataBuffer().position(), fbb.Offset())) { var data = ms.ToArray(); File.WriteAllBytes(@"Resources/monsterdata_cstest.mon",data); } // Now assert the buffer TestBuffer(fbb.DataBuffer()); }
public void TestNumbers64() { var builder = new FlatBufferBuilder(1); builder.AddUlong(0x1122334455667788); Assert.ArrayEqual(new byte[] { 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11 }, builder.DataBuffer.Data); builder = new FlatBufferBuilder(1); builder.AddLong(0x1122334455667788); Assert.ArrayEqual(new byte[] { 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11 }, builder.DataBuffer.Data); }
public void TestVector_1xUInt8() { var builder = new FlatBufferBuilder(1); builder.StartVector(sizeof(byte), 1, 1); Assert.ArrayEqual(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }, builder.DataBuffer.Data); builder.AddByte(1); Assert.ArrayEqual(new byte[] { 0, 0, 0, 0, 1, 0, 0, 0 }, builder.DataBuffer.Data); builder.EndVector(); Assert.ArrayEqual(new byte[] { 1, 0, 0, 0, 1, 0, 0, 0 }, builder.DataBuffer.Data); }
public void TestNumbers() { var builder = new FlatBufferBuilder(1); Assert.ArrayEqual(new byte[] { 0 }, builder.DataBuffer.Data); builder.AddBool(true); Assert.ArrayEqual(new byte[] { 1 }, builder.DataBuffer.Data); builder.AddSbyte(-127); Assert.ArrayEqual(new byte[] { 129, 1 }, builder.DataBuffer.Data); builder.AddByte(255); Assert.ArrayEqual(new byte[] { 0, 255, 129, 1 }, builder.DataBuffer.Data); // First pad builder.AddShort(-32222); Assert.ArrayEqual(new byte[] { 0, 0, 0x22, 0x82, 0, 255, 129, 1 }, builder.DataBuffer.Data); // Second pad builder.AddUshort(0xFEEE); Assert.ArrayEqual(new byte[] { 0xEE, 0xFE, 0x22, 0x82, 0, 255, 129, 1 }, builder.DataBuffer.Data); // no pad builder.AddInt(-53687092); Assert.ArrayEqual(new byte[] { 0, 0, 0, 0, 204, 204, 204, 252, 0xEE, 0xFE, 0x22, 0x82, 0, 255, 129, 1 }, builder.DataBuffer.Data); // third pad builder.AddUint(0x98765432); Assert.ArrayEqual(new byte[] { 0x32, 0x54, 0x76, 0x98, 204, 204, 204, 252, 0xEE, 0xFE, 0x22, 0x82, 0, 255, 129, 1 }, builder.DataBuffer.Data); // no pad }
public void TestBunchOfBools() { var builder = new FlatBufferBuilder(1); builder.StartObject(8); for (var i = 0; i < 8; i++) { builder.AddBool(i, true, false); } var off = builder.EndObject(); builder.Finish(off); Assert.ArrayEqual(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // padding to 64 bytes 24, 0, 0, 0, // root of table, pointing to vtable offset (obj0) 20, 0, // vtable bytes 12, 0, // object length 11, 0, // start of value 0 10, 0, // start of value 1 9, 0, // start of value 2 8, 0, // start of value 3 7, 0, // start of value 4 6, 0, // start of value 5 5, 0, // start of value 6 4, 0, // start of value 7 20, 0, 0, 0, // int32 offset for start of vtable 1, 1, 1, 1, // values 1, 1, 1, 1, }, builder.DataBuffer.Data); }
public void TestCreateArbitarytring() { var builder = new FlatBufferBuilder(1); builder.CreateString("\x01\x02\x03"); Assert.ArrayEqual(new byte[] { 3, 0, 0, 0, 0x01, 0x02, 0x03, 0 }, builder.DataBuffer.Data); // No padding builder.CreateString("\x04\x05\x06\x07"); Assert.ArrayEqual(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Padding to 32 bytes 4, 0, 0, 0, 0x04, 0x05, 0x06, 0x07, 0, 0, 0, 0, // zero terminator with 3 byte pad 3, 0, 0, 0, 0x01, 0x02, 0x03, 0 }, builder.DataBuffer.Data); // No padding }
public void TestCreateAsciiString() { var builder = new FlatBufferBuilder(1); builder.CreateString("foo"); Assert.ArrayEqual(new byte[] { 3, 0, 0, 0, (byte)'f', (byte)'o', (byte)'o', 0 }, builder.DataBuffer.Data); builder.CreateString("moop"); Assert.ArrayEqual(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Padding to 32 bytes 4, 0, 0, 0, (byte)'m', (byte)'o', (byte)'o', (byte)'p', 0, 0, 0, 0, // zero terminator with 3 byte pad 3, 0, 0, 0, (byte)'f', (byte)'o', (byte)'o', 0 }, builder.DataBuffer.Data); }
public static Offset <ReqLogin> EndReqLogin(FlatBufferBuilder builder) { int o = builder.EndObject(); return(new Offset <ReqLogin>(o)); }
public static void AddPosition(FlatBufferBuilder builder, Offset <Vec3> positionOffset) { builder.AddOffset(0, positionOffset.Value, 0); }
public static void AddData(FlatBufferBuilder builder, VectorOffset dataOffset) { builder.AddOffset(0, dataOffset.Value, 0); }
public void CanCreateNewFlatBufferFromScratch() { // Second, let's create a FlatBuffer from scratch in C#, and test it also. // We use an initial size of 1 to exercise the reallocation algorithm, // normally a size larger than the typical FlatBuffer you generate would be // better for performance. var fbb = new FlatBufferBuilder(1); // We set up the same values as monsterdata.json: var str = fbb.CreateString("MyMonster"); var test1 = fbb.CreateString("test1"); var test2 = fbb.CreateString("test2"); Monster.StartInventoryVector(fbb, 5); for (int i = 4; i >= 0; i--) { fbb.AddByte((byte)i); } var inv = fbb.EndVector(); var fred = fbb.CreateString("Fred"); Monster.StartMonster(fbb); Monster.AddName(fbb, fred); var mon2 = Monster.EndMonster(fbb); Monster.StartTest4Vector(fbb, 2); MyGame.Example.Test.CreateTest(fbb, (short)10, (sbyte)20); MyGame.Example.Test.CreateTest(fbb, (short)30, (sbyte)40); var test4 = fbb.EndVector(); Monster.StartTestarrayofstringVector(fbb, 2); fbb.AddOffset(test2.Value); fbb.AddOffset(test1.Value); var testArrayOfString = fbb.EndVector(); Monster.StartMonster(fbb); Monster.AddPos(fbb, Vec3.CreateVec3(fbb, 1.0f, 2.0f, 3.0f, 3.0, Color.Green, (short)5, (sbyte)6)); Monster.AddHp(fbb, (short)80); Monster.AddName(fbb, str); Monster.AddInventory(fbb, inv); Monster.AddTestType(fbb, Any.Monster); Monster.AddTest(fbb, mon2.Value); Monster.AddTest4(fbb, test4); Monster.AddTestarrayofstring(fbb, testArrayOfString); Monster.AddTestbool(fbb, false); var mon = Monster.EndMonster(fbb); Monster.FinishMonsterBuffer(fbb, mon); // Dump to output directory so we can inspect later, if needed using (var ms = new MemoryStream(fbb.DataBuffer.Data, fbb.DataBuffer.Position, fbb.Offset)) { var data = ms.ToArray(); File.WriteAllBytes(@"Resources/monsterdata_cstest.mon",data); } // Now assert the buffer TestBuffer(fbb.DataBuffer); //Attempt to mutate Monster fields and check whether the buffer has been mutated properly // revert to original values after testing Monster monster = Monster.GetRootAsMonster(fbb.DataBuffer); // mana is optional and does not exist in the buffer so the mutation should fail // the mana field should retain its default value Assert.AreEqual(monster.MutateMana((short)10), false); Assert.AreEqual(monster.Mana, (short)150); // testType is an existing field and mutating it should succeed Assert.AreEqual(monster.TestType, Any.Monster); Assert.AreEqual(monster.MutateTestType(Any.NONE), true); Assert.AreEqual(monster.TestType, Any.NONE); Assert.AreEqual(monster.MutateTestType(Any.Monster), true); Assert.AreEqual(monster.TestType, Any.Monster); //mutate the inventory vector Assert.AreEqual(monster.MutateInventory(0, 1), true); Assert.AreEqual(monster.MutateInventory(1, 2), true); Assert.AreEqual(monster.MutateInventory(2, 3), true); Assert.AreEqual(monster.MutateInventory(3, 4), true); Assert.AreEqual(monster.MutateInventory(4, 5), true); for (int i = 0; i < monster.InventoryLength; i++) { Assert.AreEqual(monster.GetInventory(i), i + 1); } //reverse mutation Assert.AreEqual(monster.MutateInventory(0, 0), true); Assert.AreEqual(monster.MutateInventory(1, 1), true); Assert.AreEqual(monster.MutateInventory(2, 2), true); Assert.AreEqual(monster.MutateInventory(3, 3), true); Assert.AreEqual(monster.MutateInventory(4, 4), true); // get a struct field and edit one of its fields Vec3 pos = monster.Pos; Assert.AreEqual(pos.X, 1.0f); pos.MutateX(55.0f); Assert.AreEqual(pos.X, 55.0f); pos.MutateX(1.0f); Assert.AreEqual(pos.X, 1.0f); TestBuffer(fbb.DataBuffer); }
public void TestWithFloat() { var builder = new FlatBufferBuilder(1); builder.StartObject(1); builder.AddFloat(0, 1, 0); builder.EndObject(); Assert.ArrayEqual(new byte[] { 0, 0, 6, 0, // vtable bytes 8, 0, // object length 4, 0, // start of value 0 6, 0, 0, 0, // int32 offset for start of vtable 0, 0, 128, 63, // value }, builder.DataBuffer.Data); }
public void TestVTableWithEmptyVector() { var builder = new FlatBufferBuilder(1); builder.StartVector(sizeof(byte), 0, 1); var vecEnd = builder.EndVector(); builder.StartObject(1); builder.AddOffset(0, vecEnd.Value, 0); builder.EndObject(); Assert.ArrayEqual(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Padding to 32 bytes 6, 0, // vtable bytes 8, 0, // object length inc vtable offset 4, 0, // start of vector offset value 0 6, 0, 0, 0, // int32 offset for start of vtable 4, 0, 0, 0, 0, 0, 0, 0, }, builder.DataBuffer.Data); }
public static void AddGeometryType(FlatBufferBuilder builder, FlatGeobuf.GeometryType geometryType) { builder.AddByte(2, (byte)geometryType, 0); }
public static void StartEnvelopeVector(FlatBufferBuilder builder, int numElems) { builder.StartVector(8, numElems, 8); }
public static VectorOffset CreateEnvelopeVectorBlock(FlatBufferBuilder builder, double[] data) { builder.StartVector(8, data.Length, 8); builder.Add(data); return(builder.EndVector()); }
public static void AddEnvelope(FlatBufferBuilder builder, VectorOffset envelopeOffset) { builder.AddOffset(1, envelopeOffset.Value, 0); }
public static void AddName(FlatBufferBuilder builder, StringOffset nameOffset) { builder.AddOffset(0, nameOffset.Value, 0); }
public static void StartHeader(FlatBufferBuilder builder) { builder.StartTable(14); }
public static Offset <Transform> EndTransform(FlatBufferBuilder builder) { int o = builder.EndObject(); return(new Offset <Transform>(o)); }
public void TestTwoFinishTable() { var builder = new FlatBufferBuilder(1); builder.StartObject(2); builder.AddByte(0, 33, 0); builder.AddByte(1, 44, 0); var off0 = builder.EndObject(); builder.Finish(off0); builder.StartObject(3); builder.AddByte(0, 55, 0); builder.AddByte(1, 66, 0); builder.AddByte(2, 77, 0); var off1 = builder.EndObject(); builder.Finish(off1); Assert.ArrayEqual(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // padding to 64 bytes 16, 0, 0, 0, // root of table, pointing to vtable offset (obj1) 0, 0, // padding 10, 0, // vtable bytes 8, 0, // object length 7, 0, // start of value 0 6, 0, // start of value 1 5, 0, // start of value 2 10, 0, 0, 0, // int32 offset for start of vtable 0, // pad 77, // values 2, 1, 0 66, 55, 12, 0, 0, 0, // root of table, pointing to vtable offset (obj0) 8, 0, // vtable bytes 8, 0, // object length 7, 0, // start of value 0 6, 0, // start of value 1 8, 0, 0, 0, // int32 offset for start of vtable 0, 0, // pad 44, // value 1, 0 33, }, builder.DataBuffer.Data); }
public void TestVTableWithAStruct_of_int8_int16_int32() { var builder = new FlatBufferBuilder(1); builder.StartObject(1); builder.Prep(4+4+4, 0); builder.AddSbyte(55); builder.Pad(3); builder.AddShort(0x1234); builder.Pad(2); builder.AddInt(0x12345678); var structStart = builder.Offset; builder.AddStruct(0, structStart, 0); builder.EndObject(); Assert.ArrayEqual(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Padding to 32 bytes 6, 0, // vtable bytes 16, 0, // object length 4, 0, // start of struct from here 6, 0, 0, 0, // int32 offset for start of vtable 0x78, 0x56, 0x34, 0x12, // struct value 2 0x00, 0x00, 0x34, 0x12, // struct value 1 0x00, 0x00, 0x00, 55, // struct value 0 }, builder.DataBuffer.Data); }
public static void AddHasZ(FlatBufferBuilder builder, bool hasZ) { builder.AddBool(3, hasZ, false); }
public static void AddScale(FlatBufferBuilder builder, Offset <Vec3> scaleOffset) { builder.AddOffset(2, scaleOffset.Value, 0); }
public static void AddHasT(FlatBufferBuilder builder, bool hasT) { builder.AddBool(5, hasT, false); }
public static void AddHasTM(FlatBufferBuilder builder, bool hasTM) { builder.AddBool(6, hasTM, false); }
public static void AddColumns(FlatBufferBuilder builder, VectorOffset columnsOffset) { builder.AddOffset(7, columnsOffset.Value, 0); }
public static void AddPassword(FlatBufferBuilder builder, StringOffset passwordOffset) { builder.AddOffset(1, passwordOffset.Value, 0); }
public static VectorOffset CreateColumnsVectorBlock(FlatBufferBuilder builder, Offset <FlatGeobuf.Column>[] data) { builder.StartVector(4, data.Length, 4); builder.Add(data); return(builder.EndVector()); }
private void SendQueueData3() { while (true) { SensorData data = null; data = SensorDataContainer.Dequeue(); if (null != data) { try { //シリアライズ var fbb = new FlatBufferBuilder(1); // int str = fbb.CreateString("ETrobocon"); // data.StartMonster(fbb); // SensorData.AddName(fbb, str); // Monster.AddHp(fbb, 80); // int mon = Monster.EndMonster(fbb); // Monster.FinishMonsterBuffer(fbb, mon); var buf = fbb.DataBuffer(); Connection.Write(buf, 0, buf.Length); } catch (ArgumentNullException) { } catch (RankException) { } catch (Exception) { throw; } } else { break; } } }
public static void StartColumnsVector(FlatBufferBuilder builder, int numElems) { builder.StartVector(4, numElems, 4); }
public static void StartTransform(FlatBufferBuilder builder) { builder.StartObject(3); }
public static void AddFeaturesCount(FlatBufferBuilder builder, ulong featuresCount) { builder.AddUlong(8, featuresCount, 0); }
private FlatBufferBuilder CreateBuffer(bool forceDefaults = true) { var fbb = new FlatBufferBuilder(16) {ForceDefaults = forceDefaults}; fbb.StartObject(1); return fbb; }
public void TestVTableWithEmptyVectorAndScalars() { var builder = new FlatBufferBuilder(1); builder.StartVector(sizeof(byte), 0, 1); var vecEnd = builder.EndVector(); builder.StartObject(2); builder.AddShort(0, 55, 0); builder.AddOffset(1, vecEnd.Value, 0); builder.EndObject(); Assert.ArrayEqual(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, // Padding to 32 bytes 8, 0, // vtable bytes 12, 0, // object length inc vtable offset 10, 0, // offset to int16 value 0 4, 0, // start of vector offset value 1 8, 0, 0, 0, // int32 offset for start of vtable 8, 0, 0, 0, // value 1 0, 0, 55, 0, // value 0 0, 0, 0, 0, // length of vector (not in sctruc) }, builder.DataBuffer.Data); }
public void TestEmptyVTable() { var builder = new FlatBufferBuilder(1); builder.StartObject(0); Assert.ArrayEqual(new byte[] { 0 }, builder.DataBuffer.Data); builder.EndObject(); Assert.ArrayEqual(new byte[] { 4, 0, 4, 0, 4, 0, 0, 0 }, builder.DataBuffer.Data); }
public void TestVTableWithOneBool() { var builder = new FlatBufferBuilder(1); builder.StartObject(1); Assert.ArrayEqual(new byte[] { 0 }, builder.DataBuffer.Data); builder.AddBool(0, true, false); builder.EndObject(); Assert.ArrayEqual(new byte[] { 0, 0, // padding to 16 bytes 6, 0, // vtable bytes 8, 0, // object length inc vtable offset 7, 0, // start of bool value 6, 0, 0, 0, // int32 offset for start of vtable 0, 0, 0, // padding 1, // value 0 }, builder.DataBuffer.Data); }
public void TestVector_2xUInt16() { var builder = new FlatBufferBuilder(1); builder.StartVector(sizeof(ushort), 2, 1); Assert.ArrayEqual(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }, builder.DataBuffer.Data); builder.AddUshort(0xABCD); Assert.ArrayEqual(new byte[] { 0, 0, 0, 0, 0, 0, 0xCD, 0xAB }, builder.DataBuffer.Data); builder.AddUshort(0xDCBA); Assert.ArrayEqual(new byte[] { 0, 0, 0, 0, 0xBA, 0xDC, 0xCD, 0xAB }, builder.DataBuffer.Data); builder.EndVector(); Assert.ArrayEqual(new byte[] { 2, 0, 0, 0, 0xBA, 0xDC, 0xCD, 0xAB }, builder.DataBuffer.Data); }
public void TestVTableWithOneInt16() { var builder = new FlatBufferBuilder(1); builder.StartObject(1); Assert.ArrayEqual(new byte[] { 0 }, builder.DataBuffer.Data); builder.AddShort(0, 0x789A, 0); builder.EndObject(); Assert.ArrayEqual(new byte[] { 0, 0, // padding to 16 bytes 6, 0, // vtable bytes 8, 0, // object length inc vtable offset 6, 0, // start of int16 value 6, 0, 0, 0, // int32 offset for start of vtable 0, 0, // padding 0x9A, 0x78, //value 0 }, builder.DataBuffer.Data); }
public void TestVTableWithAVectorOf_2xStructOf_2xInt8() { var builder = new FlatBufferBuilder(1); builder.StartVector(sizeof(byte)*2, 2, 1); builder.AddByte(33); builder.AddByte(44); builder.AddByte(55); builder.AddByte(66); var vecEnd = builder.EndVector(); builder.StartObject(1); builder.AddOffset(0, vecEnd.Value, 0); builder.EndObject(); Assert.ArrayEqual(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Padding to 32 bytes 6, 0, // vtable bytes 8, 0, // object length 4, 0, // offset of vector offset 6, 0, 0, 0, // int32 offset for start of vtable 4, 0, 0, 0, // Vector start offset 2, 0, 0, 0, // Vector len 66, // vector 1, 1 55, // vector 1, 0 44, // vector 0, 1 33, // vector 0, 0 }, builder.DataBuffer.Data); }
public void TestVTableWithTwoInt16() { var builder = new FlatBufferBuilder(1); builder.StartObject(2); Assert.ArrayEqual(new byte[] { 0 }, builder.DataBuffer.Data); builder.AddShort(0, 0x3456, 0); builder.AddShort(1, 0x789A, 0); builder.EndObject(); Assert.ArrayEqual(new byte[] { 8, 0, // vtable bytes 8, 0, // object length inc vtable offset 6, 0, // start of int16 value 0 4, 0, // start of int16 value 1 8, 0, 0, 0, // int32 offset for start of vtable 0x9A, 0x78, // value 1 0x56, 0x34, // value 0 }, builder.DataBuffer.Data); }
public static void AddIndexNodeSize(FlatBufferBuilder builder, ushort indexNodeSize) { builder.AddUshort(9, indexNodeSize, 16); }
public static void AddRotation(FlatBufferBuilder builder, Offset <Vec4> rotationOffset) { builder.AddOffset(1, rotationOffset.Value, 0); }
public void TestVTableWithInt16AndBool() { var builder = new FlatBufferBuilder(1); builder.StartObject(2); Assert.ArrayEqual(new byte[] { 0 }, builder.DataBuffer.Data); builder.AddShort(0, 0x3456, 0); builder.AddBool(1, true, false); builder.EndObject(); Assert.ArrayEqual(new byte[] { 8, 0, // vtable bytes 8, 0, // object length inc vtable offset 6, 0, // start of int16 value 0 5, 0, // start of bool value 1 8, 0, 0, 0, // int32 offset for start of vtable 0, 1, // padding + value 1 0x56, 0x34, // value 0 }, builder.DataBuffer.Data); }
public static void AddCrs(FlatBufferBuilder builder, Offset <FlatGeobuf.Crs> crsOffset) { builder.AddOffset(10, crsOffset.Value, 0); }
public void TestVTableWithOneBool_DefaultValue() { var builder = new FlatBufferBuilder(1); builder.StartObject(1); Assert.ArrayEqual(new byte[] { 0 }, builder.DataBuffer.Data); builder.AddBool(0, false, false); builder.EndObject(); Assert.ArrayEqual(new byte[] { 0, 0, 0, 0, 0, 0, // padding to 16 bytes 6, 0, // vtable bytes 4, 0, // end of object from here 0, 0, // entry 0 is empty (default value) 6, 0, 0, 0, // int32 offset for start of vtable }, builder.DataBuffer.Data); }
public static void AddTitle(FlatBufferBuilder builder, StringOffset titleOffset) { builder.AddOffset(11, titleOffset.Value, 0); }
public void TestVTableWithSomeElements() { var builder = new FlatBufferBuilder(1); builder.StartObject(2); builder.AddByte(0, 33, 0); builder.AddShort(1, 66, 0); var off = builder.EndObject(); builder.Finish(off); Assert.ArrayEqual(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //Padding to 32 bytes 12, 0, 0, 0, // root of table, pointing to vtable offset 8, 0, // vtable bytes 8, 0, // object length 7, 0, // start of value 0 4, 0, // start of value 1 8, 0, 0, 0, // int32 offset for start of vtable 66, 0, // value 1 0, 33, // value 0 }, builder.DataBuffer.Data); }
public static void AddDescription(FlatBufferBuilder builder, StringOffset descriptionOffset) { builder.AddOffset(12, descriptionOffset.Value, 0); }
public void TestVTableWith_1xInt16_and_Vector_or_2xInt16() { var builder = new FlatBufferBuilder(1); builder.StartVector(sizeof(short), 2, 1); builder.AddShort(0x1234); builder.AddShort(0x5678); var vecEnd = builder.EndVector(); builder.StartObject(2); builder.AddOffset(1, vecEnd.Value, 0); builder.AddShort(0, 55, 0); builder.EndObject(); Assert.ArrayEqual(new byte[] { 0, 0, 0, 0, // Padding to 32 bytes 8, 0, // vtable bytes 12, 0, // object length 6, 0, // start of value 0 from end of vtable 8, 0, // start of value 1 from end of buffer 8, 0, 0, 0, // int32 offset for start of vtable 0, 0, 55, 0, // padding + value 0 4, 0, 0, 0, // position of vector from here 2, 0, 0, 0, // length of vector 0x78, 0x56, // vector value 0 0x34, 0x12, // vector value 1 }, builder.DataBuffer.Data); }
public static void AddMetadata(FlatBufferBuilder builder, StringOffset metadataOffset) { builder.AddOffset(13, metadataOffset.Value, 0); }
private void CheckObjects(int fieldCount, int objectCount) { _lcg.Reset(); const int testValuesMax = 11; var builder = new FlatBufferBuilder(1); var objects = new int[objectCount]; for (var i = 0; i < objectCount; ++i) { builder.StartObject(fieldCount); for (var j = 0; j < fieldCount; ++j) { var fieldType = _lcg.Next()%testValuesMax; switch (fieldType) { case 0: { builder.AddBool(j, FuzzTestData.BoolValue, false); break; } case 1: { builder.AddSbyte(j, FuzzTestData.Int8Value, 0); break; } case 2: { builder.AddByte(j, FuzzTestData.UInt8Value, 0); break; } case 3: { builder.AddShort(j, FuzzTestData.Int16Value, 0); break; } case 4: { builder.AddUshort(j, FuzzTestData.UInt16Value, 0); break; } case 5: { builder.AddInt(j, FuzzTestData.Int32Value, 0); break; } case 6: { builder.AddUint(j, FuzzTestData.UInt32Value, 0); break; } case 7: { builder.AddLong(j, FuzzTestData.Int64Value, 0); break; } case 8: { builder.AddUlong(j, FuzzTestData.UInt64Value, 0); break; } case 9: { builder.AddFloat(j, FuzzTestData.Float32Value, 0); break; } case 10: { builder.AddDouble(j, FuzzTestData.Float64Value, 0); break; } default: throw new Exception("Unreachable"); } } var offset = builder.EndObject(); // Store the object offset objects[i] = offset; } _lcg.Reset(); // Test all objects are readable and return expected values... for (var i = 0; i < objectCount; ++i) { var table = new TestTable(builder.DataBuffer, builder.DataBuffer.Length - objects[i]); for (var j = 0; j < fieldCount; ++j) { var fieldType = _lcg.Next() % testValuesMax; var fc = 2 + j; // 2 == VtableMetadataFields var f = fc * 2; switch (fieldType) { case 0: { Assert.AreEqual(FuzzTestData.BoolValue, table.GetSlot(f, false)); break; } case 1: { Assert.AreEqual(FuzzTestData.Int8Value, table.GetSlot(f, (sbyte)0)); break; } case 2: { Assert.AreEqual(FuzzTestData.UInt8Value, table.GetSlot(f, (byte)0)); break; } case 3: { Assert.AreEqual(FuzzTestData.Int16Value, table.GetSlot(f, (short)0)); break; } case 4: { Assert.AreEqual(FuzzTestData.UInt16Value, table.GetSlot(f, (ushort)0)); break; } case 5: { Assert.AreEqual(FuzzTestData.Int32Value, table.GetSlot(f, (int)0)); break; } case 6: { Assert.AreEqual(FuzzTestData.UInt32Value, table.GetSlot(f, (uint)0)); break; } case 7: { Assert.AreEqual(FuzzTestData.Int64Value, table.GetSlot(f, (long)0)); break; } case 8: { Assert.AreEqual(FuzzTestData.UInt64Value, table.GetSlot(f, (ulong)0)); break; } case 9: { Assert.AreEqual(FuzzTestData.Float32Value, table.GetSlot(f, (float)0)); break; } case 10: { Assert.AreEqual(FuzzTestData.Float64Value, table.GetSlot(f, (double)0)); break; } default: throw new Exception("Unreachable"); } } } }
public static Offset <FlatGeobuf.Header> EndHeader(FlatBufferBuilder builder) { int o = builder.EndTable(); return(new Offset <FlatGeobuf.Header>(o)); }
public void TestNestedFlatBuffer() { const string nestedMonsterName = "NestedMonsterName"; const short nestedMonsterHp = 600; const short nestedMonsterMana = 1024; // Create nested buffer as a Monster type var fbb1 = new FlatBufferBuilder(16); var str1 = fbb1.CreateString(nestedMonsterName); Monster.StartMonster(fbb1); Monster.AddName(fbb1, str1); Monster.AddHp(fbb1, nestedMonsterHp); Monster.AddMana(fbb1, nestedMonsterMana); var monster1 = Monster.EndMonster(fbb1); Monster.FinishMonsterBuffer(fbb1, monster1); var fbb1Bytes = fbb1.SizedByteArray(); fbb1 = null; // Create a Monster which has the first buffer as a nested buffer var fbb2 = new FlatBufferBuilder(16); var str2 = fbb2.CreateString("My Monster"); var nestedBuffer = Monster.CreateTestnestedflatbufferVector(fbb2, fbb1Bytes); Monster.StartMonster(fbb2); Monster.AddName(fbb2, str2); Monster.AddHp(fbb2, 50); Monster.AddMana(fbb2, 32); Monster.AddTestnestedflatbuffer(fbb2, nestedBuffer); var monster = Monster.EndMonster(fbb2); Monster.FinishMonsterBuffer(fbb2, monster); // Now test the data extracted from the nested buffer var mons = Monster.GetRootAsMonster(fbb2.DataBuffer); var nestedMonster = mons.TestnestedflatbufferAsMonster(); Assert.AreEqual(nestedMonsterMana, nestedMonster.Mana); Assert.AreEqual(nestedMonsterHp, nestedMonster.Hp); Assert.AreEqual(nestedMonsterName, nestedMonster.Name); }
public static void FinishSizePrefixedHeaderBuffer(FlatBufferBuilder builder, Offset <FlatGeobuf.Header> offset) { builder.FinishSizePrefixed(offset.Value); }
public static void StartRawImage(FlatBufferBuilder builder) { builder.StartTable(3); }
public static void AddAccount(FlatBufferBuilder builder, StringOffset accountOffset) { builder.AddOffset(0, accountOffset.Value, 0); }