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
622b8d05
Commit
622b8d05
authored
Jun 15, 2015
by
Wouter van Oortmerssen
Committed by
Wouter van Oortmerssen
Jun 16, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed warnings on Windows
parent
5faa0ab1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
14 deletions
+31
-14
flattests.vcxproj
build/VS2010/flattests.vcxproj
+3
-1
reflection.h
include/flatbuffers/reflection.h
+16
-10
idl_parser.cpp
src/idl_parser.cpp
+4
-2
test.cpp
tests/test.cpp
+8
-1
No files found.
build/VS2010/flattests.vcxproj
View file @
622b8d05
...
...
@@ -265,6 +265,7 @@
<ItemGroup>
<ClInclude
Include=
"..\..\include\flatbuffers\flatbuffers.h"
/>
<ClInclude
Include=
"..\..\include\flatbuffers\idl.h"
/>
<ClInclude
Include=
"..\..\include\flatbuffers\reflection.h"
/>
<ClInclude
Include=
"..\..\include\flatbuffers\util.h"
/>
<ClInclude
Include=
"..\..\tests\monster_test_generated.h"
/>
<ClCompile
Include=
"..\..\src\idl_gen_fbs.cpp"
/>
...
...
@@ -276,4 +277,4 @@
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.targets"
/>
<ImportGroup
Label=
"ExtensionTargets"
>
</ImportGroup>
</Project>
</Project>
\ No newline at end of file
include/flatbuffers/reflection.h
View file @
622b8d05
...
...
@@ -48,14 +48,16 @@ inline const Table *GetAnyRoot(const uint8_t *flatbuf) {
template
<
typename
T
>
T
GetFieldI
(
const
Table
*
table
,
const
reflection
::
Field
*
field
)
{
assert
(
sizeof
(
T
)
==
GetTypeSize
(
field
->
type
()
->
base_type
()));
return
table
->
GetField
<
T
>
(
field
->
offset
(),
field
->
default_integer
());
return
table
->
GetField
<
T
>
(
field
->
offset
(),
static_cast
<
T
>
(
field
->
default_integer
()));
}
// Get a field, if you know it's floating point and its exact type.
template
<
typename
T
>
T
GetFieldF
(
const
Table
*
table
,
const
reflection
::
Field
*
field
)
{
assert
(
sizeof
(
T
)
==
GetTypeSize
(
field
->
type
()
->
base_type
()));
return
table
->
GetField
<
T
>
(
field
->
offset
(),
field
->
default_real
());
return
table
->
GetField
<
T
>
(
field
->
offset
(),
static_cast
<
T
>
(
field
->
default_real
()));
}
// Get a field, if you know it's a string.
...
...
@@ -106,7 +108,7 @@ inline double GetAnyFieldF(const Table *table,
case
reflection
:
:
Double
:
return
GetFieldF
<
double
>
(
table
,
field
);
case
reflection
:
:
String
:
return
strtod
(
GetFieldS
(
table
,
field
)
->
c_str
(),
nullptr
);
default
:
return
GetAnyFieldI
(
table
,
field
);
default
:
return
static_cast
<
double
>
(
GetAnyFieldI
(
table
,
field
)
);
}
}
...
...
@@ -191,6 +193,7 @@ template<typename T, typename U> class pointer_inside_vector {
const
T
*
operator
->
()
const
{
return
operator
*
();
}
void
operator
=
(
const
pointer_inside_vector
&
piv
);
private
:
size_t
offset_
;
const
std
::
vector
<
U
>
&
vec_
;
...
...
@@ -220,7 +223,7 @@ class ResizeContext {
if
(
!
delta_
)
return
;
// We can't shrink by less than largest_scalar_t.
// Now change all the offsets by delta_.
auto
root
=
GetAnyRoot
(
buf_
.
data
());
Straddle
<
uoffset_t
>
(
buf_
.
data
(),
root
,
buf_
.
data
());
Straddle
<
uoffset_t
,
1
>
(
buf_
.
data
(),
root
,
buf_
.
data
());
ResizeTable
(
schema
.
root_table
(),
root
);
// We can now add or remove bytes at start.
if
(
delta_
>
0
)
buf_
.
insert
(
buf_
.
begin
()
+
start
,
delta_
,
0
);
...
...
@@ -230,8 +233,8 @@ class ResizeContext {
// Check if the range between first (lower address) and second straddles
// the insertion point. If it does, change the offset at offsetloc (of
// type T, with direction D).
template
<
typename
T
,
int
D
=
1
>
void
Straddle
(
void
*
first
,
void
*
second
,
void
*
offsetloc
)
{
template
<
typename
T
,
int
D
>
void
Straddle
(
void
*
first
,
void
*
second
,
void
*
offsetloc
)
{
if
(
first
<=
startptr_
&&
second
>=
startptr_
)
{
WriteScalar
<
T
>
(
offsetloc
,
ReadScalar
<
T
>
(
offsetloc
)
+
delta_
*
D
);
DagCheck
(
offsetloc
)
=
true
;
...
...
@@ -283,7 +286,7 @@ class ResizeContext {
if
(
DagCheck
(
offsetloc
))
continue
;
// This offset already visited.
auto
ref
=
offsetloc
+
ReadScalar
<
uoffset_t
>
(
offsetloc
);
Straddle
<
uoffset_t
>
(
offsetloc
,
ref
,
offsetloc
);
Straddle
<
uoffset_t
,
1
>
(
offsetloc
,
ref
,
offsetloc
);
// Recurse.
switch
(
base_type
)
{
case
reflection
:
:
Obj
:
{
...
...
@@ -301,7 +304,7 @@ class ResizeContext {
if
(
DagCheck
(
loc
))
continue
;
// This offset already visited.
auto
dest
=
loc
+
vec
->
Get
(
i
);
Straddle
<
uoffset_t
>
(
loc
,
dest
,
loc
);
Straddle
<
uoffset_t
,
1
>
(
loc
,
dest
,
loc
);
ResizeTable
(
elemobjectdef
,
reinterpret_cast
<
Table
*>
(
dest
));
}
break
;
...
...
@@ -325,6 +328,8 @@ class ResizeContext {
}
}
void
operator
=
(
const
ResizeContext
&
rc
);
private
:
const
reflection
::
Schema
&
schema_
;
uint8_t
*
startptr_
;
...
...
@@ -361,7 +366,7 @@ template<typename T> void ResizeVector(const reflection::Schema &schema,
uoffset_t
newsize
,
T
val
,
const
Vector
<
T
>
*
vec
,
std
::
vector
<
uint8_t
>
*
flatbuf
)
{
auto
delta_elem
=
newsize
-
static_cast
<
int
>
(
vec
->
size
());
auto
delta_elem
=
static_cast
<
int
>
(
newsize
)
-
static_cast
<
int
>
(
vec
->
size
());
auto
delta_bytes
=
delta_elem
*
static_cast
<
int
>
(
sizeof
(
T
));
auto
vec_start
=
reinterpret_cast
<
const
uint8_t
*>
(
vec
)
-
flatbuf
->
data
();
auto
start
=
static_cast
<
uoffset_t
>
(
vec_start
+
sizeof
(
uoffset_t
)
+
...
...
@@ -372,7 +377,8 @@ template<typename T> void ResizeVector(const reflection::Schema &schema,
// Set new elements to "val".
for
(
int
i
=
0
;
i
<
delta_elem
;
i
++
)
{
auto
loc
=
flatbuf
->
data
()
+
start
+
i
*
sizeof
(
T
);
if
(
std
::
is_scalar
<
T
>::
value
)
{
auto
is_scalar
=
std
::
is_scalar
<
T
>::
value
;
if
(
is_scalar
)
{
WriteScalar
(
loc
,
val
);
}
else
{
// struct
*
reinterpret_cast
<
T
*>
(
loc
)
=
val
;
...
...
src/idl_parser.cpp
View file @
622b8d05
...
...
@@ -40,7 +40,7 @@ const char kTypeSizes[] = {
// The enums in the reflection schema should match the ones we use internally.
// Compare the last element to check if these go out of sync.
static_assert
(
BASE_TYPE_UNION
==
static_cast
<
BaseType
>
(
reflection
::
BaseType
::
Union
),
static_cast
<
BaseType
>
(
reflection
::
Union
),
"enums don't match"
);
static
void
Error
(
const
std
::
string
&
msg
)
{
...
...
@@ -1346,7 +1346,9 @@ Offset<reflection::Object> StructDef::Serialize(FlatBufferBuilder *builder)
const
{
std
::
vector
<
Offset
<
reflection
::
Field
>>
field_offsets
;
for
(
auto
it
=
fields
.
vec
.
begin
();
it
!=
fields
.
vec
.
end
();
++
it
)
{
field_offsets
.
push_back
((
*
it
)
->
Serialize
(
builder
,
it
-
fields
.
vec
.
begin
()));
field_offsets
.
push_back
(
(
*
it
)
->
Serialize
(
builder
,
static_cast
<
uint16_t
>
(
it
-
fields
.
vec
.
begin
())));
}
return
reflection
::
CreateObject
(
*
builder
,
builder
->
CreateString
(
name
),
...
...
tests/test.cpp
View file @
622b8d05
...
...
@@ -14,6 +14,8 @@
* limitations under the License.
*/
#define FLATBUFFERS_DEBUG_VERIFICATION_FAILURE 1
#include "flatbuffers/flatbuffers.h"
#include "flatbuffers/idl.h"
#include "flatbuffers/util.h"
...
...
@@ -292,7 +294,12 @@ void ReflectionTest(uint8_t *flatbuf, size_t length) {
// Load a binary schema.
std
::
string
bfbsfile
;
TEST_EQ
(
flatbuffers
::
LoadFile
(
"tests/monster_test.bfbs"
,
false
,
&
bfbsfile
),
true
);
"tests/monster_test.bfbs"
,
true
,
&
bfbsfile
),
true
);
// Verify it, just in case:
flatbuffers
::
Verifier
verifier
(
reinterpret_cast
<
const
uint8_t
*>
(
bfbsfile
.
c_str
()),
bfbsfile
.
length
());
TEST_EQ
(
reflection
::
VerifySchemaBuffer
(
verifier
),
true
);
// Make sure the schema is what we expect it to be.
auto
schema
=
reflection
::
GetSchema
(
bfbsfile
.
c_str
());
...
...
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