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
cdb0dca3
Commit
cdb0dca3
authored
Aug 13, 2014
by
Wouter van Oortmerssen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed possible alignment issue in Java
Tested: on Linux Change-Id: Ie80aa19ed13ac4fa15cd3fd768f1a35526bdc607
parent
f2908b77
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
10 deletions
+18
-10
FlatBufferBuilder.java
java/flatbuffers/FlatBufferBuilder.java
+3
-2
idl_gen_java.cpp
src/idl_gen_java.cpp
+6
-2
Monster.java
tests/MyGame/Example/Monster.java
+9
-6
No files found.
java/flatbuffers/FlatBufferBuilder.java
View file @
cdb0dca3
...
...
@@ -123,10 +123,11 @@ public class FlatBufferBuilder {
putInt
(
off
);
}
public
void
startVector
(
int
elem_size
,
int
num_elems
)
{
public
void
startVector
(
int
elem_size
,
int
num_elems
,
int
alignment
)
{
notNested
();
vector_num_elems
=
num_elems
;
prep
(
SIZEOF_INT
,
elem_size
*
num_elems
);
prep
(
alignment
,
elem_size
*
num_elems
);
// Just in case alignment > int.
}
public
int
endVector
()
{
...
...
@@ -137,7 +138,7 @@ public class FlatBufferBuilder {
public
int
createString
(
String
s
)
{
byte
[]
utf8
=
s
.
getBytes
(
utf8charset
);
addByte
((
byte
)
0
);
startVector
(
1
,
utf8
.
length
);
startVector
(
1
,
utf8
.
length
,
1
);
System
.
arraycopy
(
utf8
,
0
,
bb
.
array
(),
space
-=
utf8
.
length
,
utf8
.
length
);
return
endVector
();
}
...
...
src/idl_gen_java.cpp
View file @
cdb0dca3
...
...
@@ -320,8 +320,12 @@ static void GenStruct(StructDef &struct_def,
code
+=
" public static void start"
+
MakeCamel
(
field
.
name
);
code
+=
"Vector(FlatBufferBuilder builder, int numElems) "
;
code
+=
"{ builder.startVector("
;
code
+=
NumToString
(
InlineSize
(
field
.
value
.
type
.
VectorType
()));
code
+=
", numElems); }
\n
"
;
auto
vector_type
=
field
.
value
.
type
.
VectorType
();
auto
alignment
=
InlineAlignment
(
vector_type
);
auto
elem_size
=
InlineSize
(
vector_type
);
code
+=
NumToString
(
elem_size
);
code
+=
", numElems, "
+
NumToString
(
alignment
);
code
+=
"); }
\n
"
;
}
}
code
+=
" public static int end"
+
struct_def
.
name
;
...
...
tests/MyGame/Example/Monster.java
View file @
cdb0dca3
...
...
@@ -33,26 +33,29 @@ public class Monster extends Table {
public
Monster
enemy
(
Monster
obj
)
{
int
o
=
__offset
(
28
);
return
o
!=
0
?
obj
.
__init
(
__indirect
(
o
+
bb_pos
),
bb
)
:
null
;
}
public
byte
testnestedflatbuffer
(
int
j
)
{
int
o
=
__offset
(
30
);
return
o
!=
0
?
bb
.
get
(
__vector
(
o
)
+
j
*
1
)
:
0
;
}
public
int
testnestedflatbufferLength
()
{
int
o
=
__offset
(
30
);
return
o
!=
0
?
__vector_len
(
o
)
:
0
;
}
public
Monster
testempty
()
{
return
testempty
(
new
Monster
());
}
public
Monster
testempty
(
Monster
obj
)
{
int
o
=
__offset
(
32
);
return
o
!=
0
?
obj
.
__init
(
__indirect
(
o
+
bb_pos
),
bb
)
:
null
;
}
public
static
void
startMonster
(
FlatBufferBuilder
builder
)
{
builder
.
startObject
(
1
4
);
}
public
static
void
startMonster
(
FlatBufferBuilder
builder
)
{
builder
.
startObject
(
1
5
);
}
public
static
void
addPos
(
FlatBufferBuilder
builder
,
int
posOffset
)
{
builder
.
addStruct
(
0
,
posOffset
,
0
);
}
public
static
void
addMana
(
FlatBufferBuilder
builder
,
short
mana
)
{
builder
.
addShort
(
1
,
mana
,
150
);
}
public
static
void
addHp
(
FlatBufferBuilder
builder
,
short
hp
)
{
builder
.
addShort
(
2
,
hp
,
100
);
}
public
static
void
addName
(
FlatBufferBuilder
builder
,
int
nameOffset
)
{
builder
.
addOffset
(
3
,
nameOffset
,
0
);
}
public
static
void
addInventory
(
FlatBufferBuilder
builder
,
int
inventoryOffset
)
{
builder
.
addOffset
(
5
,
inventoryOffset
,
0
);
}
public
static
void
startInventoryVector
(
FlatBufferBuilder
builder
,
int
numElems
)
{
builder
.
startVector
(
1
,
numElems
);
}
public
static
void
startInventoryVector
(
FlatBufferBuilder
builder
,
int
numElems
)
{
builder
.
startVector
(
1
,
numElems
,
1
);
}
public
static
void
addColor
(
FlatBufferBuilder
builder
,
byte
color
)
{
builder
.
addByte
(
6
,
color
,
8
);
}
public
static
void
addTestType
(
FlatBufferBuilder
builder
,
byte
testType
)
{
builder
.
addByte
(
7
,
testType
,
0
);
}
public
static
void
addTest
(
FlatBufferBuilder
builder
,
int
testOffset
)
{
builder
.
addOffset
(
8
,
testOffset
,
0
);
}
public
static
void
addTest4
(
FlatBufferBuilder
builder
,
int
test4Offset
)
{
builder
.
addOffset
(
9
,
test4Offset
,
0
);
}
public
static
void
startTest4Vector
(
FlatBufferBuilder
builder
,
int
numElems
)
{
builder
.
startVector
(
4
,
numElems
);
}
public
static
void
startTest4Vector
(
FlatBufferBuilder
builder
,
int
numElems
)
{
builder
.
startVector
(
4
,
numElems
,
2
);
}
public
static
void
addTestarrayofstring
(
FlatBufferBuilder
builder
,
int
testarrayofstringOffset
)
{
builder
.
addOffset
(
10
,
testarrayofstringOffset
,
0
);
}
public
static
void
startTestarrayofstringVector
(
FlatBufferBuilder
builder
,
int
numElems
)
{
builder
.
startVector
(
4
,
numElems
);
}
public
static
void
startTestarrayofstringVector
(
FlatBufferBuilder
builder
,
int
numElems
)
{
builder
.
startVector
(
4
,
numElems
,
4
);
}
public
static
void
addTestarrayoftables
(
FlatBufferBuilder
builder
,
int
testarrayoftablesOffset
)
{
builder
.
addOffset
(
11
,
testarrayoftablesOffset
,
0
);
}
public
static
void
startTestarrayoftablesVector
(
FlatBufferBuilder
builder
,
int
numElems
)
{
builder
.
startVector
(
4
,
numElems
);
}
public
static
void
startTestarrayoftablesVector
(
FlatBufferBuilder
builder
,
int
numElems
)
{
builder
.
startVector
(
4
,
numElems
,
4
);
}
public
static
void
addEnemy
(
FlatBufferBuilder
builder
,
int
enemyOffset
)
{
builder
.
addOffset
(
12
,
enemyOffset
,
0
);
}
public
static
void
addTestnestedflatbuffer
(
FlatBufferBuilder
builder
,
int
testnestedflatbufferOffset
)
{
builder
.
addOffset
(
13
,
testnestedflatbufferOffset
,
0
);
}
public
static
void
startTestnestedflatbufferVector
(
FlatBufferBuilder
builder
,
int
numElems
)
{
builder
.
startVector
(
1
,
numElems
);
}
public
static
void
startTestnestedflatbufferVector
(
FlatBufferBuilder
builder
,
int
numElems
)
{
builder
.
startVector
(
1
,
numElems
,
1
);
}
public
static
void
addTestempty
(
FlatBufferBuilder
builder
,
int
testemptyOffset
)
{
builder
.
addOffset
(
14
,
testemptyOffset
,
0
);
}
public
static
int
endMonster
(
FlatBufferBuilder
builder
)
{
return
builder
.
endObject
();
}
};
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