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
4bc6de9a
Commit
4bc6de9a
authored
Mar 06, 2018
by
Wouter van Oortmerssen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix broken Java/C# codegen
parent
3a62813f
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
45 additions
and
39 deletions
+45
-39
idl_gen_general.cpp
src/idl_gen_general.cpp
+24
-16
Monster.cs
tests/MyGame/Example/Monster.cs
+5
-8
Monster.java
tests/MyGame/Example/Monster.java
+1
-1
Referrable.cs
tests/MyGame/Example/Referrable.cs
+2
-2
Referrable.java
tests/MyGame/Example/Referrable.java
+1
-1
generate_code.bat
tests/generate_code.bat
+2
-1
monster_test.bfbs
tests/monster_test.bfbs
+0
-0
namespace_test2_generated.ts
tests/namespace_test/namespace_test2_generated.ts
+10
-10
No files found.
src/idl_gen_general.cpp
View file @
4bc6de9a
...
...
@@ -1026,20 +1026,23 @@ class GeneralGenerator : public BaseGenerator {
code
+=
MakeCamel
(
field
.
name
,
lang_
.
first_camel_upper
)
+
"ByKey("
;
code
+=
GenTypeNameDest
(
key_field
.
value
.
type
)
+
" key)"
;
code
+=
offset_prefix
;
code
+=
qualified_name
+
".__lookup_by_key(null, "
;
code
+=
lang_
.
accessor_prefix
+
"__vector(o), key, "
;
code
+=
lang_
.
accessor_prefix
+
"bb) : null; "
;
code
+=
"}
\n
"
;
code
+=
" public "
+
qualified_name
+
lang_
.
optional_suffix
+
" "
;
code
+=
MakeCamel
(
field
.
name
,
lang_
.
first_camel_upper
)
+
"ByKey("
;
code
+=
qualified_name
+
lang_
.
optional_suffix
+
" obj, "
;
code
+=
GenTypeNameDest
(
key_field
.
value
.
type
)
+
" key)"
;
code
+=
offset_prefix
;
code
+=
qualified_name
+
".__lookup_by_key(obj, "
;
code
+=
qualified_name
+
".__lookup_by_key("
;
if
(
lang_
.
language
==
IDLOptions
::
kJava
)
code
+=
"null, "
;
code
+=
lang_
.
accessor_prefix
+
"__vector(o), key, "
;
code
+=
lang_
.
accessor_prefix
+
"bb) : null; "
;
code
+=
"}
\n
"
;
if
(
lang_
.
language
==
IDLOptions
::
kJava
)
{
code
+=
" public "
+
qualified_name
+
lang_
.
optional_suffix
+
" "
;
code
+=
MakeCamel
(
field
.
name
,
lang_
.
first_camel_upper
)
+
"ByKey("
;
code
+=
qualified_name
+
lang_
.
optional_suffix
+
" obj, "
;
code
+=
GenTypeNameDest
(
key_field
.
value
.
type
)
+
" key)"
;
code
+=
offset_prefix
;
code
+=
qualified_name
+
".__lookup_by_key(obj, "
;
code
+=
lang_
.
accessor_prefix
+
"__vector(o), key, "
;
code
+=
lang_
.
accessor_prefix
+
"bb) : null; "
;
code
+=
"}
\n
"
;
}
break
;
}
}
...
...
@@ -1363,8 +1366,10 @@ class GeneralGenerator : public BaseGenerator {
}
code
+=
"
\n
public static "
+
struct_def
.
name
+
lang_
.
optional_suffix
;
code
+=
" __lookup_by_key("
+
struct_def
.
name
;
code
+=
" obj, int vectorLocation, "
;
code
+=
" __lookup_by_key("
;
if
(
lang_
.
language
==
IDLOptions
::
kJava
)
code
+=
struct_def
.
name
+
" obj, "
;
code
+=
"int vectorLocation, "
;
code
+=
GenTypeNameDest
(
key_field
->
value
.
type
);
code
+=
" key, ByteBuffer bb) {
\n
"
;
if
(
key_field
->
value
.
type
.
base_type
==
BASE_TYPE_STRING
)
{
...
...
@@ -1387,9 +1392,12 @@ class GeneralGenerator : public BaseGenerator {
code
+=
" start += middle;
\n
"
;
code
+=
" span -= middle;
\n
"
;
code
+=
" } else {
\n
"
;
code
+=
" return (obj == null ? "
;
code
+=
"new "
+
struct_def
.
name
;
code
+=
"(), obj).__assign(tableOffset, bb);
\n
"
;
code
+=
" return "
;
if
(
lang_
.
language
==
IDLOptions
::
kJava
)
code
+=
"(obj == null ? new "
+
struct_def
.
name
+
"() : obj)"
;
else
code
+=
"new "
+
struct_def
.
name
+
"()"
;
code
+=
".__assign(tableOffset, bb);
\n
"
;
code
+=
" }
\n
}
\n
"
;
code
+=
" return null;
\n
"
;
code
+=
" }
\n
"
;
...
...
tests/MyGame/Example/Monster.cs
View file @
4bc6de9a
...
...
@@ -43,8 +43,7 @@ public struct Monster : IFlatbufferObject
/// multiline too
public
Monster
?
Testarrayoftables
(
int
j
)
{
int
o
=
__p
.
__offset
(
26
);
return
o
!=
0
?
(
Monster
?)(
new
Monster
()).
__assign
(
__p
.
__indirect
(
__p
.
__vector
(
o
)
+
j
*
4
),
__p
.
bb
)
:
null
;
}
public
int
TestarrayoftablesLength
{
get
{
int
o
=
__p
.
__offset
(
26
);
return
o
!=
0
?
__p
.
__vector_len
(
o
)
:
0
;
}
}
public
Monster
?
TestarrayoftablesByKey
(
string
key
)
{
int
o
=
__p
.
__offset
(
26
);
return
o
!=
0
?
Monster
.
__lookup_by_key
(
null
,
__p
.
__vector
(
o
),
key
,
__p
.
bb
)
:
null
;
}
public
Monster
?
TestarrayoftablesByKey
(
Monster
?
obj
,
string
key
)
{
int
o
=
__p
.
__offset
(
26
);
return
o
!=
0
?
Monster
.
__lookup_by_key
(
obj
,
__p
.
__vector
(
o
),
key
,
__p
.
bb
)
:
null
;
}
public
Monster
?
TestarrayoftablesByKey
(
string
key
)
{
int
o
=
__p
.
__offset
(
26
);
return
o
!=
0
?
Monster
.
__lookup_by_key
(
__p
.
__vector
(
o
),
key
,
__p
.
bb
)
:
null
;
}
public
Monster
?
Enemy
{
get
{
int
o
=
__p
.
__offset
(
28
);
return
o
!=
0
?
(
Monster
?)(
new
Monster
()).
__assign
(
__p
.
__indirect
(
o
+
__p
.
bb_pos
),
__p
.
bb
)
:
null
;
}
}
public
byte
Testnestedflatbuffer
(
int
j
)
{
int
o
=
__p
.
__offset
(
30
);
return
o
!=
0
?
__p
.
bb
.
Get
(
__p
.
__vector
(
o
)
+
j
*
1
)
:
(
byte
)
0
;
}
public
int
TestnestedflatbufferLength
{
get
{
int
o
=
__p
.
__offset
(
30
);
return
o
!=
0
?
__p
.
__vector_len
(
o
)
:
0
;
}
}
...
...
@@ -101,8 +100,7 @@ public struct Monster : IFlatbufferObject
public
MyGame
.
InParentNamespace
?
ParentNamespaceTest
{
get
{
int
o
=
__p
.
__offset
(
72
);
return
o
!=
0
?
(
MyGame
.
InParentNamespace
?)(
new
MyGame
.
InParentNamespace
()).
__assign
(
__p
.
__indirect
(
o
+
__p
.
bb_pos
),
__p
.
bb
)
:
null
;
}
}
public
Referrable
?
VectorOfReferrables
(
int
j
)
{
int
o
=
__p
.
__offset
(
74
);
return
o
!=
0
?
(
Referrable
?)(
new
Referrable
()).
__assign
(
__p
.
__indirect
(
__p
.
__vector
(
o
)
+
j
*
4
),
__p
.
bb
)
:
null
;
}
public
int
VectorOfReferrablesLength
{
get
{
int
o
=
__p
.
__offset
(
74
);
return
o
!=
0
?
__p
.
__vector_len
(
o
)
:
0
;
}
}
public
Referrable
?
VectorOfReferrablesByKey
(
ulong
key
)
{
int
o
=
__p
.
__offset
(
74
);
return
o
!=
0
?
Referrable
.
__lookup_by_key
(
null
,
__p
.
__vector
(
o
),
key
,
__p
.
bb
)
:
null
;
}
public
Referrable
?
VectorOfReferrablesByKey
(
Referrable
?
obj
,
ulong
key
)
{
int
o
=
__p
.
__offset
(
74
);
return
o
!=
0
?
Referrable
.
__lookup_by_key
(
obj
,
__p
.
__vector
(
o
),
key
,
__p
.
bb
)
:
null
;
}
public
Referrable
?
VectorOfReferrablesByKey
(
ulong
key
)
{
int
o
=
__p
.
__offset
(
74
);
return
o
!=
0
?
Referrable
.
__lookup_by_key
(
__p
.
__vector
(
o
),
key
,
__p
.
bb
)
:
null
;
}
public
ulong
SingleWeakReference
{
get
{
int
o
=
__p
.
__offset
(
76
);
return
o
!=
0
?
__p
.
bb
.
GetUlong
(
o
+
__p
.
bb_pos
)
:
(
ulong
)
0
;
}
}
public
bool
MutateSingleWeakReference
(
ulong
single_weak_reference
)
{
int
o
=
__p
.
__offset
(
76
);
if
(
o
!=
0
)
{
__p
.
bb
.
PutUlong
(
o
+
__p
.
bb_pos
,
single_weak_reference
);
return
true
;
}
else
{
return
false
;
}
}
public
ulong
VectorOfWeakReferences
(
int
j
)
{
int
o
=
__p
.
__offset
(
78
);
return
o
!=
0
?
__p
.
bb
.
GetUlong
(
__p
.
__vector
(
o
)
+
j
*
8
)
:
(
ulong
)
0
;
}
...
...
@@ -111,8 +109,7 @@ public struct Monster : IFlatbufferObject
public
bool
MutateVectorOfWeakReferences
(
int
j
,
ulong
vector_of_weak_references
)
{
int
o
=
__p
.
__offset
(
78
);
if
(
o
!=
0
)
{
__p
.
bb
.
PutUlong
(
__p
.
__vector
(
o
)
+
j
*
8
,
vector_of_weak_references
);
return
true
;
}
else
{
return
false
;
}
}
public
Referrable
?
VectorOfStrongReferrables
(
int
j
)
{
int
o
=
__p
.
__offset
(
80
);
return
o
!=
0
?
(
Referrable
?)(
new
Referrable
()).
__assign
(
__p
.
__indirect
(
__p
.
__vector
(
o
)
+
j
*
4
),
__p
.
bb
)
:
null
;
}
public
int
VectorOfStrongReferrablesLength
{
get
{
int
o
=
__p
.
__offset
(
80
);
return
o
!=
0
?
__p
.
__vector_len
(
o
)
:
0
;
}
}
public
Referrable
?
VectorOfStrongReferrablesByKey
(
ulong
key
)
{
int
o
=
__p
.
__offset
(
80
);
return
o
!=
0
?
Referrable
.
__lookup_by_key
(
null
,
__p
.
__vector
(
o
),
key
,
__p
.
bb
)
:
null
;
}
public
Referrable
?
VectorOfStrongReferrablesByKey
(
Referrable
?
obj
,
ulong
key
)
{
int
o
=
__p
.
__offset
(
80
);
return
o
!=
0
?
Referrable
.
__lookup_by_key
(
obj
,
__p
.
__vector
(
o
),
key
,
__p
.
bb
)
:
null
;
}
public
Referrable
?
VectorOfStrongReferrablesByKey
(
ulong
key
)
{
int
o
=
__p
.
__offset
(
80
);
return
o
!=
0
?
Referrable
.
__lookup_by_key
(
__p
.
__vector
(
o
),
key
,
__p
.
bb
)
:
null
;
}
public
ulong
CoOwningReference
{
get
{
int
o
=
__p
.
__offset
(
82
);
return
o
!=
0
?
__p
.
bb
.
GetUlong
(
o
+
__p
.
bb_pos
)
:
(
ulong
)
0
;
}
}
public
bool
MutateCoOwningReference
(
ulong
co_owning_reference
)
{
int
o
=
__p
.
__offset
(
82
);
if
(
o
!=
0
)
{
__p
.
bb
.
PutUlong
(
o
+
__p
.
bb_pos
,
co_owning_reference
);
return
true
;
}
else
{
return
false
;
}
}
public
ulong
VectorOfCoOwningReferences
(
int
j
)
{
int
o
=
__p
.
__offset
(
84
);
return
o
!=
0
?
__p
.
bb
.
GetUlong
(
__p
.
__vector
(
o
)
+
j
*
8
)
:
(
ulong
)
0
;
}
...
...
@@ -212,7 +209,7 @@ public struct Monster : IFlatbufferObject
return
builder
.
CreateVectorOfTables
(
offsets
);
}
public
static
Monster
?
__lookup_by_key
(
Monster
obj
,
int
vectorLocation
,
string
key
,
ByteBuffer
bb
)
{
public
static
Monster
?
__lookup_by_key
(
int
vectorLocation
,
string
key
,
ByteBuffer
bb
)
{
byte
[]
byteKey
=
System
.
Text
.
Encoding
.
UTF8
.
GetBytes
(
key
);
int
span
=
bb
.
GetInt
(
vectorLocation
-
4
);
int
start
=
0
;
...
...
@@ -227,7 +224,7 @@ public struct Monster : IFlatbufferObject
start
+=
middle
;
span
-=
middle
;
}
else
{
return
(
obj
==
null
?
new
Monster
(),
obj
).
__assign
(
tableOffset
,
bb
);
return
new
Monster
(
).
__assign
(
tableOffset
,
bb
);
}
}
return
null
;
...
...
tests/MyGame/Example/Monster.java
View file @
4bc6de9a
...
...
@@ -247,7 +247,7 @@ public final class Monster extends Table {
start
+=
middle
;
span
-=
middle
;
}
else
{
return
(
obj
==
null
?
new
Monster
()
,
obj
).
__assign
(
tableOffset
,
bb
);
return
(
obj
==
null
?
new
Monster
()
:
obj
).
__assign
(
tableOffset
,
bb
);
}
}
return
null
;
...
...
tests/MyGame/Example/Referrable.cs
View file @
4bc6de9a
...
...
@@ -39,7 +39,7 @@ public struct Referrable : IFlatbufferObject
return
builder
.
CreateVectorOfTables
(
offsets
);
}
public
static
Referrable
?
__lookup_by_key
(
Referrable
obj
,
int
vectorLocation
,
ulong
key
,
ByteBuffer
bb
)
{
public
static
Referrable
?
__lookup_by_key
(
int
vectorLocation
,
ulong
key
,
ByteBuffer
bb
)
{
int
span
=
bb
.
GetInt
(
vectorLocation
-
4
);
int
start
=
0
;
while
(
span
!=
0
)
{
...
...
@@ -53,7 +53,7 @@ public struct Referrable : IFlatbufferObject
start
+=
middle
;
span
-=
middle
;
}
else
{
return
(
obj
==
null
?
new
Referrable
(),
obj
).
__assign
(
tableOffset
,
bb
);
return
new
Referrable
(
).
__assign
(
tableOffset
,
bb
);
}
}
return
null
;
...
...
tests/MyGame/Example/Referrable.java
View file @
4bc6de9a
...
...
@@ -53,7 +53,7 @@ public final class Referrable extends Table {
start
+=
middle
;
span
-=
middle
;
}
else
{
return
(
obj
==
null
?
new
Referrable
()
,
obj
).
__assign
(
tableOffset
,
bb
);
return
(
obj
==
null
?
new
Referrable
()
:
obj
).
__assign
(
tableOffset
,
bb
);
}
}
return
null
;
...
...
tests/generate_code.bat
View file @
4bc6de9a
...
...
@@ -21,7 +21,7 @@ if "%1"=="-b" set buildtype=%2
..\%buildtype%\flatc.exe -b --schema --bfbs-comments -I include_test monster_test.fbs
..\%buildtype%\flatc.exe --jsonschema --schema -I include_test monster_test.fbs
cd ../samples
..\%buildtype%\flatc.exe --cpp --gen-mutable --gen-object-api --cpp-ptr-type flatbuffers::unique_ptr monster.fbs
..\%buildtype%\flatc.exe --cpp --gen-mutable --
reflect-names --
gen-object-api --cpp-ptr-type flatbuffers::unique_ptr monster.fbs
cd ../reflection
cd ../tests
\ No newline at end of file
tests/monster_test.bfbs
View file @
4bc6de9a
No preview for this file type
tests/namespace_test/namespace_test2_generated.ts
View file @
4bc6de9a
// automatically generated by the FlatBuffers compiler, do not modify
import
*
as
NS
9459827973991502386
from
"./namespace_test1_generated"
;
import
*
as
NS
39599748
from
"./namespace_test1_generated"
;
/**
* @constructor
*/
...
...
@@ -39,24 +39,24 @@ static getRootAsTableInFirstNS(bb:flatbuffers.ByteBuffer, obj?:TableInFirstNS):T
* @param {NamespaceA.NamespaceB.TableInNestedNS=} obj
* @returns {NamespaceA.NamespaceB.TableInNestedNS|null}
*/
fooTable
(
obj
?:
NS
9459827973991502386
.
NamespaceA
.
NamespaceB
.
TableInNestedNS
):
NS9459827973991502386
.
NamespaceA
.
NamespaceB
.
TableInNestedNS
|
null
{
fooTable
(
obj
?:
NS
39599748
.
NamespaceA
.
NamespaceB
.
TableInNestedNS
):
NS39599748
.
NamespaceA
.
NamespaceB
.
TableInNestedNS
|
null
{
var
offset
=
this
.
bb
!
.
__offset
(
this
.
bb_pos
,
4
);
return
offset
?
(
obj
||
new
NS
9459827973991502386
.
NamespaceA
.
NamespaceB
.
TableInNestedNS
).
__init
(
this
.
bb
!
.
__indirect
(
this
.
bb_pos
+
offset
),
this
.
bb
!
)
:
null
;
return
offset
?
(
obj
||
new
NS
39599748
.
NamespaceA
.
NamespaceB
.
TableInNestedNS
).
__init
(
this
.
bb
!
.
__indirect
(
this
.
bb_pos
+
offset
),
this
.
bb
!
)
:
null
;
};
/**
* @returns {NamespaceA.NamespaceB.EnumInNestedNS}
*/
fooEnum
():
NS
9459827973991502386
.
NamespaceA
.
NamespaceB
.
EnumInNestedNS
{
fooEnum
():
NS
39599748
.
NamespaceA
.
NamespaceB
.
EnumInNestedNS
{
var
offset
=
this
.
bb
!
.
__offset
(
this
.
bb_pos
,
6
);
return
offset
?
/** @type {NamespaceA.NamespaceB.EnumInNestedNS} */
(
this
.
bb
!
.
readInt8
(
this
.
bb_pos
+
offset
))
:
NS
9459827973991502386
.
NamespaceA
.
NamespaceB
.
EnumInNestedNS
.
A
;
return
offset
?
/** @type {NamespaceA.NamespaceB.EnumInNestedNS} */
(
this
.
bb
!
.
readInt8
(
this
.
bb_pos
+
offset
))
:
NS
39599748
.
NamespaceA
.
NamespaceB
.
EnumInNestedNS
.
A
;
};
/**
* @param {NamespaceA.NamespaceB.EnumInNestedNS} value
* @returns {boolean}
*/
mutate_foo_enum
(
value
:
NS
9459827973991502386
.
NamespaceA
.
NamespaceB
.
EnumInNestedNS
):
boolean
{
mutate_foo_enum
(
value
:
NS
39599748
.
NamespaceA
.
NamespaceB
.
EnumInNestedNS
):
boolean
{
var
offset
=
this
.
bb
!
.
__offset
(
this
.
bb_pos
,
6
);
if
(
offset
===
0
)
{
...
...
@@ -71,9 +71,9 @@ mutate_foo_enum(value:NS9459827973991502386.NamespaceA.NamespaceB.EnumInNestedNS
* @param {NamespaceA.NamespaceB.StructInNestedNS=} obj
* @returns {NamespaceA.NamespaceB.StructInNestedNS|null}
*/
fooStruct
(
obj
?:
NS
9459827973991502386
.
NamespaceA
.
NamespaceB
.
StructInNestedNS
):
NS9459827973991502386
.
NamespaceA
.
NamespaceB
.
StructInNestedNS
|
null
{
fooStruct
(
obj
?:
NS
39599748
.
NamespaceA
.
NamespaceB
.
StructInNestedNS
):
NS39599748
.
NamespaceA
.
NamespaceB
.
StructInNestedNS
|
null
{
var
offset
=
this
.
bb
!
.
__offset
(
this
.
bb_pos
,
8
);
return
offset
?
(
obj
||
new
NS
9459827973991502386
.
NamespaceA
.
NamespaceB
.
StructInNestedNS
).
__init
(
this
.
bb_pos
+
offset
,
this
.
bb
!
)
:
null
;
return
offset
?
(
obj
||
new
NS
39599748
.
NamespaceA
.
NamespaceB
.
StructInNestedNS
).
__init
(
this
.
bb_pos
+
offset
,
this
.
bb
!
)
:
null
;
};
/**
...
...
@@ -95,8 +95,8 @@ static addFooTable(builder:flatbuffers.Builder, fooTableOffset:flatbuffers.Offse
* @param {flatbuffers.Builder} builder
* @param {NamespaceA.NamespaceB.EnumInNestedNS} fooEnum
*/
static
addFooEnum
(
builder
:
flatbuffers
.
Builder
,
fooEnum
:
NS
9459827973991502386
.
NamespaceA
.
NamespaceB
.
EnumInNestedNS
)
{
builder
.
addFieldInt8
(
1
,
fooEnum
,
NS
9459827973991502386
.
NamespaceA
.
NamespaceB
.
EnumInNestedNS
.
A
);
static
addFooEnum
(
builder
:
flatbuffers
.
Builder
,
fooEnum
:
NS
39599748
.
NamespaceA
.
NamespaceB
.
EnumInNestedNS
)
{
builder
.
addFieldInt8
(
1
,
fooEnum
,
NS
39599748
.
NamespaceA
.
NamespaceB
.
EnumInNestedNS
.
A
);
};
/**
...
...
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