Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
flatbuffers
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
flatbuffers
Commits
c9198dbb
Commit
c9198dbb
authored
Dec 17, 2015
by
Shuhei Tanuma
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(PHP) fixes getting indirect table, also fixes getInt method on 32bit machine.
parent
b974e95c
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
37 additions
and
4 deletions
+37
-4
ByteBuffer.php
php/ByteBuffer.php
+5
-0
idl_gen_php.cpp
src/idl_gen_php.cpp
+7
-1
Monster.php
tests/MyGame/Example/Monster.php
+2
-2
generate_code.bat
tests/generate_code.bat
+2
-0
generate_code.sh
tests/generate_code.sh
+2
-0
monsterdata_indirect.json
tests/monsterdata_indirect.json
+7
-0
monsterdata_indirect.mon
tests/monsterdata_indirect.mon
+0
-0
phpTest.php
tests/phpTest.php
+12
-1
No files found.
php/ByteBuffer.php
View file @
c9198dbb
...
...
@@ -399,8 +399,13 @@ class ByteBuffer
$sign
=
$index
+
(
ByteBuffer
::
isLittleEndian
()
?
3
:
0
);
$issigned
=
isset
(
$this
->
_buffer
[
$sign
])
&&
ord
(
$this
->
_buffer
[
$sign
])
&
0x80
;
if
(
PHP_INT_SIZE
>
4
)
{
// 4294967296 = 1 << 32 = Maximum unsigned 32-bit int
return
$issigned
?
$result
-
4294967296
:
$result
;
}
else
{
// 32bit / Windows treated number as signed integer.
return
$result
;
}
}
/**
...
...
src/idl_gen_php.cpp
View file @
c9198dbb
...
...
@@ -249,7 +249,13 @@ namespace php {
NumToString
(
field
.
value
.
offset
)
+
");
\n
"
;
code
+=
Indent
+
Indent
;
code
+=
"return $o != 0 ? $obj->init($o + $this->bb_pos, $this->bb) : "
;
code
+=
"return $o != 0 ? $obj->init("
;
if
(
field
.
value
.
type
.
struct_def
->
fixed
)
{
code
+=
"$o + $this->bb_pos, $this->bb) : "
;
}
else
{
code
+=
"$this->__indirect($o + $this->bb_pos), $this->bb) : "
;
}
code
+=
GenDefaultValue
(
field
.
value
)
+
";
\n
"
;
code
+=
Indent
+
"}
\n\n
"
;
}
...
...
tests/MyGame/Example/Monster.php
View file @
c9198dbb
...
...
@@ -188,7 +188,7 @@ class Monster extends Table
{
$obj
=
new
Monster
();
$o
=
$this
->
__offset
(
28
);
return
$o
!=
0
?
$obj
->
init
(
$
o
+
$this
->
bb_pos
,
$this
->
bb
)
:
0
;
return
$o
!=
0
?
$obj
->
init
(
$
this
->
__indirect
(
$o
+
$this
->
bb_pos
)
,
$this
->
bb
)
:
0
;
}
/**
...
...
@@ -214,7 +214,7 @@ class Monster extends Table
{
$obj
=
new
Stat
();
$o
=
$this
->
__offset
(
32
);
return
$o
!=
0
?
$obj
->
init
(
$
o
+
$this
->
bb_pos
,
$this
->
bb
)
:
0
;
return
$o
!=
0
?
$obj
->
init
(
$
this
->
__indirect
(
$o
+
$this
->
bb_pos
)
,
$this
->
bb
)
:
0
;
}
/**
...
...
tests/generate_code.bat
View file @
c9198dbb
..\flatc.exe -c -j -n -g -b -p --php -s --gen-mutable --no-includes monster_test.fbs monsterdata_test.json
..\flatc.exe -b --schema monster_test.fbs
..\flatc.exe -b .\monster_test.fbs .\monsterdata_indirect.json
\ No newline at end of file
tests/generate_code.sh
View file @
c9198dbb
../flatc
--cpp
--java
--csharp
--go
--binary
--python
--js
--php
--gen-mutable
--no-includes
monster_test.fbs monsterdata_test.json
../flatc
--binary
--schema
monster_test.fbs
../flatc
--binary
monster_test.fbs monsterdata_indirect.json
\ No newline at end of file
tests/monsterdata_indirect.json
0 → 100644
View file @
c9198dbb
{
"name"
:
"Gob"
,
"enemy"
:
{
"name"
:
"Awk"
}
}
\ No newline at end of file
tests/monsterdata_indirect.mon
0 → 100644
View file @
c9198dbb
File added
tests/phpTest.php
View file @
c9198dbb
...
...
@@ -74,6 +74,9 @@ function main()
fuzzTest1
(
$assert
);
// testUnicode($assert);
testIndirectBuffer
(
$assert
);
echo
'FlatBuffers php test: completed successfully'
.
PHP_EOL
;
}
...
...
@@ -587,7 +590,15 @@ function testByteBuffer(Assert $assert) {
$assert
->
Equal
(
0x0D0C0B0A
,
$uut
->
readLittleEndian
(
0
,
4
,
true
));
}
function
testIndirectBuffer
(
Assert
$assert
)
{
$js
=
json_decode
(
file_get_contents
(
'monsterdata_indirect.json'
),
true
);
$data
=
file_get_contents
(
'monsterdata_indirect.mon'
);
$bb
=
Google\FlatBuffers\ByteBuffer
::
wrap
(
$data
);
$mons
=
\MyGame\Example\Monster
::
getRootAsMonster
(
$bb
);
$assert
->
Equal
(
$js
[
"name"
],
$mons
->
getName
());
$assert
->
Equal
(
$js
[
"enemy"
][
"name"
],
$mons
->
getEnemy
()
->
getName
());
}
class
Assert
{
public
function
ok
(
$result
,
$message
=
""
)
{
if
(
!
$result
){
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment