function main() { /// Begin Test $assert = new Assert(); // First, let's test reading a FlatBuffer generated by C++ code: // This file was generated from monsterdata_test.json // Now test it: $data = file_get_contents('monsterdata_test.mon'); $bb = Google\FlatBuffers\ByteBuffer::wrap($data); test_buffer($assert, $bb); // Second, let's create a FlatBuffer from scratch in JavaScript, 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. $fbb = new Google\FlatBuffers\FlatBufferBuilder(1); // We set up the same values as monsterdata.json: $str = $fbb->createString("MyMonster"); $name = $fbb->createString('Fred'); \MyGame\Example\Monster::startMonster($fbb); \MyGame\Example\Monster::addName($fbb, $name); $enemy = \MyGame\Example\Monster::endMonster($fbb); $inv = \MyGame\Example\Monster::CreateInventoryVector($fbb, array(0, 1, 2, 3, 4)); $fred = $fbb->createString('Fred'); \MyGame\Example\Monster::StartMonster($fbb); \MyGame\Example\Monster::AddName($fbb, $fred); $mon2 = \MyGame\Example\Monster::EndMonster($fbb); \MyGame\Example\Monster::StartTest4Vector($fbb, 2); \MyGame\Example\Test::CreateTest($fbb, 10, 20); \MyGame\Example\Test::CreateTest($fbb, 30, 40); $test4 = $fbb->endVector(); $testArrayOfString = \MyGame\Example\Monster::CreateTestarrayofstringVector($fbb, array($fbb->createString('test1'), $fbb->createString('test2'))); \MyGame\Example\Monster::StartMonster($fbb); \MyGame\Example\Monster::AddPos($fbb, \MyGame\Example\Vec3::CreateVec3($fbb, 1.0, 2.0, 3.0, 3.0, \MyGame\Example\Color::Green, 5, 6)); \MyGame\Example\Monster::AddHp($fbb, 80); \MyGame\Example\Monster::AddName($fbb, $str); \MyGame\Example\Monster::AddInventory($fbb, $inv); \MyGame\Example\Monster::AddTestType($fbb, \MyGame\Example\Any::Monster); \MyGame\Example\Monster::AddTest($fbb, $mon2); \MyGame\Example\Monster::AddTest4($fbb, $test4); \MyGame\Example\Monster::AddTestarrayofstring($fbb, $testArrayOfString); \MyGame\Example\Monster::AddEnemy($fbb, $enemy); \MyGame\Example\Monster::AddTestbool($fbb, false); $mon = \MyGame\Example\Monster::EndMonster($fbb); \MyGame\Example\Monster::FinishMonsterBuffer($fbb, $mon); // Test it: test_buffer($assert, $fbb->dataBuffer()); testByteBuffer($assert); fuzzTest1($assert); // testUnicode($assert); echo 'FlatBuffers php test: completed successfully' . PHP_EOL; }
public function getPos() { $obj = new Vec3(); $o = $this->__offset(4); return $o != 0 ? $obj->init($o + $this->bb_pos, $this->bb) : 0; }