(PHP) add experimental support for PHP language.
* codegen for all basic features: WIP (probably implemented all basic feature)
* JSON parsing: NO
* Simple mutation: NO
* Reflection: NO
* Buffer verifier: NO (will be add later)
* Testing: basic: Yes
* Testing: fuzz: Yes
* Performance: Not bad
* Platform: Supported Linux, OS X, Windows (has 32bit integer limitation)
* Engine Unity: No
flatc --php monster_test.fbs
<?php
//include neccessary files.
$fbb = new Google\FlatBuffers\FlatBufferBuilder(1);
$str = $fbb->createString("monster");
\MyGame\Example\Monster::startMonster($fbb);
\MyGame\Example\Monster::addHp($fbb, 80);
\MyGame\Example\Monster::addName($fbb, $str);
$mon = \MyGame\Example\Monster::endMonster($fbb);
$fbb->finish($mon);
echo $fbb->sizedByteArray();
PHP 5.4 higher
Currently, we do not register this library to packagist as still experimental and versioning problem.
If you intended to use flatbuffers with composer. add repostiories section to composer.json like below.
"repositories": [{
"type": "vcs",
"url": "https://github.com/google/flatbuffers"
}],
and just put google/flatbuffers.
"require": {
"google/flatbuffers": "*"
}
* PHP's integer is platform dependant. we strongly recommend use 64bit machine
and don't use uint, ulong types as prevent overflow issue.
ref: http://php.net/manual/en/language.types.integer.php
* php don't support float type. floating point numbers are always parsed as double precision internally.
ref: http://php.net/manual/en/language.types.float.php
* ByteBuffer is little bit slow implemnentation due to many chr/ord function calls. Especially encoding objects.
This is expected performance as PHP5 has parsing arguments overhead. probably we'll add C-extension.
Basically, PHP implementation respects Java and C# implementation.
Note: ByteBuffer and FlatBuffersBuilder class are not intended to use other purposes.
we may change internal API foreseeable future.
PSR-2, PSR-4 standards.
Implemented simple assertion class (respect JavaScript testcase implementation) as we prefer small code base.
this also keeps CI iteration speed.
we'll choose phpunit or something when the test cases grown.
2015-11-05 07:19:28 +00:00
|
|
|
<?php
|
2016-05-26 13:26:58 +00:00
|
|
|
// automatically generated by the FlatBuffers compiler, do not modify
|
(PHP) add experimental support for PHP language.
* codegen for all basic features: WIP (probably implemented all basic feature)
* JSON parsing: NO
* Simple mutation: NO
* Reflection: NO
* Buffer verifier: NO (will be add later)
* Testing: basic: Yes
* Testing: fuzz: Yes
* Performance: Not bad
* Platform: Supported Linux, OS X, Windows (has 32bit integer limitation)
* Engine Unity: No
flatc --php monster_test.fbs
<?php
//include neccessary files.
$fbb = new Google\FlatBuffers\FlatBufferBuilder(1);
$str = $fbb->createString("monster");
\MyGame\Example\Monster::startMonster($fbb);
\MyGame\Example\Monster::addHp($fbb, 80);
\MyGame\Example\Monster::addName($fbb, $str);
$mon = \MyGame\Example\Monster::endMonster($fbb);
$fbb->finish($mon);
echo $fbb->sizedByteArray();
PHP 5.4 higher
Currently, we do not register this library to packagist as still experimental and versioning problem.
If you intended to use flatbuffers with composer. add repostiories section to composer.json like below.
"repositories": [{
"type": "vcs",
"url": "https://github.com/google/flatbuffers"
}],
and just put google/flatbuffers.
"require": {
"google/flatbuffers": "*"
}
* PHP's integer is platform dependant. we strongly recommend use 64bit machine
and don't use uint, ulong types as prevent overflow issue.
ref: http://php.net/manual/en/language.types.integer.php
* php don't support float type. floating point numbers are always parsed as double precision internally.
ref: http://php.net/manual/en/language.types.float.php
* ByteBuffer is little bit slow implemnentation due to many chr/ord function calls. Especially encoding objects.
This is expected performance as PHP5 has parsing arguments overhead. probably we'll add C-extension.
Basically, PHP implementation respects Java and C# implementation.
Note: ByteBuffer and FlatBuffersBuilder class are not intended to use other purposes.
we may change internal API foreseeable future.
PSR-2, PSR-4 standards.
Implemented simple assertion class (respect JavaScript testcase implementation) as we prefer small code base.
this also keeps CI iteration speed.
we'll choose phpunit or something when the test cases grown.
2015-11-05 07:19:28 +00:00
|
|
|
|
|
|
|
namespace MyGame\Example;
|
|
|
|
|
|
|
|
use \Google\FlatBuffers\Struct;
|
|
|
|
use \Google\FlatBuffers\Table;
|
|
|
|
use \Google\FlatBuffers\ByteBuffer;
|
|
|
|
use \Google\FlatBuffers\FlatBufferBuilder;
|
|
|
|
|
|
|
|
class Stat extends Table
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param ByteBuffer $bb
|
|
|
|
* @return Stat
|
|
|
|
*/
|
|
|
|
public static function getRootAsStat(ByteBuffer $bb)
|
|
|
|
{
|
|
|
|
$obj = new Stat();
|
|
|
|
return ($obj->init($bb->getInt($bb->getPosition()) + $bb->getPosition(), $bb));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function StatIdentifier()
|
|
|
|
{
|
|
|
|
return "MONS";
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function StatBufferHasIdentifier(ByteBuffer $buf)
|
|
|
|
{
|
|
|
|
return self::__has_identifier($buf, self::StatIdentifier());
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function StatExtension()
|
|
|
|
{
|
|
|
|
return "mon";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $_i offset
|
|
|
|
* @param ByteBuffer $_bb
|
|
|
|
* @return Stat
|
|
|
|
**/
|
|
|
|
public function init($_i, ByteBuffer $_bb)
|
|
|
|
{
|
|
|
|
$this->bb_pos = $_i;
|
|
|
|
$this->bb = $_bb;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getId()
|
|
|
|
{
|
|
|
|
$o = $this->__offset(4);
|
|
|
|
return $o != 0 ? $this->__string($o + $this->bb_pos) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return long
|
|
|
|
*/
|
|
|
|
public function getVal()
|
|
|
|
{
|
|
|
|
$o = $this->__offset(6);
|
|
|
|
return $o != 0 ? $this->bb->getLong($o + $this->bb_pos) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ushort
|
|
|
|
*/
|
|
|
|
public function getCount()
|
|
|
|
{
|
|
|
|
$o = $this->__offset(8);
|
|
|
|
return $o != 0 ? $this->bb->getUshort($o + $this->bb_pos) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param FlatBufferBuilder $builder
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function startStat(FlatBufferBuilder $builder)
|
|
|
|
{
|
|
|
|
$builder->StartObject(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param FlatBufferBuilder $builder
|
|
|
|
* @return Stat
|
|
|
|
*/
|
|
|
|
public static function createStat(FlatBufferBuilder $builder, $id, $val, $count)
|
|
|
|
{
|
|
|
|
$builder->startObject(3);
|
|
|
|
self::addId($builder, $id);
|
|
|
|
self::addVal($builder, $val);
|
|
|
|
self::addCount($builder, $count);
|
|
|
|
$o = $builder->endObject();
|
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param FlatBufferBuilder $builder
|
|
|
|
* @param StringOffset
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function addId(FlatBufferBuilder $builder, $id)
|
|
|
|
{
|
|
|
|
$builder->addOffsetX(0, $id, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param FlatBufferBuilder $builder
|
|
|
|
* @param long
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function addVal(FlatBufferBuilder $builder, $val)
|
|
|
|
{
|
|
|
|
$builder->addLongX(1, $val, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param FlatBufferBuilder $builder
|
|
|
|
* @param ushort
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function addCount(FlatBufferBuilder $builder, $count)
|
|
|
|
{
|
|
|
|
$builder->addUshortX(2, $count, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param FlatBufferBuilder $builder
|
|
|
|
* @return int table offset
|
|
|
|
*/
|
|
|
|
public static function endStat(FlatBufferBuilder $builder)
|
|
|
|
{
|
|
|
|
$o = $builder->endObject();
|
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
}
|