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
6bfcb286
Commit
6bfcb286
authored
Dec 22, 2015
by
ncpenke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1 from google/master
Catchup
parents
b974e95c
18915372
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
532 additions
and
53 deletions
+532
-53
CMakeLists.txt
CMakeLists.txt
+1
-1
flatbuffers.h
include/flatbuffers/flatbuffers.h
+12
-0
idl.h
include/flatbuffers/idl.h
+78
-31
idl_parser.cpp
src/idl_parser.cpp
+0
-0
reflection.cpp
src/reflection.cpp
+6
-3
generate_code.bat
tests/generate_code.bat
+17
-2
generate_code.sh
tests/generate_code.sh
+18
-0
EnumInNestedNS.py
tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.py
+9
-0
StructInNestedNS.cs
.../namespace_test/NamespaceA/NamespaceB/StructInNestedNS.cs
+1
-0
StructInNestedNS.py
.../namespace_test/NamespaceA/NamespaceB/StructInNestedNS.py
+23
-0
TableInNestedNS.cs
...s/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.cs
+1
-0
TableInNestedNS.py
...s/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.py
+23
-0
__init__.py
tests/namespace_test/NamespaceA/NamespaceB/__init__.py
+0
-0
TableInFirstNS.cs
tests/namespace_test/NamespaceA/TableInFirstNS.cs
+1
-0
TableInFirstNS.py
tests/namespace_test/NamespaceA/TableInFirstNS.py
+47
-0
__init__.py
tests/namespace_test/NamespaceA/__init__.py
+0
-0
namespace_test1_generated.h
tests/namespace_test/namespace_test1_generated.h
+7
-4
namespace_test1_generated.js
tests/namespace_test/namespace_test1_generated.js
+143
-0
namespace_test2_generated.h
tests/namespace_test/namespace_test2_generated.h
+19
-12
namespace_test2_generated.js
tests/namespace_test/namespace_test2_generated.js
+115
-0
test.cpp
tests/test.cpp
+11
-0
No files found.
CMakeLists.txt
View file @
6bfcb286
...
...
@@ -81,7 +81,7 @@ if(APPLE)
"
${
CMAKE_CXX_FLAGS
}
-std=c++11 -stdlib=libc++ -Wall -pedantic -Werror -Wextra"
)
elseif
(
CMAKE_COMPILER_IS_GNUCXX
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-std=c++0x -Wall -pedantic -Werror -Wextra -Werror=shadow"
)
"
${
CMAKE_CXX_FLAGS
}
-std=c++0x -Wall -pedantic -Werror -Wextra -Werror=shadow
-Wunused-result -Werror=unused-result
"
)
elseif
(
"
${
CMAKE_CXX_COMPILER_ID
}
"
MATCHES
"Clang"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-std=c++0x -stdlib=libc++ -Wall -pedantic -Werror -Wextra"
)
...
...
include/flatbuffers/flatbuffers.h
View file @
6bfcb286
...
...
@@ -1187,6 +1187,18 @@ class Table {
uint8_t
data_
[
1
];
};
// Helper function to test if a field is present, using any of the field
// enums in the generated code.
// `table` must be a generated table type. Since this is a template parameter,
// this is not typechecked to be a subclass of Table, so beware!
// Note: this function will return false for fields equal to the default
// value, since they're not stored in the buffer (unless force_defaults was
// used).
template
<
typename
T
>
bool
IsFieldPresent
(
const
T
*
table
,
voffset_t
field
)
{
// Cast, since Table is a private baseclass of any table types.
return
reinterpret_cast
<
const
Table
*>
(
table
)
->
CheckField
(
field
);
}
// Utility function for reverse lookups on the EnumNames*() functions
// (in the generated C++ code)
// names must be NULL terminated.
...
...
include/flatbuffers/idl.h
View file @
6bfcb286
...
...
@@ -340,6 +340,46 @@ struct IDLOptions {
lang
(
IDLOptions
::
kJava
)
{}
};
// A way to make error propagation less error prone by requiring values to be
// checked.
// Once you create a value of this type you must either:
// - Call Check() on it.
// - Copy or assign it to another value.
// Failure to do so leads to an assert.
// This guarantees that this as return value cannot be ignored.
class
CheckedError
{
public
:
explicit
CheckedError
(
bool
error
)
:
is_error_
(
error
),
has_been_checked_
(
false
)
{}
CheckedError
&
operator
=
(
const
CheckedError
&
other
)
{
is_error_
=
other
.
is_error_
;
has_been_checked_
=
false
;
other
.
has_been_checked_
=
true
;
return
*
this
;
}
CheckedError
(
const
CheckedError
&
other
)
{
*
this
=
other
;
// Use assignment operator.
}
~
CheckedError
()
{
assert
(
has_been_checked_
);
}
bool
Check
()
{
has_been_checked_
=
true
;
return
is_error_
;
}
private
:
bool
is_error_
;
mutable
bool
has_been_checked_
;
};
// Additionally, in GCC we can get these errors statically, for additional
// assurance:
#ifdef __GNUC__
#define CHECKED_ERROR CheckedError __attribute__((warn_unused_result))
#else
#define CHECKED_ERROR CheckedError
#endif
class
Parser
{
public
:
explicit
Parser
(
const
IDLOptions
&
options
=
IDLOptions
())
...
...
@@ -395,44 +435,51 @@ class Parser {
// See reflection/reflection.fbs
void
Serialize
();
private
:
int64_t
ParseHexNum
(
int
nibbles
);
void
Next
();
bool
IsNext
(
int
t
);
void
Expect
(
int
t
);
CHECKED_ERROR
CheckBitsFit
(
int64_t
val
,
size_t
bits
);
private
:
CHECKED_ERROR
Error
(
const
std
::
string
&
msg
);
CHECKED_ERROR
ParseHexNum
(
int
nibbles
,
int64_t
*
val
);
CHECKED_ERROR
Next
();
bool
Is
(
int
t
);
CHECKED_ERROR
Expect
(
int
t
);
std
::
string
TokenToStringId
(
int
t
);
EnumDef
*
LookupEnum
(
const
std
::
string
&
id
);
void
ParseNamespacing
(
std
::
string
*
id
,
std
::
string
*
last
);
void
ParseTypeIdent
(
Type
&
type
);
void
ParseType
(
Type
&
type
);
FieldDef
&
AddField
(
StructDef
&
struct_def
,
const
std
::
string
&
name
,
const
Type
&
type
);
void
ParseField
(
StructDef
&
struct_def
);
void
ParseAnyValue
(
Value
&
val
,
FieldDef
*
field
,
size_t
parent_fieldn
);
uoffset_t
ParseTable
(
const
StructDef
&
struct_def
,
std
::
string
*
value
);
CHECKED_ERROR
ParseNamespacing
(
std
::
string
*
id
,
std
::
string
*
last
);
CHECKED_ERROR
ParseTypeIdent
(
Type
&
type
);
CHECKED_ERROR
ParseType
(
Type
&
type
);
CHECKED_ERROR
AddField
(
StructDef
&
struct_def
,
const
std
::
string
&
name
,
const
Type
&
type
,
FieldDef
**
dest
);
CHECKED_ERROR
ParseField
(
StructDef
&
struct_def
);
CHECKED_ERROR
ParseAnyValue
(
Value
&
val
,
FieldDef
*
field
,
size_t
parent_fieldn
);
CHECKED_ERROR
ParseTable
(
const
StructDef
&
struct_def
,
std
::
string
*
value
,
uoffset_t
*
o
value
);
void
SerializeStruct
(
const
StructDef
&
struct_def
,
const
Value
&
val
);
void
AddVector
(
bool
sortbysize
,
int
count
);
uoffset_t
ParseVector
(
const
Type
&
type
);
void
ParseMetaData
(
Definition
&
def
);
bool
TryTypedValue
(
int
dtoken
,
bool
check
,
Value
&
e
,
BaseType
req
);
void
ParseHash
(
Value
&
e
,
FieldDef
*
field
);
void
ParseSingleValue
(
Value
&
e
);
int64_t
ParseIntegerFromString
(
Type
&
type
);
CHECKED_ERROR
ParseVector
(
const
Type
&
type
,
uoffset_t
*
ovalue
);
CHECKED_ERROR
ParseMetaData
(
Definition
&
def
);
CHECKED_ERROR
TryTypedValue
(
int
dtoken
,
bool
check
,
Value
&
e
,
BaseType
req
,
bool
*
destmatch
);
CHECKED_ERROR
ParseHash
(
Value
&
e
,
FieldDef
*
field
);
CHECKED_ERROR
ParseSingleValue
(
Value
&
e
);
CHECKED_ERROR
ParseIntegerFromString
(
Type
&
type
,
int64_t
*
result
);
StructDef
*
LookupCreateStruct
(
const
std
::
string
&
name
,
bool
create_if_new
=
true
,
bool
definition
=
false
);
EnumDef
&
ParseEnum
(
bool
is_union
);
void
ParseNamespace
();
StructDef
&
StartStruct
(
const
std
::
string
&
name
);
void
ParseDecl
();
void
ParseProtoFields
(
StructDef
*
struct_def
,
bool
isextend
,
CHECKED_ERROR
ParseEnum
(
bool
is_union
,
EnumDef
**
dest
);
CHECKED_ERROR
ParseNamespace
();
CHECKED_ERROR
StartStruct
(
const
std
::
string
&
name
,
StructDef
**
dest
);
CHECKED_ERROR
ParseDecl
();
CHECKED_ERROR
ParseProtoFields
(
StructDef
*
struct_def
,
bool
isextend
,
bool
inside_oneof
);
void
ParseProtoOption
();
void
ParseProtoKey
();
void
ParseProtoDecl
();
void
ParseProtoCurliesOrIdent
();
Type
ParseTypeFromProtoType
();
CHECKED_ERROR
ParseProtoOption
();
CHECKED_ERROR
ParseProtoKey
();
CHECKED_ERROR
ParseProtoDecl
();
CHECKED_ERROR
ParseProtoCurliesOrIdent
();
CHECKED_ERROR
ParseTypeFromProtoType
(
Type
*
type
);
CHECKED_ERROR
DoParse
(
const
char
*
_source
,
const
char
**
include_paths
,
const
char
*
source_filename
);
public
:
SymbolTable
<
StructDef
>
structs_
;
...
...
@@ -454,7 +501,7 @@ class Parser {
const
char
*
source_
,
*
cursor_
;
int
line_
;
// the current line being parsed
int
token_
;
std
::
string
file
s
_being_parsed_
;
std
::
string
file_being_parsed_
;
std
::
string
attribute_
;
std
::
vector
<
std
::
string
>
doc_comment_
;
...
...
src/idl_parser.cpp
View file @
6bfcb286
This diff is collapsed.
Click to expand it.
src/reflection.cpp
View file @
6bfcb286
...
...
@@ -287,14 +287,17 @@ void SetString(const reflection::Schema &schema, const std::string &val,
const
String
*
str
,
std
::
vector
<
uint8_t
>
*
flatbuf
,
const
reflection
::
Object
*
root_table
)
{
auto
delta
=
static_cast
<
int
>
(
val
.
size
())
-
static_cast
<
int
>
(
str
->
Length
());
auto
st
art
=
static_cast
<
uoffset_t
>
(
reinterpret_cast
<
const
uint8_t
*>
(
str
)
-
flatbuf
->
data
()
+
sizeof
(
uoffset_t
)
);
auto
st
r_start
=
static_cast
<
uoffset_t
>
(
reinterpret_cast
<
const
uint8_t
*>
(
str
)
-
flatbuf
->
data
());
auto
start
=
str_start
+
sizeof
(
uoffset_t
);
if
(
delta
)
{
// Clear the old string, since we don't want parts of it remaining.
memset
(
flatbuf
->
data
()
+
start
,
0
,
str
->
Length
());
// Different size, we must expand (or contract).
ResizeContext
(
schema
,
start
,
delta
,
flatbuf
,
root_table
);
// Set the new length.
WriteScalar
(
flatbuf
->
data
()
+
str_start
,
static_cast
<
uoffset_t
>
(
val
.
size
()));
}
// Copy new data. Safe because we created the right amount of space.
memcpy
(
flatbuf
->
data
()
+
start
,
val
.
c_str
(),
val
.
size
()
+
1
);
...
...
tests/generate_code.bat
View file @
6bfcb286
..\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
:: Copyright 2015 Google Inc. All rights reserved.
::
:: Licensed under the Apache License, Version 2.0 (the "License");
:: you may not use this file except in compliance with the License.
:: You may obtain a copy of the License at
::
:: http://www.apache.org/licenses/LICENSE-2.0
::
:: Unless required by applicable law or agreed to in writing, software
:: distributed under the License is distributed on an "AS IS" BASIS,
:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
:: See the License for the specific language governing permissions and
:: limitations under the License.
..\flatc.exe --cpp --java --csharp --go --binary --python --js --php --gen-mutable --no-includes monster_test.fbs monsterdata_test.json
..\flatc.exe --cpp --java --csharp --go --binary --python --js --php --gen-mutable -o namespace_test namespace_test\namespace_test1.fbs namespace_test\namespace_test2.fbs
..\flatc.exe --binary --schema monster_test.fbs
tests/generate_code.sh
View file @
6bfcb286
#!/bin/bash
# Copyright 2015 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
../flatc
--cpp
--java
--csharp
--go
--binary
--python
--js
--php
--gen-mutable
--no-includes
monster_test.fbs monsterdata_test.json
../flatc
--cpp
--java
--csharp
--go
--binary
--python
--js
--php
--gen-mutable
-o
namespace_test namespace_test/namespace_test1.fbs namespace_test/namespace_test2.fbs
../flatc
--binary
--schema
monster_test.fbs
tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.py
0 → 100644
View file @
6bfcb286
# automatically generated, do not modify
# namespace: NamespaceB
class
EnumInNestedNS
(
object
):
A
=
0
B
=
1
C
=
2
tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.cs
View file @
6bfcb286
...
...
@@ -3,6 +3,7 @@
namespace
NamespaceA.NamespaceB
{
using
System
;
using
FlatBuffers
;
public
sealed
class
StructInNestedNS
:
Struct
{
...
...
tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.py
0 → 100644
View file @
6bfcb286
# automatically generated, do not modify
# namespace: NamespaceB
import
flatbuffers
class
StructInNestedNS
(
object
):
__slots__
=
[
'_tab'
]
# StructInNestedNS
def
Init
(
self
,
buf
,
pos
):
self
.
_tab
=
flatbuffers
.
table
.
Table
(
buf
,
pos
)
# StructInNestedNS
def
A
(
self
):
return
self
.
_tab
.
Get
(
flatbuffers
.
number_types
.
Int32Flags
,
self
.
_tab
.
Pos
+
flatbuffers
.
number_types
.
UOffsetTFlags
.
py_type
(
0
))
# StructInNestedNS
def
B
(
self
):
return
self
.
_tab
.
Get
(
flatbuffers
.
number_types
.
Int32Flags
,
self
.
_tab
.
Pos
+
flatbuffers
.
number_types
.
UOffsetTFlags
.
py_type
(
4
))
def
CreateStructInNestedNS
(
builder
,
a
,
b
):
builder
.
Prep
(
4
,
8
)
builder
.
PrependInt32
(
b
)
builder
.
PrependInt32
(
a
)
return
builder
.
Offset
()
tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.cs
View file @
6bfcb286
...
...
@@ -3,6 +3,7 @@
namespace
NamespaceA.NamespaceB
{
using
System
;
using
FlatBuffers
;
public
sealed
class
TableInNestedNS
:
Table
{
...
...
tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.py
0 → 100644
View file @
6bfcb286
# automatically generated, do not modify
# namespace: NamespaceB
import
flatbuffers
class
TableInNestedNS
(
object
):
__slots__
=
[
'_tab'
]
# TableInNestedNS
def
Init
(
self
,
buf
,
pos
):
self
.
_tab
=
flatbuffers
.
table
.
Table
(
buf
,
pos
)
# TableInNestedNS
def
Foo
(
self
):
o
=
flatbuffers
.
number_types
.
UOffsetTFlags
.
py_type
(
self
.
_tab
.
Offset
(
4
))
if
o
!=
0
:
return
self
.
_tab
.
Get
(
flatbuffers
.
number_types
.
Int32Flags
,
o
+
self
.
_tab
.
Pos
)
return
0
def
TableInNestedNSStart
(
builder
):
builder
.
StartObject
(
1
)
def
TableInNestedNSAddFoo
(
builder
,
foo
):
builder
.
PrependInt32Slot
(
0
,
foo
,
0
)
def
TableInNestedNSEnd
(
builder
):
return
builder
.
EndObject
()
tests/namespace_test/NamespaceA/NamespaceB/__init__.py
0 → 100644
View file @
6bfcb286
tests/namespace_test/NamespaceA/TableInFirstNS.cs
View file @
6bfcb286
...
...
@@ -3,6 +3,7 @@
namespace
NamespaceA
{
using
System
;
using
FlatBuffers
;
public
sealed
class
TableInFirstNS
:
Table
{
...
...
tests/namespace_test/NamespaceA/TableInFirstNS.py
0 → 100644
View file @
6bfcb286
# automatically generated, do not modify
# namespace: NamespaceA
import
flatbuffers
class
TableInFirstNS
(
object
):
__slots__
=
[
'_tab'
]
# TableInFirstNS
def
Init
(
self
,
buf
,
pos
):
self
.
_tab
=
flatbuffers
.
table
.
Table
(
buf
,
pos
)
# TableInFirstNS
def
FooTable
(
self
):
o
=
flatbuffers
.
number_types
.
UOffsetTFlags
.
py_type
(
self
.
_tab
.
Offset
(
4
))
if
o
!=
0
:
x
=
self
.
_tab
.
Indirect
(
o
+
self
.
_tab
.
Pos
)
from
.TableInNestedNS
import
TableInNestedNS
obj
=
TableInNestedNS
()
obj
.
Init
(
self
.
_tab
.
Bytes
,
x
)
return
obj
return
None
# TableInFirstNS
def
FooEnum
(
self
):
o
=
flatbuffers
.
number_types
.
UOffsetTFlags
.
py_type
(
self
.
_tab
.
Offset
(
6
))
if
o
!=
0
:
return
self
.
_tab
.
Get
(
flatbuffers
.
number_types
.
Int8Flags
,
o
+
self
.
_tab
.
Pos
)
return
0
# TableInFirstNS
def
FooStruct
(
self
):
o
=
flatbuffers
.
number_types
.
UOffsetTFlags
.
py_type
(
self
.
_tab
.
Offset
(
8
))
if
o
!=
0
:
x
=
o
+
self
.
_tab
.
Pos
from
.StructInNestedNS
import
StructInNestedNS
obj
=
StructInNestedNS
()
obj
.
Init
(
self
.
_tab
.
Bytes
,
x
)
return
obj
return
None
def
TableInFirstNSStart
(
builder
):
builder
.
StartObject
(
3
)
def
TableInFirstNSAddFooTable
(
builder
,
fooTable
):
builder
.
PrependUOffsetTRelativeSlot
(
0
,
flatbuffers
.
number_types
.
UOffsetTFlags
.
py_type
(
fooTable
),
0
)
def
TableInFirstNSAddFooEnum
(
builder
,
fooEnum
):
builder
.
PrependInt8Slot
(
1
,
fooEnum
,
0
)
def
TableInFirstNSAddFooStruct
(
builder
,
fooStruct
):
builder
.
PrependStructSlot
(
2
,
flatbuffers
.
number_types
.
UOffsetTFlags
.
py_type
(
fooStruct
),
0
)
def
TableInFirstNSEnd
(
builder
):
return
builder
.
EndObject
()
tests/namespace_test/NamespaceA/__init__.py
0 → 100644
View file @
6bfcb286
tests/namespace_test/namespace_test1_generated.h
View file @
6bfcb286
...
...
@@ -42,11 +42,14 @@ MANUALLY_ALIGNED_STRUCT(4) StructInNestedNS FLATBUFFERS_FINAL_CLASS {
STRUCT_END
(
StructInNestedNS
,
8
);
struct
TableInNestedNS
FLATBUFFERS_FINAL_CLASS
:
private
flatbuffers
::
Table
{
int32_t
foo
()
const
{
return
GetField
<
int32_t
>
(
4
,
0
);
}
bool
mutate_foo
(
int32_t
_foo
)
{
return
SetField
(
4
,
_foo
);
}
enum
{
VT_FOO
=
4
,
};
int32_t
foo
()
const
{
return
GetField
<
int32_t
>
(
VT_FOO
,
0
);
}
bool
mutate_foo
(
int32_t
_foo
)
{
return
SetField
(
VT_FOO
,
_foo
);
}
bool
Verify
(
flatbuffers
::
Verifier
&
verifier
)
const
{
return
VerifyTableStart
(
verifier
)
&&
VerifyField
<
int32_t
>
(
verifier
,
4
/* foo */
)
&&
VerifyField
<
int32_t
>
(
verifier
,
VT_FOO
)
&&
verifier
.
EndTable
();
}
};
...
...
@@ -54,7 +57,7 @@ struct TableInNestedNS FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
struct
TableInNestedNSBuilder
{
flatbuffers
::
FlatBufferBuilder
&
fbb_
;
flatbuffers
::
uoffset_t
start_
;
void
add_foo
(
int32_t
foo
)
{
fbb_
.
AddElement
<
int32_t
>
(
4
,
foo
,
0
);
}
void
add_foo
(
int32_t
foo
)
{
fbb_
.
AddElement
<
int32_t
>
(
TableInNestedNS
::
VT_FOO
,
foo
,
0
);
}
TableInNestedNSBuilder
(
flatbuffers
::
FlatBufferBuilder
&
_fbb
)
:
fbb_
(
_fbb
)
{
start_
=
fbb_
.
StartTable
();
}
TableInNestedNSBuilder
&
operator
=
(
const
TableInNestedNSBuilder
&
);
flatbuffers
::
Offset
<
TableInNestedNS
>
Finish
()
{
...
...
tests/namespace_test/namespace_test1_generated.js
0 → 100644
View file @
6bfcb286
// automatically generated by the FlatBuffers compiler, do not modify
/**
* @const
*/
var
NamespaceA
=
NamespaceA
||
{};
/**
* @const
*/
NamespaceA
.
NamespaceB
=
NamespaceA
.
NamespaceB
||
{};
/**
* @enum
*/
NamespaceA
.
NamespaceB
.
EnumInNestedNS
=
{
A
:
0
,
B
:
1
,
C
:
2
};
/**
* @constructor
*/
NamespaceA
.
NamespaceB
.
TableInNestedNS
=
function
()
{
/**
* @type {flatbuffers.ByteBuffer}
*/
this
.
bb
=
null
;
/**
* @type {number}
*/
this
.
bb_pos
=
0
;
};
/**
* @param {number} i
* @param {flatbuffers.ByteBuffer} bb
* @returns {NamespaceA.NamespaceB.TableInNestedNS}
*/
NamespaceA
.
NamespaceB
.
TableInNestedNS
.
prototype
.
__init
=
function
(
i
,
bb
)
{
this
.
bb_pos
=
i
;
this
.
bb
=
bb
;
return
this
;
};
/**
* @param {flatbuffers.ByteBuffer} bb
* @param {NamespaceA.NamespaceB.TableInNestedNS=} obj
* @returns {NamespaceA.NamespaceB.TableInNestedNS}
*/
NamespaceA
.
NamespaceB
.
TableInNestedNS
.
getRootAsTableInNestedNS
=
function
(
bb
,
obj
)
{
return
(
obj
||
new
NamespaceA
.
NamespaceB
.
TableInNestedNS
).
__init
(
bb
.
readInt32
(
bb
.
position
())
+
bb
.
position
(),
bb
);
};
/**
* @returns {number}
*/
NamespaceA
.
NamespaceB
.
TableInNestedNS
.
prototype
.
foo
=
function
()
{
var
offset
=
this
.
bb
.
__offset
(
this
.
bb_pos
,
4
);
return
offset
?
this
.
bb
.
readInt32
(
this
.
bb_pos
+
offset
)
:
0
;
};
/**
* @param {flatbuffers.Builder} builder
*/
NamespaceA
.
NamespaceB
.
TableInNestedNS
.
startTableInNestedNS
=
function
(
builder
)
{
builder
.
startObject
(
1
);
};
/**
* @param {flatbuffers.Builder} builder
* @param {number} foo
*/
NamespaceA
.
NamespaceB
.
TableInNestedNS
.
addFoo
=
function
(
builder
,
foo
)
{
builder
.
addFieldInt32
(
0
,
foo
,
0
);
};
/**
* @param {flatbuffers.Builder} builder
* @returns {flatbuffers.Offset}
*/
NamespaceA
.
NamespaceB
.
TableInNestedNS
.
endTableInNestedNS
=
function
(
builder
)
{
var
offset
=
builder
.
endObject
();
return
offset
;
};
/**
* @constructor
*/
NamespaceA
.
NamespaceB
.
StructInNestedNS
=
function
()
{
/**
* @type {flatbuffers.ByteBuffer}
*/
this
.
bb
=
null
;
/**
* @type {number}
*/
this
.
bb_pos
=
0
;
};
/**
* @param {number} i
* @param {flatbuffers.ByteBuffer} bb
* @returns {NamespaceA.NamespaceB.StructInNestedNS}
*/
NamespaceA
.
NamespaceB
.
StructInNestedNS
.
prototype
.
__init
=
function
(
i
,
bb
)
{
this
.
bb_pos
=
i
;
this
.
bb
=
bb
;
return
this
;
};
/**
* @returns {number}
*/
NamespaceA
.
NamespaceB
.
StructInNestedNS
.
prototype
.
a
=
function
()
{
return
this
.
bb
.
readInt32
(
this
.
bb_pos
);
};
/**
* @returns {number}
*/
NamespaceA
.
NamespaceB
.
StructInNestedNS
.
prototype
.
b
=
function
()
{
return
this
.
bb
.
readInt32
(
this
.
bb_pos
+
4
);
};
/**
* @param {flatbuffers.Builder} builder
* @param {number} a
* @param {number} b
* @returns {flatbuffers.Offset}
*/
NamespaceA
.
NamespaceB
.
StructInNestedNS
.
createStructInNestedNS
=
function
(
builder
,
a
,
b
)
{
builder
.
prep
(
4
,
8
);
builder
.
writeInt32
(
b
);
builder
.
writeInt32
(
a
);
return
builder
.
offset
();
};
// Exports for Node.js and RequireJS
this
.
NamespaceA
=
NamespaceA
;
tests/namespace_test/namespace_test2_generated.h
View file @
6bfcb286
...
...
@@ -5,6 +5,8 @@
#include "flatbuffers/flatbuffers.h"
#include "namespace_test1_generated.h"
namespace
NamespaceA
{
namespace
NamespaceB
{
struct
TableInNestedNS
;
...
...
@@ -17,18 +19,23 @@ namespace NamespaceA {
struct
TableInFirstNS
;
struct
TableInFirstNS
FLATBUFFERS_FINAL_CLASS
:
private
flatbuffers
::
Table
{
const
NamespaceA
::
NamespaceB
::
TableInNestedNS
*
foo_table
()
const
{
return
GetPointer
<
const
NamespaceA
::
NamespaceB
::
TableInNestedNS
*>
(
4
);
}
NamespaceA
::
NamespaceB
::
TableInNestedNS
*
mutable_foo_table
()
{
return
GetPointer
<
NamespaceA
::
NamespaceB
::
TableInNestedNS
*>
(
4
);
}
NamespaceA
::
NamespaceB
::
EnumInNestedNS
foo_enum
()
const
{
return
static_cast
<
NamespaceA
::
NamespaceB
::
EnumInNestedNS
>
(
GetField
<
int8_t
>
(
6
,
0
));
}
bool
mutate_foo_enum
(
NamespaceA
::
NamespaceB
::
EnumInNestedNS
_foo_enum
)
{
return
SetField
(
6
,
static_cast
<
int8_t
>
(
_foo_enum
));
}
const
NamespaceA
::
NamespaceB
::
StructInNestedNS
*
foo_struct
()
const
{
return
GetStruct
<
const
NamespaceA
::
NamespaceB
::
StructInNestedNS
*>
(
8
);
}
NamespaceA
::
NamespaceB
::
StructInNestedNS
*
mutable_foo_struct
()
{
return
GetStruct
<
NamespaceA
::
NamespaceB
::
StructInNestedNS
*>
(
8
);
}
enum
{
VT_FOO_TABLE
=
4
,
VT_FOO_ENUM
=
6
,
VT_FOO_STRUCT
=
8
,
};
const
NamespaceA
::
NamespaceB
::
TableInNestedNS
*
foo_table
()
const
{
return
GetPointer
<
const
NamespaceA
::
NamespaceB
::
TableInNestedNS
*>
(
VT_FOO_TABLE
);
}
NamespaceA
::
NamespaceB
::
TableInNestedNS
*
mutable_foo_table
()
{
return
GetPointer
<
NamespaceA
::
NamespaceB
::
TableInNestedNS
*>
(
VT_FOO_TABLE
);
}
NamespaceA
::
NamespaceB
::
EnumInNestedNS
foo_enum
()
const
{
return
static_cast
<
NamespaceA
::
NamespaceB
::
EnumInNestedNS
>
(
GetField
<
int8_t
>
(
VT_FOO_ENUM
,
0
));
}
bool
mutate_foo_enum
(
NamespaceA
::
NamespaceB
::
EnumInNestedNS
_foo_enum
)
{
return
SetField
(
VT_FOO_ENUM
,
static_cast
<
int8_t
>
(
_foo_enum
));
}
const
NamespaceA
::
NamespaceB
::
StructInNestedNS
*
foo_struct
()
const
{
return
GetStruct
<
const
NamespaceA
::
NamespaceB
::
StructInNestedNS
*>
(
VT_FOO_STRUCT
);
}
NamespaceA
::
NamespaceB
::
StructInNestedNS
*
mutable_foo_struct
()
{
return
GetStruct
<
NamespaceA
::
NamespaceB
::
StructInNestedNS
*>
(
VT_FOO_STRUCT
);
}
bool
Verify
(
flatbuffers
::
Verifier
&
verifier
)
const
{
return
VerifyTableStart
(
verifier
)
&&
VerifyField
<
flatbuffers
::
uoffset_t
>
(
verifier
,
4
/* foo_table */
)
&&
VerifyField
<
flatbuffers
::
uoffset_t
>
(
verifier
,
VT_FOO_TABLE
)
&&
verifier
.
VerifyTable
(
foo_table
())
&&
VerifyField
<
int8_t
>
(
verifier
,
6
/* foo_enum */
)
&&
VerifyField
<
NamespaceA
::
NamespaceB
::
StructInNestedNS
>
(
verifier
,
8
/* foo_struct */
)
&&
VerifyField
<
int8_t
>
(
verifier
,
VT_FOO_ENUM
)
&&
VerifyField
<
NamespaceA
::
NamespaceB
::
StructInNestedNS
>
(
verifier
,
VT_FOO_STRUCT
)
&&
verifier
.
EndTable
();
}
};
...
...
@@ -36,9 +43,9 @@ struct TableInFirstNS FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
struct
TableInFirstNSBuilder
{
flatbuffers
::
FlatBufferBuilder
&
fbb_
;
flatbuffers
::
uoffset_t
start_
;
void
add_foo_table
(
flatbuffers
::
Offset
<
NamespaceA
::
NamespaceB
::
TableInNestedNS
>
foo_table
)
{
fbb_
.
AddOffset
(
4
,
foo_table
);
}
void
add_foo_enum
(
NamespaceA
::
NamespaceB
::
EnumInNestedNS
foo_enum
)
{
fbb_
.
AddElement
<
int8_t
>
(
6
,
static_cast
<
int8_t
>
(
foo_enum
),
0
);
}
void
add_foo_struct
(
const
NamespaceA
::
NamespaceB
::
StructInNestedNS
*
foo_struct
)
{
fbb_
.
AddStruct
(
8
,
foo_struct
);
}
void
add_foo_table
(
flatbuffers
::
Offset
<
NamespaceA
::
NamespaceB
::
TableInNestedNS
>
foo_table
)
{
fbb_
.
AddOffset
(
TableInFirstNS
::
VT_FOO_TABLE
,
foo_table
);
}
void
add_foo_enum
(
NamespaceA
::
NamespaceB
::
EnumInNestedNS
foo_enum
)
{
fbb_
.
AddElement
<
int8_t
>
(
TableInFirstNS
::
VT_FOO_ENUM
,
static_cast
<
int8_t
>
(
foo_enum
),
0
);
}
void
add_foo_struct
(
const
NamespaceA
::
NamespaceB
::
StructInNestedNS
*
foo_struct
)
{
fbb_
.
AddStruct
(
TableInFirstNS
::
VT_FOO_STRUCT
,
foo_struct
);
}
TableInFirstNSBuilder
(
flatbuffers
::
FlatBufferBuilder
&
_fbb
)
:
fbb_
(
_fbb
)
{
start_
=
fbb_
.
StartTable
();
}
TableInFirstNSBuilder
&
operator
=
(
const
TableInFirstNSBuilder
&
);
flatbuffers
::
Offset
<
TableInFirstNS
>
Finish
()
{
...
...
tests/namespace_test/namespace_test2_generated.js
0 → 100644
View file @
6bfcb286
// automatically generated by the FlatBuffers compiler, do not modify
/**
* @const
*/
var
NamespaceA
=
NamespaceA
||
{};
/**
* @const
*/
NamespaceA
.
NamespaceB
=
NamespaceA
.
NamespaceB
||
{};
/**
* @constructor
*/
NamespaceA
.
TableInFirstNS
=
function
()
{
/**
* @type {flatbuffers.ByteBuffer}
*/
this
.
bb
=
null
;
/**
* @type {number}
*/
this
.
bb_pos
=
0
;
};
/**
* @param {number} i
* @param {flatbuffers.ByteBuffer} bb
* @returns {NamespaceA.TableInFirstNS}
*/
NamespaceA
.
TableInFirstNS
.
prototype
.
__init
=
function
(
i
,
bb
)
{
this
.
bb_pos
=
i
;
this
.
bb
=
bb
;
return
this
;
};
/**
* @param {flatbuffers.ByteBuffer} bb
* @param {NamespaceA.TableInFirstNS=} obj
* @returns {NamespaceA.TableInFirstNS}
*/
NamespaceA
.
TableInFirstNS
.
getRootAsTableInFirstNS
=
function
(
bb
,
obj
)
{
return
(
obj
||
new
NamespaceA
.
TableInFirstNS
).
__init
(
bb
.
readInt32
(
bb
.
position
())
+
bb
.
position
(),
bb
);
};
/**
* @param {NamespaceA.NamespaceB.TableInNestedNS=} obj
* @returns {NamespaceA.NamespaceB.TableInNestedNS}
*/
NamespaceA
.
TableInFirstNS
.
prototype
.
fooTable
=
function
(
obj
)
{
var
offset
=
this
.
bb
.
__offset
(
this
.
bb_pos
,
4
);
return
offset
?
(
obj
||
new
NamespaceA
.
NamespaceB
.
TableInNestedNS
).
__init
(
this
.
bb
.
__indirect
(
this
.
bb_pos
+
offset
),
this
.
bb
)
:
null
;
};
/**
* @returns {NamespaceA.NamespaceB.EnumInNestedNS}
*/
NamespaceA
.
TableInFirstNS
.
prototype
.
fooEnum
=
function
()
{
var
offset
=
this
.
bb
.
__offset
(
this
.
bb_pos
,
6
);
return
offset
?
/** @type {NamespaceA.NamespaceB.EnumInNestedNS} */
(
this
.
bb
.
readInt8
(
this
.
bb_pos
+
offset
))
:
NamespaceA
.
NamespaceB
.
EnumInNestedNS
.
A
;
};
/**
* @param {NamespaceA.NamespaceB.StructInNestedNS=} obj
* @returns {NamespaceA.NamespaceB.StructInNestedNS}
*/
NamespaceA
.
TableInFirstNS
.
prototype
.
fooStruct
=
function
(
obj
)
{
var
offset
=
this
.
bb
.
__offset
(
this
.
bb_pos
,
8
);
return
offset
?
(
obj
||
new
NamespaceA
.
NamespaceB
.
StructInNestedNS
).
__init
(
this
.
bb_pos
+
offset
,
this
.
bb
)
:
null
;
};
/**
* @param {flatbuffers.Builder} builder
*/
NamespaceA
.
TableInFirstNS
.
startTableInFirstNS
=
function
(
builder
)
{
builder
.
startObject
(
3
);
};
/**
* @param {flatbuffers.Builder} builder
* @param {flatbuffers.Offset} fooTableOffset
*/
NamespaceA
.
TableInFirstNS
.
addFooTable
=
function
(
builder
,
fooTableOffset
)
{
builder
.
addFieldOffset
(
0
,
fooTableOffset
,
0
);
};
/**
* @param {flatbuffers.Builder} builder
* @param {NamespaceA.NamespaceB.EnumInNestedNS} fooEnum
*/
NamespaceA
.
TableInFirstNS
.
addFooEnum
=
function
(
builder
,
fooEnum
)
{
builder
.
addFieldInt8
(
1
,
fooEnum
,
NamespaceA
.
NamespaceB
.
EnumInNestedNS
.
A
);
};
/**
* @param {flatbuffers.Builder} builder
* @param {flatbuffers.Offset} fooStructOffset
*/
NamespaceA
.
TableInFirstNS
.
addFooStruct
=
function
(
builder
,
fooStructOffset
)
{
builder
.
addFieldStruct
(
2
,
fooStructOffset
,
0
);
};
/**
* @param {flatbuffers.Builder} builder
* @returns {flatbuffers.Offset}
*/
NamespaceA
.
TableInFirstNS
.
endTableInFirstNS
=
function
(
builder
)
{
var
offset
=
builder
.
endObject
();
return
offset
;
};
// Exports for Node.js and RequireJS
this
.
NamespaceA
=
NamespaceA
;
tests/test.cpp
View file @
6bfcb286
...
...
@@ -21,6 +21,8 @@
#include "flatbuffers/util.h"
#include "monster_test_generated.h"
#include "namespace_test/namespace_test1_generated.h"
#include "namespace_test/namespace_test2_generated.h"
#include <random>
...
...
@@ -219,6 +221,10 @@ void AccessFlatBufferTest(const uint8_t *flatbuf, size_t length) {
for
(
auto
it
=
tests
->
begin
();
it
!=
tests
->
end
();
++
it
)
{
TEST_EQ
(
it
->
a
()
==
10
||
it
->
a
()
==
30
,
true
);
// Just testing iterators.
}
// Checking for presence of fields:
TEST_EQ
(
flatbuffers
::
IsFieldPresent
(
monster
,
Monster
::
VT_HP
),
true
);
TEST_EQ
(
flatbuffers
::
IsFieldPresent
(
monster
,
Monster
::
VT_MANA
),
false
);
}
// Change a FlatBuffer in-place, after it has been constructed.
...
...
@@ -398,6 +404,11 @@ void ReflectionTest(uint8_t *flatbuf, size_t length) {
rtestarrayofstring
->
MutateOffset
(
2
,
string_ptr
);
TEST_EQ_STR
(
rtestarrayofstring
->
Get
(
0
)
->
c_str
(),
"bob"
);
TEST_EQ_STR
(
rtestarrayofstring
->
Get
(
2
)
->
c_str
(),
"hank"
);
// Test integrity of all resize operations above.
flatbuffers
::
Verifier
resize_verifier
(
reinterpret_cast
<
const
uint8_t
*>
(
resizingbuf
.
data
()),
resizingbuf
.
size
());
TEST_EQ
(
VerifyMonsterBuffer
(
resize_verifier
),
true
);
// As an additional test, also set it on the name field.
// Note: unlike the name change above, this just overwrites the offset,
// rather than changing the string in-place.
...
...
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