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
df0991b7
Commit
df0991b7
authored
Sep 14, 2016
by
Xun Liu
Committed by
Xun Liu
Sep 15, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
serialize fully qualified struct & enum name in schema binary
parent
96ab6ade
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
4 deletions
+15
-4
idl_parser.cpp
src/idl_parser.cpp
+6
-3
monster_test.bfbs
tests/monster_test.bfbs
+0
-0
test.cpp
tests/test.cpp
+9
-1
No files found.
src/idl_parser.cpp
View file @
df0991b7
...
...
@@ -1977,7 +1977,8 @@ std::set<std::string> Parser::GetIncludedFilesRecursive(
// Schema serialization functionality:
template
<
typename
T
>
bool
compareName
(
const
T
*
a
,
const
T
*
b
)
{
return
a
->
name
<
b
->
name
;
return
a
->
defined_namespace
->
GetFullyQualifiedName
(
a
->
name
)
<
b
->
defined_namespace
->
GetFullyQualifiedName
(
b
->
name
);
}
template
<
typename
T
>
void
AssignIndices
(
const
std
::
vector
<
T
*>
&
defvec
)
{
...
...
@@ -2023,8 +2024,9 @@ Offset<reflection::Object> StructDef::Serialize(FlatBufferBuilder *builder,
(
*
it
)
->
Serialize
(
builder
,
static_cast
<
uint16_t
>
(
it
-
fields
.
vec
.
begin
()),
parser
));
}
auto
qualified_name
=
defined_namespace
->
GetFullyQualifiedName
(
name
);
return
reflection
::
CreateObject
(
*
builder
,
builder
->
CreateString
(
name
),
builder
->
CreateString
(
qualified_
name
),
builder
->
CreateVectorOfSortedTables
(
&
field_offsets
),
fixed
,
...
...
@@ -2061,8 +2063,9 @@ Offset<reflection::Enum> EnumDef::Serialize(FlatBufferBuilder *builder,
for
(
auto
it
=
vals
.
vec
.
begin
();
it
!=
vals
.
vec
.
end
();
++
it
)
{
enumval_offsets
.
push_back
((
*
it
)
->
Serialize
(
builder
));
}
auto
qualified_name
=
defined_namespace
->
GetFullyQualifiedName
(
name
);
return
reflection
::
CreateEnum
(
*
builder
,
builder
->
CreateString
(
name
),
builder
->
CreateString
(
qualified_
name
),
builder
->
CreateVector
(
enumval_offsets
),
is_union
,
underlying_type
.
Serialize
(
builder
),
...
...
tests/monster_test.bfbs
View file @
df0991b7
No preview for this file type
tests/test.cpp
View file @
df0991b7
...
...
@@ -433,7 +433,7 @@ void ReflectionTest(uint8_t *flatbuf, size_t length) {
// Make sure the schema is what we expect it to be.
auto
&
schema
=
*
reflection
::
GetSchema
(
bfbsfile
.
c_str
());
auto
root_table
=
schema
.
root_table
();
TEST_EQ_STR
(
root_table
->
name
()
->
c_str
(),
"Monster"
);
TEST_EQ_STR
(
root_table
->
name
()
->
c_str
(),
"M
yGame.Example.M
onster"
);
auto
fields
=
root_table
->
fields
();
auto
hp_field_ptr
=
fields
->
LookupByKey
(
"hp"
);
TEST_NOTNULL
(
hp_field_ptr
);
...
...
@@ -446,6 +446,14 @@ void ReflectionTest(uint8_t *flatbuf, size_t length) {
TEST_NOTNULL
(
friendly_field_ptr
->
attributes
());
TEST_NOTNULL
(
friendly_field_ptr
->
attributes
()
->
LookupByKey
(
"priority"
));
// Make sure the table index is what we expect it to be.
auto
pos_field_ptr
=
fields
->
LookupByKey
(
"pos"
);
TEST_NOTNULL
(
pos_field_ptr
);
TEST_EQ
(
pos_field_ptr
->
type
()
->
base_type
(),
reflection
::
Obj
);
auto
pos_table_ptr
=
schema
.
objects
()
->
Get
(
pos_field_ptr
->
type
()
->
index
());
TEST_NOTNULL
(
pos_table_ptr
);
TEST_EQ_STR
(
pos_table_ptr
->
name
()
->
c_str
(),
"MyGame.Example.Vec3"
);
// Now use it to dynamically access a buffer.
auto
&
root
=
*
flatbuffers
::
GetAnyRoot
(
flatbuf
);
auto
hp
=
flatbuffers
::
GetFieldI
<
uint16_t
>
(
root
,
hp_field
);
...
...
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