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
d72c4781
Commit
d72c4781
authored
Dec 09, 2014
by
Wouter van Oortmerssen
Committed by
Android (Google) Code Review
Dec 09, 2014
Browse files
Options
Browse Files
Download
Plain Diff
Merge "Added VectorLength helper function that works on nullptr." into ub-games-master
parents
10f4ecac
8833cff9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
0 deletions
+7
-0
flatbuffers.h
include/flatbuffers/flatbuffers.h
+6
-0
test.cpp
tests/test.cpp
+1
-0
No files found.
include/flatbuffers/flatbuffers.h
View file @
d72c4781
...
...
@@ -296,6 +296,12 @@ protected:
uoffset_t
length_
;
};
// Convenient helper function to get the length of any vector, regardless
// of wether it is null or not (the field is not set).
template
<
typename
T
>
static
inline
size_t
VectorLength
(
const
Vector
<
T
>
*
v
)
{
return
v
?
v
->
Length
()
:
0
;
}
struct
String
:
public
Vector
<
char
>
{
const
char
*
c_str
()
const
{
return
reinterpret_cast
<
const
char
*>
(
Data
());
}
};
...
...
tests/test.cpp
View file @
d72c4781
...
...
@@ -137,6 +137,7 @@ void AccessFlatBufferTest(const std::string &flatbuf) {
TEST_EQ
(
pos
->
test3
().
b
(),
20
);
auto
inventory
=
monster
->
inventory
();
TEST_EQ
(
VectorLength
(
inventory
),
10
);
// Works even if inventory is null.
TEST_NOTNULL
(
inventory
);
unsigned
char
inv_data
[]
=
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
};
for
(
auto
it
=
inventory
->
begin
();
it
!=
inventory
->
end
();
++
it
)
...
...
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