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
5e3f9d51
Commit
5e3f9d51
authored
Apr 04, 2016
by
Wouter van Oortmerssen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/google/flatbuffers
parents
e98b1912
cdc5d5b1
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
88 additions
and
12 deletions
+88
-12
CMakeLists.txt
CMakeLists.txt
+8
-1
Tutorial.md
docs/source/Tutorial.md
+2
-2
flatbuffers.h
include/flatbuffers/flatbuffers.h
+12
-4
idl.h
include/flatbuffers/idl.h
+2
-0
Table.php
php/Table.php
+9
-3
readme.md
readme.md
+1
-1
flatc.cpp
src/flatc.cpp
+3
-0
idl_gen_cpp.cpp
src/idl_gen_cpp.cpp
+15
-1
idl_gen_php.cpp
src/idl_gen_php.cpp
+19
-0
Monster.php
tests/MyGame/Example/Monster.php
+16
-0
phpTest.php
tests/phpTest.php
+1
-0
No files found.
CMakeLists.txt
View file @
5e3f9d51
...
@@ -82,8 +82,15 @@ if(APPLE)
...
@@ -82,8 +82,15 @@ if(APPLE)
set
(
CMAKE_CXX_FLAGS
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-std=c++11 -stdlib=libc++ -Wall -pedantic -Werror -Wextra"
)
"
${
CMAKE_CXX_FLAGS
}
-std=c++11 -stdlib=libc++ -Wall -pedantic -Werror -Wextra"
)
elseif
(
CMAKE_COMPILER_IS_GNUCXX
)
elseif
(
CMAKE_COMPILER_IS_GNUCXX
)
if
(
CYGWIN
)
set
(
CMAKE_CXX_FLAGS
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-std=c++0x -Wall -pedantic -Werror -Wextra -Werror=shadow"
)
"
${
CMAKE_CXX_FLAGS
}
-std=gnu++11"
)
else
(
CYGWIN
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-std=c++0x"
)
endif
(
CYGWIN
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-Wall -pedantic -Werror -Wextra -Werror=shadow"
)
if
(
GCC_VERSION VERSION_GREATER 4.4
)
if
(
GCC_VERSION VERSION_GREATER 4.4
)
set
(
CMAKE_CXX_FLAGS
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-Wunused-result -Werror=unused-result"
)
"
${
CMAKE_CXX_FLAGS
}
-Wunused-result -Werror=unused-result"
)
...
...
docs/source/Tutorial.md
View file @
5e3f9d51
...
@@ -432,10 +432,10 @@ our `orc` Monster, lets create some `Weapon`s: a `Sword` and an `Axe`.
...
@@ -432,10 +432,10 @@ our `orc` Monster, lets create some `Weapon`s: a `Sword` and an `Axe`.
</div>
</div>
<div
class=
"language-java"
>
<div
class=
"language-java"
>
~~~
{.java}
~~~
{.java}
String
weaponOneName = builder.createString("Sword")
int
weaponOneName = builder.createString("Sword")
short weaponOneDamage = 3;
short weaponOneDamage = 3;
String
weaponTwoName = builder.createString("Axe");
int
weaponTwoName = builder.createString("Axe");
short weaponTwoDamage = 5;
short weaponTwoDamage = 5;
// Use the `createWeapon()` helper function to create the weapons, since we set every field.
// Use the `createWeapon()` helper function to create the weapons, since we set every field.
...
...
include/flatbuffers/flatbuffers.h
View file @
5e3f9d51
...
@@ -91,6 +91,14 @@
...
@@ -91,6 +91,14 @@
#else
#else
#define FLATBUFFERS_FINAL_CLASS
#define FLATBUFFERS_FINAL_CLASS
#endif
#endif
#if (!defined(_MSC_VER) || _MSC_VER >= 1900) && \
(!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 406))
#define FLATBUFFERS_CONSTEXPR constexpr
#else
#define FLATBUFFERS_CONSTEXPR
#endif
/// @endcond
/// @endcond
/// @file
/// @file
...
@@ -1112,14 +1120,14 @@ FLATBUFFERS_FINAL_CLASS
...
@@ -1112,14 +1120,14 @@ FLATBUFFERS_FINAL_CLASS
bool
force_defaults_
;
// Serialize values equal to their defaults anyway.
bool
force_defaults_
;
// Serialize values equal to their defaults anyway.
struct
StringOffsetCompare
{
struct
StringOffsetCompare
{
StringOffsetCompare
(
const
vector_downward
&
buf
)
:
buf_
(
buf
)
{}
StringOffsetCompare
(
const
vector_downward
&
buf
)
:
buf_
(
&
buf
)
{}
bool
operator
()
(
const
Offset
<
String
>
&
a
,
const
Offset
<
String
>
&
b
)
const
{
bool
operator
()
(
const
Offset
<
String
>
&
a
,
const
Offset
<
String
>
&
b
)
const
{
auto
stra
=
reinterpret_cast
<
const
String
*>
(
buf_
.
data_at
(
a
.
o
));
auto
stra
=
reinterpret_cast
<
const
String
*>
(
buf_
->
data_at
(
a
.
o
));
auto
strb
=
reinterpret_cast
<
const
String
*>
(
buf_
.
data_at
(
b
.
o
));
auto
strb
=
reinterpret_cast
<
const
String
*>
(
buf_
->
data_at
(
b
.
o
));
return
strncmp
(
stra
->
c_str
(),
strb
->
c_str
(),
return
strncmp
(
stra
->
c_str
(),
strb
->
c_str
(),
std
::
min
(
stra
->
size
(),
strb
->
size
())
+
1
)
<
0
;
std
::
min
(
stra
->
size
(),
strb
->
size
())
+
1
)
<
0
;
}
}
const
vector_downward
&
buf_
;
const
vector_downward
*
buf_
;
};
};
// For use with CreateSharedString. Instantiated on first use only.
// For use with CreateSharedString. Instantiated on first use only.
...
...
include/flatbuffers/idl.h
View file @
5e3f9d51
...
@@ -331,6 +331,7 @@ struct IDLOptions {
...
@@ -331,6 +331,7 @@ struct IDLOptions {
bool
proto_mode
;
bool
proto_mode
;
bool
generate_all
;
bool
generate_all
;
bool
skip_unexpected_fields_in_json
;
bool
skip_unexpected_fields_in_json
;
bool
generate_name_strings
;
// Possible options for the more general generator below.
// Possible options for the more general generator below.
enum
Language
{
kJava
,
kCSharp
,
kGo
,
kMAX
};
enum
Language
{
kJava
,
kCSharp
,
kGo
,
kMAX
};
...
@@ -349,6 +350,7 @@ struct IDLOptions {
...
@@ -349,6 +350,7 @@ struct IDLOptions {
proto_mode
(
false
),
proto_mode
(
false
),
generate_all
(
false
),
generate_all
(
false
),
skip_unexpected_fields_in_json
(
false
),
skip_unexpected_fields_in_json
(
false
),
generate_name_strings
(
false
),
lang
(
IDLOptions
::
kJava
)
{}
lang
(
IDLOptions
::
kJava
)
{}
};
};
...
...
php/Table.php
View file @
5e3f9d51
...
@@ -89,9 +89,15 @@ abstract class Table
...
@@ -89,9 +89,15 @@ abstract class Table
return
$offset
+
$this
->
bb
->
getInt
(
$offset
)
+
Constants
::
SIZEOF_INT
;
return
$offset
+
$this
->
bb
->
getInt
(
$offset
)
+
Constants
::
SIZEOF_INT
;
}
}
// protected function __vector_as_bytebuffer($vector_offset, $elem_size)
protected
function
__vector_as_bytes
(
$vector_offset
,
$elem_size
=
1
)
// {
{
// }
$o
=
$this
->
__offset
(
$vector_offset
);
if
(
$o
==
0
)
{
return
null
;
}
return
substr
(
$this
->
bb
->
_buffer
,
$this
->
__vector
(
$o
),
$this
->
__vector_len
(
$o
)
*
$elem_size
);
}
/**
/**
* @param Table $table
* @param Table $table
...
...
readme.md
View file @
5e3f9d51
...
@@ -47,7 +47,7 @@ you would leave it in.
...
@@ -47,7 +47,7 @@ you would leave it in.
[
CONTRIBUTING
]:
http://github.com/google/flatbuffers/blob/master/CONTRIBUTING
[
CONTRIBUTING
]:
http://github.com/google/flatbuffers/blob/master/CONTRIBUTING
[
`flatbuffers` tag
]:
https://stackoverflow.com/questions/tagged/flatbuffers
[
`flatbuffers` tag
]:
https://stackoverflow.com/questions/tagged/flatbuffers
[
FlatBuffers Google Group
]:
http
://group.google.com/group
/flatbuffers
[
FlatBuffers Google Group
]:
http
s://groups.google.com/forum/#!forum
/flatbuffers
[
FlatBuffers Issues Tracker
]:
http://github.com/google/flatbuffers/issues
[
FlatBuffers Issues Tracker
]:
http://github.com/google/flatbuffers/issues
[
stackoverflow.com
]:
http://www.stackoverflow.com
[
stackoverflow.com
]:
http://www.stackoverflow.com
[
landing page
]:
http://google.github.io/flatbuffers
[
landing page
]:
http://google.github.io/flatbuffers
...
...
src/flatc.cpp
View file @
5e3f9d51
...
@@ -117,6 +117,7 @@ static void Error(const std::string &err, bool usage, bool show_exe_name) {
...
@@ -117,6 +117,7 @@ static void Error(const std::string &err, bool usage, bool show_exe_name) {
" schemas the generated file depends on (C++).
\n
"
" schemas the generated file depends on (C++).
\n
"
" --gen-mutable Generate accessors that can mutate buffers in-place.
\n
"
" --gen-mutable Generate accessors that can mutate buffers in-place.
\n
"
" --gen-onefile Generate single output file for C#
\n
"
" --gen-onefile Generate single output file for C#
\n
"
" --gen-name-strings Generate type name functions for C++.
\n
"
" --raw-binary Allow binaries without file_indentifier to be read.
\n
"
" --raw-binary Allow binaries without file_indentifier to be read.
\n
"
" This may crash flatc given a mismatched schema.
\n
"
" This may crash flatc given a mismatched schema.
\n
"
" --proto Input is a .proto, translate to .fbs.
\n
"
" --proto Input is a .proto, translate to .fbs.
\n
"
...
@@ -171,6 +172,8 @@ int main(int argc, const char *argv[]) {
...
@@ -171,6 +172,8 @@ int main(int argc, const char *argv[]) {
opts
.
scoped_enums
=
true
;
opts
.
scoped_enums
=
true
;
}
else
if
(
arg
==
"--gen-mutable"
)
{
}
else
if
(
arg
==
"--gen-mutable"
)
{
opts
.
mutable_buffer
=
true
;
opts
.
mutable_buffer
=
true
;
}
else
if
(
arg
==
"--gen-name-strings"
)
{
opts
.
generate_name_strings
=
true
;
}
else
if
(
arg
==
"--gen-all"
)
{
}
else
if
(
arg
==
"--gen-all"
)
{
opts
.
generate_all
=
true
;
opts
.
generate_all
=
true
;
opts
.
include_dependence_headers
=
false
;
opts
.
include_dependence_headers
=
false
;
...
...
src/idl_gen_cpp.cpp
View file @
5e3f9d51
...
@@ -267,6 +267,14 @@ std::string GenFieldOffsetName(const FieldDef &field) {
...
@@ -267,6 +267,14 @@ std::string GenFieldOffsetName(const FieldDef &field) {
return
"VT_"
+
uname
;
return
"VT_"
+
uname
;
}
}
static
void
GenFullyQualifiedNameGetter
(
const
Parser
&
parser
,
const
std
::
string
&
name
,
std
::
string
&
code
)
{
if
(
parser
.
opts
.
generate_name_strings
)
{
code
+=
" static FLATBUFFERS_CONSTEXPR const char *GetFullyQualifiedName() {
\n
"
;
code
+=
" return
\"
"
+
parser
.
namespaces_
.
back
()
->
GetFullyQualifiedName
(
name
)
+
"
\"
;
\n
"
;
code
+=
" }
\n
"
;
}
}
// Generate an accessor struct, builder structs & function for a table.
// Generate an accessor struct, builder structs & function for a table.
static
void
GenTable
(
const
Parser
&
parser
,
StructDef
&
struct_def
,
static
void
GenTable
(
const
Parser
&
parser
,
StructDef
&
struct_def
,
std
::
string
*
code_ptr
)
{
std
::
string
*
code_ptr
)
{
...
@@ -277,6 +285,8 @@ static void GenTable(const Parser &parser, StructDef &struct_def,
...
@@ -277,6 +285,8 @@ static void GenTable(const Parser &parser, StructDef &struct_def,
code
+=
"struct "
+
struct_def
.
name
;
code
+=
"struct "
+
struct_def
.
name
;
code
+=
" FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table"
;
code
+=
" FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table"
;
code
+=
" {
\n
"
;
code
+=
" {
\n
"
;
// Generate GetFullyQualifiedName
GenFullyQualifiedNameGetter
(
parser
,
struct_def
.
name
,
code
);
// Generate field id constants.
// Generate field id constants.
if
(
struct_def
.
fields
.
vec
.
size
()
>
0
)
{
if
(
struct_def
.
fields
.
vec
.
size
()
>
0
)
{
code
+=
" enum {
\n
"
;
code
+=
" enum {
\n
"
;
...
@@ -583,8 +593,12 @@ static void GenStruct(const Parser &parser, StructDef &struct_def,
...
@@ -583,8 +593,12 @@ static void GenStruct(const Parser &parser, StructDef &struct_def,
GenPadding
(
field
,
code
,
padding_id
,
PaddingDefinition
);
GenPadding
(
field
,
code
,
padding_id
,
PaddingDefinition
);
}
}
// Generate GetFullyQualifiedName
code
+=
"
\n
public:
\n
"
;
GenFullyQualifiedNameGetter
(
parser
,
struct_def
.
name
,
code
);
// Generate a constructor that takes all fields as arguments.
// Generate a constructor that takes all fields as arguments.
code
+=
"
\n
public:
\n
"
+
struct_def
.
name
+
"("
;
code
+=
" "
+
struct_def
.
name
+
"("
;
for
(
auto
it
=
struct_def
.
fields
.
vec
.
begin
();
for
(
auto
it
=
struct_def
.
fields
.
vec
.
begin
();
it
!=
struct_def
.
fields
.
vec
.
end
();
it
!=
struct_def
.
fields
.
vec
.
end
();
++
it
)
{
++
it
)
{
...
...
src/idl_gen_php.cpp
View file @
5e3f9d51
...
@@ -165,6 +165,22 @@ namespace php {
...
@@ -165,6 +165,22 @@ namespace php {
code
+=
Indent
+
"}
\n\n
"
;
code
+=
Indent
+
"}
\n\n
"
;
}
}
// Get a [ubyte] vector as a byte array.
static
void
GetUByte
(
const
FieldDef
&
field
,
std
::
string
*
code_ptr
)
{
std
::
string
&
code
=
*
code_ptr
;
code
+=
Indent
+
"/**
\n
"
;
code
+=
Indent
+
" * @return string
\n
"
;
code
+=
Indent
+
" */
\n
"
;
code
+=
Indent
+
"public function get"
;
code
+=
MakeCamel
(
field
.
name
)
+
"Bytes()
\n
"
;
code
+=
Indent
+
"{
\n
"
;
code
+=
Indent
+
Indent
+
"return $this->__vector_as_bytes("
;
code
+=
NumToString
(
field
.
value
.
offset
)
+
");
\n
"
;
code
+=
Indent
+
"}
\n\n
"
;
}
// Get the value of a struct's scalar.
// Get the value of a struct's scalar.
static
void
GetScalarFieldOfStruct
(
const
FieldDef
&
field
,
static
void
GetScalarFieldOfStruct
(
const
FieldDef
&
field
,
std
::
string
*
code_ptr
)
{
std
::
string
*
code_ptr
)
{
...
@@ -690,6 +706,9 @@ namespace php {
...
@@ -690,6 +706,9 @@ namespace php {
}
}
if
(
field
.
value
.
type
.
base_type
==
BASE_TYPE_VECTOR
)
{
if
(
field
.
value
.
type
.
base_type
==
BASE_TYPE_VECTOR
)
{
GetVectorLen
(
field
,
code_ptr
);
GetVectorLen
(
field
,
code_ptr
);
if
(
field
.
value
.
type
.
element
==
BASE_TYPE_UCHAR
)
{
GetUByte
(
field
,
code_ptr
);
}
}
}
}
}
...
...
tests/MyGame/Example/Monster.php
View file @
5e3f9d51
...
@@ -98,6 +98,14 @@ class Monster extends Table
...
@@ -98,6 +98,14 @@ class Monster extends Table
return
$o
!=
0
?
$this
->
__vector_len
(
$o
)
:
0
;
return
$o
!=
0
?
$this
->
__vector_len
(
$o
)
:
0
;
}
}
/**
* @return string
*/
public
function
getInventoryBytes
()
{
return
$this
->
__vector_as_bytes
(
14
);
}
/**
/**
* @return sbyte
* @return sbyte
*/
*/
...
@@ -210,6 +218,14 @@ class Monster extends Table
...
@@ -210,6 +218,14 @@ class Monster extends Table
return
$o
!=
0
?
$this
->
__vector_len
(
$o
)
:
0
;
return
$o
!=
0
?
$this
->
__vector_len
(
$o
)
:
0
;
}
}
/**
* @return string
*/
public
function
getTestnestedflatbufferBytes
()
{
return
$this
->
__vector_as_bytes
(
30
);
}
public
function
getTestempty
()
public
function
getTestempty
()
{
{
$obj
=
new
Stat
();
$obj
=
new
Stat
();
...
...
tests/phpTest.php
View file @
5e3f9d51
...
@@ -128,6 +128,7 @@ function test_buffer(Assert $assert, Google\FlatBuffers\ByteBuffer $bb) {
...
@@ -128,6 +128,7 @@ function test_buffer(Assert $assert, Google\FlatBuffers\ByteBuffer $bb) {
}
}
$assert
->
strictEqual
(
$invsum
,
10
);
$assert
->
strictEqual
(
$invsum
,
10
);
$assert
->
strictEqual
(
bin2hex
(
$monster
->
GetInventoryBytes
()),
"0001020304"
);
$test_0
=
$monster
->
GetTest4
(
0
);
$test_0
=
$monster
->
GetTest4
(
0
);
$test_1
=
$monster
->
GetTest4
(
1
);
$test_1
=
$monster
->
GetTest4
(
1
);
...
...
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