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
1a896822
Commit
1a896822
authored
Dec 22, 2016
by
Wouter van Oortmerssen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/google/flatbuffers
parents
5fd0fefa
f8a964d2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
1 deletion
+31
-1
flatbuffers.h
include/flatbuffers/flatbuffers.h
+1
-1
reflection.h
include/flatbuffers/reflection.h
+16
-0
test.cpp
tests/test.cpp
+14
-0
No files found.
include/flatbuffers/flatbuffers.h
View file @
1a896822
...
...
@@ -1502,7 +1502,7 @@ template<typename T> struct BufferRef : BufferRefBase {
bool
Verify
()
{
Verifier
verifier
(
buf
,
len
);
return
verifier
.
VerifyBuffer
<
T
>
();
return
verifier
.
VerifyBuffer
<
T
>
(
nullptr
);
}
uint8_t
*
buf
;
...
...
include/flatbuffers/reflection.h
View file @
1a896822
...
...
@@ -105,6 +105,22 @@ inline Table *GetFieldT(const Table &table,
return
table
.
GetPointer
<
Table
*>
(
field
.
offset
());
}
// Get a field, if you know it's a struct.
inline
const
Struct
*
GetFieldStruct
(
const
Table
&
table
,
const
reflection
::
Field
&
field
)
{
// TODO: This does NOT check if the field is a table or struct, but we'd need
// access to the schema to check the is_struct flag.
assert
(
field
.
type
()
->
base_type
()
==
reflection
::
Obj
);
return
table
.
GetStruct
<
const
Struct
*>
(
field
.
offset
());
}
// Get a structure's field, if you know it's a struct.
inline
const
Struct
*
GetFieldStruct
(
const
Struct
&
structure
,
const
reflection
::
Field
&
field
)
{
assert
(
field
.
type
()
->
base_type
()
==
reflection
::
Obj
);
return
structure
.
GetStruct
<
const
Struct
*>
(
field
.
offset
());
}
// Raw helper functions used below: get any value in memory as a 64bit int, a
// double or a string.
// All scalars get static_cast to an int64_t, strings use strtoull, every other
...
...
tests/test.cpp
View file @
1a896822
...
...
@@ -511,6 +511,20 @@ void ReflectionTest(uint8_t *flatbuf, size_t length) {
auto
hp_string
=
flatbuffers
::
GetAnyFieldS
(
root
,
hp_field
,
&
schema
);
TEST_EQ_STR
(
hp_string
.
c_str
(),
"80"
);
// Get struct field through reflection
auto
pos_struct
=
flatbuffers
::
GetFieldStruct
(
root
,
*
pos_field_ptr
);
TEST_NOTNULL
(
pos_struct
);
TEST_EQ
(
flatbuffers
::
GetAnyFieldF
(
*
pos_struct
,
*
pos_table_ptr
->
fields
()
->
LookupByKey
(
"z"
)),
3.0
f
);
auto
test3_field
=
pos_table_ptr
->
fields
()
->
LookupByKey
(
"test3"
);
auto
test3_struct
=
flatbuffers
::
GetFieldStruct
(
*
pos_struct
,
*
test3_field
);
TEST_NOTNULL
(
test3_struct
);
auto
test3_object
=
schema
.
objects
()
->
Get
(
test3_field
->
type
()
->
index
());
TEST_EQ
(
flatbuffers
::
GetAnyFieldF
(
*
test3_struct
,
*
test3_object
->
fields
()
->
LookupByKey
(
"a"
)),
10
);
// We can also modify it.
flatbuffers
::
SetField
<
uint16_t
>
(
&
root
,
hp_field
,
200
);
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