aboutsummaryrefslogtreecommitdiff
path: root/tests/MyGame/Example/TestSimpleTableWithEnum.php
diff options
context:
space:
mode:
authorShuhei Taunma <chobieee@gmail.com>2015-11-05 16:19:28 +0900
committerShuhei Tanuma <chobieee@gmail.com>2015-11-18 00:26:39 +0900
commit5ce86826718c938e38b0f57e4bc5840fe15a1565 (patch)
tree7b34312db70588595b515c21fd8df36814cf27dd /tests/MyGame/Example/TestSimpleTableWithEnum.php
parent3f1c4b41f650a5d4e9f89f606f01ba0a6a164029 (diff)
downloadflatbuffers-5ce86826718c938e38b0f57e4bc5840fe15a1565.tar.gz
(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.
Diffstat (limited to 'tests/MyGame/Example/TestSimpleTableWithEnum.php')
-rw-r--r--tests/MyGame/Example/TestSimpleTableWithEnum.php99
1 files changed, 99 insertions, 0 deletions
diff --git a/tests/MyGame/Example/TestSimpleTableWithEnum.php b/tests/MyGame/Example/TestSimpleTableWithEnum.php
new file mode 100644
index 00000000..6181461e
--- /dev/null
+++ b/tests/MyGame/Example/TestSimpleTableWithEnum.php
@@ -0,0 +1,99 @@
+<?php
+// automatically generated, do not modify
+
+namespace MyGame\Example;
+
+use \Google\FlatBuffers\Struct;
+use \Google\FlatBuffers\Table;
+use \Google\FlatBuffers\ByteBuffer;
+use \Google\FlatBuffers\FlatBufferBuilder;
+
+class TestSimpleTableWithEnum extends Table
+{
+ /**
+ * @param ByteBuffer $bb
+ * @return TestSimpleTableWithEnum
+ */
+ public static function getRootAsTestSimpleTableWithEnum(ByteBuffer $bb)
+ {
+ $obj = new TestSimpleTableWithEnum();
+ return ($obj->init($bb->getInt($bb->getPosition()) + $bb->getPosition(), $bb));
+ }
+
+ public static function TestSimpleTableWithEnumIdentifier()
+ {
+ return "MONS";
+ }
+
+ public static function TestSimpleTableWithEnumBufferHasIdentifier(ByteBuffer $buf)
+ {
+ return self::__has_identifier($buf, self::TestSimpleTableWithEnumIdentifier());
+ }
+
+ public static function TestSimpleTableWithEnumExtension()
+ {
+ return "mon";
+ }
+
+ /**
+ * @param int $_i offset
+ * @param ByteBuffer $_bb
+ * @return TestSimpleTableWithEnum
+ **/
+ public function init($_i, ByteBuffer $_bb)
+ {
+ $this->bb_pos = $_i;
+ $this->bb = $_bb;
+ return $this;
+ }
+
+ /**
+ * @return sbyte
+ */
+ public function getColor()
+ {
+ $o = $this->__offset(4);
+ return $o != 0 ? $this->bb->getSbyte($o + $this->bb_pos) : \MyGame\Example\Color::Green;
+ }
+
+ /**
+ * @param FlatBufferBuilder $builder
+ * @return void
+ */
+ public static function startTestSimpleTableWithEnum(FlatBufferBuilder $builder)
+ {
+ $builder->StartObject(1);
+ }
+
+ /**
+ * @param FlatBufferBuilder $builder
+ * @return TestSimpleTableWithEnum
+ */
+ public static function createTestSimpleTableWithEnum(FlatBufferBuilder $builder, $color)
+ {
+ $builder->startObject(1);
+ self::addColor($builder, $color);
+ $o = $builder->endObject();
+ return $o;
+ }
+
+ /**
+ * @param FlatBufferBuilder $builder
+ * @param sbyte
+ * @return void
+ */
+ public static function addColor(FlatBufferBuilder $builder, $color)
+ {
+ $builder->addSbyteX(0, $color, 2);
+ }
+
+ /**
+ * @param FlatBufferBuilder $builder
+ * @return int table offset
+ */
+ public static function endTestSimpleTableWithEnum(FlatBufferBuilder $builder)
+ {
+ $o = $builder->endObject();
+ return $o;
+ }
+}