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
e10b8d6f
Commit
e10b8d6f
authored
Nov 25, 2015
by
Wouter van Oortmerssen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #349 from belldon/enum-fix
Fixes issue #348: C# vector of enums doesn't compile
parents
6775a0a9
644bcbde
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
149 additions
and
126 deletions
+149
-126
idl_gen_general.cpp
src/idl_gen_general.cpp
+135
-112
Monster.cs
tests/MyGame/Example/Monster.cs
+4
-4
Monster.java
tests/MyGame/Example/Monster.java
+2
-2
Stat.cs
tests/MyGame/Example/Stat.cs
+2
-2
Stat.java
tests/MyGame/Example/Stat.java
+3
-3
TestSimpleTableWithEnum.cs
tests/MyGame/Example/TestSimpleTableWithEnum.cs
+2
-2
Vec3.cs
tests/MyGame/Example/Vec3.cs
+1
-1
No files found.
src/idl_gen_general.cpp
View file @
e10b8d6f
...
@@ -194,8 +194,13 @@ static std::string FunctionStart(const LanguageParameters &lang, char upper) {
...
@@ -194,8 +194,13 @@ static std::string FunctionStart(const LanguageParameters &lang, char upper) {
:
upper
);
:
upper
);
}
}
static
bool
IsEnum
(
const
Type
&
type
)
{
return
type
.
enum_def
!=
nullptr
&&
IsInteger
(
type
.
base_type
);
}
static
std
::
string
GenTypeBasic
(
const
LanguageParameters
&
lang
,
static
std
::
string
GenTypeBasic
(
const
LanguageParameters
&
lang
,
const
Type
&
type
)
{
const
Type
&
type
,
bool
enableLangOverrides
)
{
static
const
char
*
gtypename
[]
=
{
static
const
char
*
gtypename
[]
=
{
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \
#JTYPE, #NTYPE, #GTYPE,
#JTYPE, #NTYPE, #GTYPE,
...
@@ -203,21 +208,18 @@ static std::string GenTypeBasic(const LanguageParameters &lang,
...
@@ -203,21 +208,18 @@ static std::string GenTypeBasic(const LanguageParameters &lang,
#undef FLATBUFFERS_TD
#undef FLATBUFFERS_TD
};
};
if
(
lang
.
language
==
GeneratorOptions
::
kCSharp
&&
type
.
base_type
==
BASE_TYPE_STRUCT
)
{
if
(
enableLangOverrides
)
{
return
"Offset<"
+
type
.
struct_def
->
name
+
">"
;
if
(
lang
.
language
==
GeneratorOptions
::
kCSharp
)
{
if
(
IsEnum
(
type
))
return
type
.
enum_def
->
name
;
if
(
type
.
base_type
==
BASE_TYPE_STRUCT
)
return
"Offset<"
+
type
.
struct_def
->
name
+
">"
;
}
}
}
return
gtypename
[
type
.
base_type
*
GeneratorOptions
::
kMAX
+
lang
.
language
];
return
gtypename
[
type
.
base_type
*
GeneratorOptions
::
kMAX
+
lang
.
language
];
}
}
// Generate type to be used in user-facing API
static
std
::
string
GenTypeBasic
(
const
LanguageParameters
&
lang
,
const
Type
&
type
)
{
static
std
::
string
GenTypeForUser
(
const
LanguageParameters
&
lang
,
return
GenTypeBasic
(
lang
,
type
,
true
);
const
Type
&
type
)
{
if
(
lang
.
language
==
GeneratorOptions
::
kCSharp
)
{
if
(
type
.
enum_def
!=
nullptr
&&
type
.
base_type
!=
BASE_TYPE_UNION
)
return
type
.
enum_def
->
name
;
}
return
GenTypeBasic
(
lang
,
type
);
}
}
static
std
::
string
GenTypeGet
(
const
LanguageParameters
&
lang
,
static
std
::
string
GenTypeGet
(
const
LanguageParameters
&
lang
,
...
@@ -233,6 +235,8 @@ static std::string GenTypePointer(const LanguageParameters &lang,
...
@@ -233,6 +235,8 @@ static std::string GenTypePointer(const LanguageParameters &lang,
case
BASE_TYPE_STRUCT
:
case
BASE_TYPE_STRUCT
:
return
type
.
struct_def
->
name
;
return
type
.
struct_def
->
name
;
case
BASE_TYPE_UNION
:
case
BASE_TYPE_UNION
:
// Unions in C# use a generic Table-derived type for better type safety
if
(
lang
.
language
==
GeneratorOptions
::
kCSharp
)
return
"TTable"
;
// fall through
// fall through
default
:
default
:
return
"Table"
;
return
"Table"
;
...
@@ -294,17 +298,6 @@ static std::string GenVectorOffsetType(const LanguageParameters &lang) {
...
@@ -294,17 +298,6 @@ static std::string GenVectorOffsetType(const LanguageParameters &lang) {
// Generate destination type name
// Generate destination type name
static
std
::
string
GenTypeNameDest
(
const
LanguageParameters
&
lang
,
const
Type
&
type
)
static
std
::
string
GenTypeNameDest
(
const
LanguageParameters
&
lang
,
const
Type
&
type
)
{
{
if
(
lang
.
language
==
GeneratorOptions
::
kCSharp
)
{
// C# enums are represented by themselves
if
(
type
.
enum_def
!=
nullptr
&&
type
.
base_type
!=
BASE_TYPE_UNION
)
return
type
.
enum_def
->
name
;
// Unions in C# use a generic Table-derived type for better type safety
if
(
type
.
base_type
==
BASE_TYPE_UNION
)
return
"TTable"
;
}
// default behavior
return
GenTypeGet
(
lang
,
DestinationType
(
lang
,
type
,
true
));
return
GenTypeGet
(
lang
,
DestinationType
(
lang
,
type
,
true
));
}
}
...
@@ -327,94 +320,78 @@ static std::string DestinationMask(const LanguageParameters &lang,
...
@@ -327,94 +320,78 @@ static std::string DestinationMask(const LanguageParameters &lang,
// Casts necessary to correctly read serialized data
// Casts necessary to correctly read serialized data
static
std
::
string
DestinationCast
(
const
LanguageParameters
&
lang
,
static
std
::
string
DestinationCast
(
const
LanguageParameters
&
lang
,
const
Type
&
type
)
{
const
Type
&
type
)
{
switch
(
lang
.
language
)
{
if
(
type
.
base_type
==
BASE_TYPE_VECTOR
)
{
return
DestinationCast
(
lang
,
type
.
VectorType
());
}
else
{
switch
(
lang
.
language
)
{
case
GeneratorOptions
:
:
kJava
:
case
GeneratorOptions
:
:
kJava
:
// Cast necessary to correctly read serialized unsigned values.
// Cast necessary to correctly read serialized unsigned values.
if
(
type
.
base_type
==
BASE_TYPE_UINT
||
if
(
type
.
base_type
==
BASE_TYPE_UINT
)
return
"(long)"
;
(
type
.
base_type
==
BASE_TYPE_VECTOR
&&
type
.
element
==
BASE_TYPE_UINT
))
return
"(long)"
;
break
;
break
;
case
GeneratorOptions
:
:
kCSharp
:
case
GeneratorOptions
:
:
kCSharp
:
// Cast from raw integral types to enum
// Cast from raw integral types to enum.
if
(
type
.
enum_def
!=
nullptr
&&
if
(
IsEnum
(
type
))
return
"("
+
type
.
enum_def
->
name
+
")"
;
type
.
base_type
!=
BASE_TYPE_UNION
)
return
"("
+
type
.
enum_def
->
name
+
")"
;
break
;
break
;
default
:
default
:
break
;
break
;
}
}
}
return
""
;
return
""
;
}
}
// Read value and possibly process it to get proper value
static
std
::
string
DestinationValue
(
const
LanguageParameters
&
lang
,
const
std
::
string
&
name
,
const
Type
&
type
)
{
std
::
string
type_mask
=
DestinationMask
(
lang
,
type
,
false
);
// is a typecast needed? (for C# enums and unsigned values in Java)
if
(
type_mask
.
length
()
||
(
lang
.
language
==
GeneratorOptions
::
kCSharp
&&
type
.
enum_def
!=
nullptr
&&
type
.
base_type
!=
BASE_TYPE_UNION
))
{
return
"("
+
GenTypeBasic
(
lang
,
type
)
+
")("
+
name
+
type_mask
+
")"
;
}
else
{
return
name
;
}
}
// Cast statements for mutator method parameters.
// Cast statements for mutator method parameters.
// In Java, parameters representing unsigned numbers need to be cast down to their respective type.
// In Java, parameters representing unsigned numbers need to be cast down to their respective type.
// For example, a long holding an unsigned int value would be cast down to int before being put onto the buffer.
// For example, a long holding an unsigned int value would be cast down to int before being put onto the buffer.
// In C#, one cast directly cast an Enum to its underlying type, which is essential before putting it onto the buffer.
// In C#, one cast directly cast an Enum to its underlying type, which is essential before putting it onto the buffer.
static
std
::
string
SourceCast
(
const
LanguageParameters
&
lang
,
static
std
::
string
SourceCast
(
const
LanguageParameters
&
lang
,
const
Type
&
type
)
{
const
Type
&
type
,
bool
castFromDest
)
{
if
(
type
.
base_type
==
BASE_TYPE_VECTOR
)
{
if
(
type
.
base_type
==
BASE_TYPE_VECTOR
)
{
return
SourceCast
(
lang
,
type
.
VectorType
());
return
SourceCast
(
lang
,
type
.
VectorType
()
,
castFromDest
);
}
else
{
}
else
{
switch
(
lang
.
language
)
{
switch
(
lang
.
language
)
{
case
GeneratorOptions
:
:
kJava
:
case
GeneratorOptions
:
:
kJava
:
if
(
type
.
base_type
==
BASE_TYPE_UINT
)
return
"(int)"
;
if
(
castFromDest
)
{
else
if
(
type
.
base_type
==
BASE_TYPE_USHORT
)
return
"(short)"
;
if
(
type
.
base_type
==
BASE_TYPE_UINT
)
return
"(int)"
;
else
if
(
type
.
base_type
==
BASE_TYPE_UCHAR
)
return
"(byte)"
;
else
if
(
type
.
base_type
==
BASE_TYPE_USHORT
)
return
"(short)"
;
else
if
(
type
.
base_type
==
BASE_TYPE_UCHAR
)
return
"(byte)"
;
}
break
;
break
;
case
GeneratorOptions
:
:
kCSharp
:
case
GeneratorOptions
:
:
kCSharp
:
if
(
type
.
enum_def
!=
nullptr
&&
if
(
IsEnum
(
type
))
return
"("
+
GenTypeBasic
(
lang
,
type
,
false
)
+
")"
;
type
.
base_type
!=
BASE_TYPE_UNION
)
return
"("
+
GenTypeGet
(
lang
,
type
)
+
")"
;
break
;
break
;
default
:
default
:
break
;
break
;
}
}
return
""
;
}
}
return
""
;
}
}
static
std
::
string
GenDefaultValue
(
const
LanguageParameters
&
lang
,
const
Value
&
value
,
bool
for_buffer
)
{
static
std
::
string
SourceCast
(
const
LanguageParameters
&
lang
,
if
(
lang
.
language
==
GeneratorOptions
::
kCSharp
&&
!
for_buffer
)
{
const
Type
&
type
)
{
switch
(
value
.
type
.
base_type
)
{
return
SourceCast
(
lang
,
type
,
true
);
case
BASE_TYPE_STRING
:
}
return
"default(StringOffset)"
;
case
BASE_TYPE_STRUCT
:
return
"default(Offset<"
+
value
.
type
.
struct_def
->
name
+
">)"
;
case
BASE_TYPE_VECTOR
:
return
"default(VectorOffset)"
;
default
:
break
;
}
}
return
value
.
type
.
base_type
==
BASE_TYPE_BOOL
static
std
::
string
SourceCastBasic
(
const
LanguageParameters
&
lang
,
?
(
value
.
constant
==
"0"
?
"false"
:
"true"
)
const
Type
&
type
,
:
value
.
constant
;
bool
castFromDest
)
{
return
IsScalar
(
type
.
base_type
)
?
SourceCast
(
lang
,
type
,
castFromDest
)
:
""
;
}
}
static
std
::
string
GenEnumDefaultValue
(
const
FieldDef
&
field
)
{
static
std
::
string
SourceCastBasic
(
const
LanguageParameters
&
lang
,
auto
enum_def
=
field
.
value
.
type
.
enum_def
;
const
Type
&
type
)
{
return
SourceCastBasic
(
lang
,
type
,
true
);
}
static
std
::
string
GenEnumDefaultValue
(
const
Value
&
value
)
{
auto
enum_def
=
value
.
type
.
enum_def
;
auto
vec
=
enum_def
->
vals
.
vec
;
auto
vec
=
enum_def
->
vals
.
vec
;
auto
default_value
=
StringToInt
(
field
.
value
.
constant
.
c_str
());
auto
default_value
=
StringToInt
(
value
.
constant
.
c_str
());
auto
result
=
field
.
value
.
constant
;
auto
result
=
value
.
constant
;
for
(
auto
it
=
vec
.
begin
();
it
!=
vec
.
end
();
++
it
)
{
for
(
auto
it
=
vec
.
begin
();
it
!=
vec
.
end
();
++
it
)
{
auto
enum_val
=
**
it
;
auto
enum_val
=
**
it
;
if
(
enum_val
.
value
==
default_value
)
{
if
(
enum_val
.
value
==
default_value
)
{
...
@@ -426,6 +403,48 @@ static std::string GenEnumDefaultValue(const FieldDef &field) {
...
@@ -426,6 +403,48 @@ static std::string GenEnumDefaultValue(const FieldDef &field) {
return
result
;
return
result
;
}
}
static
std
::
string
GenDefaultValue
(
const
LanguageParameters
&
lang
,
const
Value
&
value
,
bool
enableLangOverrides
)
{
if
(
enableLangOverrides
)
{
// handles both enum case and vector of enum case
if
(
lang
.
language
==
GeneratorOptions
::
kCSharp
&&
value
.
type
.
enum_def
!=
nullptr
&&
value
.
type
.
base_type
!=
BASE_TYPE_UNION
)
{
return
GenEnumDefaultValue
(
value
);
}
}
return
value
.
type
.
base_type
==
BASE_TYPE_BOOL
?
(
value
.
constant
==
"0"
?
"false"
:
"true"
)
:
value
.
constant
;
}
static
std
::
string
GenDefaultValue
(
const
LanguageParameters
&
lang
,
const
Value
&
value
)
{
return
GenDefaultValue
(
lang
,
value
,
true
);
}
static
std
::
string
GenDefaultValueBasic
(
const
LanguageParameters
&
lang
,
const
Value
&
value
,
bool
enableLangOverrides
)
{
if
(
!
IsScalar
(
value
.
type
.
base_type
))
{
if
(
enableLangOverrides
)
{
if
(
lang
.
language
==
GeneratorOptions
::
kCSharp
)
{
switch
(
value
.
type
.
base_type
)
{
case
BASE_TYPE_STRING
:
return
"default(StringOffset)"
;
case
BASE_TYPE_STRUCT
:
return
"default(Offset<"
+
value
.
type
.
struct_def
->
name
+
">)"
;
case
BASE_TYPE_VECTOR
:
return
"default(VectorOffset)"
;
default
:
break
;
}
}
}
return
"0"
;
}
return
GenDefaultValue
(
lang
,
value
,
enableLangOverrides
);
}
static
std
::
string
GenDefaultValueBasic
(
const
LanguageParameters
&
lang
,
const
Value
&
value
)
{
return
GenDefaultValueBasic
(
lang
,
value
,
true
);
}
static
void
GenEnum
(
const
LanguageParameters
&
lang
,
EnumDef
&
enum_def
,
static
void
GenEnum
(
const
LanguageParameters
&
lang
,
EnumDef
&
enum_def
,
std
::
string
*
code_ptr
)
{
std
::
string
*
code_ptr
)
{
...
@@ -440,7 +459,7 @@ static void GenEnum(const LanguageParameters &lang, EnumDef &enum_def,
...
@@ -440,7 +459,7 @@ static void GenEnum(const LanguageParameters &lang, EnumDef &enum_def,
GenComment
(
enum_def
.
doc_comment
,
code_ptr
,
&
lang
.
comment_config
);
GenComment
(
enum_def
.
doc_comment
,
code_ptr
,
&
lang
.
comment_config
);
code
+=
std
::
string
(
"public "
)
+
lang
.
enum_decl
+
enum_def
.
name
;
code
+=
std
::
string
(
"public "
)
+
lang
.
enum_decl
+
enum_def
.
name
;
if
(
lang
.
language
==
GeneratorOptions
::
kCSharp
)
{
if
(
lang
.
language
==
GeneratorOptions
::
kCSharp
)
{
code
+=
lang
.
inheritance_marker
+
GenTypeBasic
(
lang
,
enum_def
.
underlying_type
);
code
+=
lang
.
inheritance_marker
+
GenTypeBasic
(
lang
,
enum_def
.
underlying_type
,
false
);
}
}
code
+=
lang
.
open_curly
;
code
+=
lang
.
open_curly
;
if
(
lang
.
language
==
GeneratorOptions
::
kJava
)
{
if
(
lang
.
language
==
GeneratorOptions
::
kJava
)
{
...
@@ -454,7 +473,7 @@ static void GenEnum(const LanguageParameters &lang, EnumDef &enum_def,
...
@@ -454,7 +473,7 @@ static void GenEnum(const LanguageParameters &lang, EnumDef &enum_def,
if
(
lang
.
language
!=
GeneratorOptions
::
kCSharp
)
{
if
(
lang
.
language
!=
GeneratorOptions
::
kCSharp
)
{
code
+=
" public static"
;
code
+=
" public static"
;
code
+=
lang
.
const_decl
;
code
+=
lang
.
const_decl
;
code
+=
GenTypeBasic
(
lang
,
enum_def
.
underlying_type
);
code
+=
GenTypeBasic
(
lang
,
enum_def
.
underlying_type
,
false
);
}
}
code
+=
" "
+
ev
.
name
+
" = "
;
code
+=
" "
+
ev
.
name
+
" = "
;
code
+=
NumToString
(
ev
.
value
);
code
+=
NumToString
(
ev
.
value
);
...
@@ -511,8 +530,8 @@ static std::string GenGetter(const LanguageParameters &lang,
...
@@ -511,8 +530,8 @@ static std::string GenGetter(const LanguageParameters &lang,
std
::
string
getter
=
"bb."
+
FunctionStart
(
lang
,
'G'
)
+
"et"
;
std
::
string
getter
=
"bb."
+
FunctionStart
(
lang
,
'G'
)
+
"et"
;
if
(
type
.
base_type
==
BASE_TYPE_BOOL
)
{
if
(
type
.
base_type
==
BASE_TYPE_BOOL
)
{
getter
=
"0!="
+
getter
;
getter
=
"0!="
+
getter
;
}
else
if
(
GenTypeBasic
(
lang
,
type
)
!=
"byte"
)
{
}
else
if
(
GenTypeBasic
(
lang
,
type
,
false
)
!=
"byte"
)
{
getter
+=
MakeCamel
(
GenType
Get
(
lang
,
typ
e
));
getter
+=
MakeCamel
(
GenType
Basic
(
lang
,
type
,
fals
e
));
}
}
return
getter
;
return
getter
;
}
}
...
@@ -525,9 +544,9 @@ static std::string GenSetter(const LanguageParameters &lang,
...
@@ -525,9 +544,9 @@ static std::string GenSetter(const LanguageParameters &lang,
const
Type
&
type
)
{
const
Type
&
type
)
{
if
(
IsScalar
(
type
.
base_type
))
{
if
(
IsScalar
(
type
.
base_type
))
{
std
::
string
setter
=
"bb."
+
FunctionStart
(
lang
,
'P'
)
+
"ut"
;
std
::
string
setter
=
"bb."
+
FunctionStart
(
lang
,
'P'
)
+
"ut"
;
if
(
GenTypeBasic
(
lang
,
type
)
!=
"byte"
&&
if
(
GenTypeBasic
(
lang
,
type
,
false
)
!=
"byte"
&&
type
.
base_type
!=
BASE_TYPE_BOOL
)
{
type
.
base_type
!=
BASE_TYPE_BOOL
)
{
setter
+=
MakeCamel
(
GenType
Get
(
lang
,
typ
e
));
setter
+=
MakeCamel
(
GenType
Basic
(
lang
,
type
,
fals
e
));
}
}
return
setter
;
return
setter
;
}
else
{
}
else
{
...
@@ -538,7 +557,7 @@ static std::string GenSetter(const LanguageParameters &lang,
...
@@ -538,7 +557,7 @@ static std::string GenSetter(const LanguageParameters &lang,
// Returns the method name for use with add/put calls.
// Returns the method name for use with add/put calls.
static
std
::
string
GenMethod
(
const
LanguageParameters
&
lang
,
const
Type
&
type
)
{
static
std
::
string
GenMethod
(
const
LanguageParameters
&
lang
,
const
Type
&
type
)
{
return
IsScalar
(
type
.
base_type
)
return
IsScalar
(
type
.
base_type
)
?
MakeCamel
(
GenTypeBasic
(
lang
,
type
))
?
MakeCamel
(
GenTypeBasic
(
lang
,
type
,
false
))
:
(
IsStruct
(
type
)
?
"Struct"
:
"Offset"
);
:
(
IsStruct
(
type
)
?
"Struct"
:
"Offset"
);
}
}
...
@@ -560,8 +579,7 @@ static void GenStructArgs(const LanguageParameters &lang,
...
@@ -560,8 +579,7 @@ static void GenStructArgs(const LanguageParameters &lang,
(
nameprefix
+
(
field
.
name
+
"_"
)).
c_str
());
(
nameprefix
+
(
field
.
name
+
"_"
)).
c_str
());
}
else
{
}
else
{
code
+=
", "
;
code
+=
", "
;
code
+=
GenTypeForUser
(
lang
,
code
+=
GenTypeBasic
(
lang
,
DestinationType
(
lang
,
field
.
value
.
type
,
false
));
DestinationType
(
lang
,
field
.
value
.
type
,
false
));
code
+=
" "
;
code
+=
" "
;
code
+=
nameprefix
;
code
+=
nameprefix
;
code
+=
MakeCamel
(
field
.
name
,
lang
.
first_camel_upper
);
code
+=
MakeCamel
(
field
.
name
,
lang
.
first_camel_upper
);
...
@@ -592,8 +610,9 @@ static void GenStructBody(const LanguageParameters &lang,
...
@@ -592,8 +610,9 @@ static void GenStructBody(const LanguageParameters &lang,
}
else
{
}
else
{
code
+=
" builder."
+
FunctionStart
(
lang
,
'P'
)
+
"ut"
;
code
+=
" builder."
+
FunctionStart
(
lang
,
'P'
)
+
"ut"
;
code
+=
GenMethod
(
lang
,
field
.
value
.
type
)
+
"("
;
code
+=
GenMethod
(
lang
,
field
.
value
.
type
)
+
"("
;
code
+=
SourceCast
(
lang
,
field
.
value
.
type
);
auto
argname
=
nameprefix
+
MakeCamel
(
field
.
name
,
lang
.
first_camel_upper
);
auto
argname
=
nameprefix
+
MakeCamel
(
field
.
name
,
lang
.
first_camel_upper
);
code
+=
DestinationValue
(
lang
,
argname
,
field
.
value
.
type
)
;
code
+=
argname
;
code
+=
");
\n
"
;
code
+=
");
\n
"
;
}
}
}
}
...
@@ -679,7 +698,7 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser,
...
@@ -679,7 +698,7 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser,
code
+=
"(new "
;
code
+=
"(new "
;
code
+=
type_name
+
"()); } }
\n
"
;
code
+=
type_name
+
"()); } }
\n
"
;
method_start
=
" public "
+
type_name_dest
+
" Get"
+
MakeCamel
(
field
.
name
,
lang
.
first_camel_upper
);
method_start
=
" public "
+
type_name_dest
+
" Get"
+
MakeCamel
(
field
.
name
,
lang
.
first_camel_upper
);
}
}
else
{
else
{
code
+=
method_start
+
"() { return "
;
code
+=
method_start
+
"() { return "
;
code
+=
MakeCamel
(
field
.
name
,
lang
.
first_camel_upper
);
code
+=
MakeCamel
(
field
.
name
,
lang
.
first_camel_upper
);
...
@@ -714,8 +733,17 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser,
...
@@ -714,8 +733,17 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser,
std
::
string
getter
=
dest_cast
+
GenGetter
(
lang
,
field
.
value
.
type
);
std
::
string
getter
=
dest_cast
+
GenGetter
(
lang
,
field
.
value
.
type
);
code
+=
method_start
;
code
+=
method_start
;
std
::
string
default_cast
=
""
;
std
::
string
default_cast
=
""
;
if
(
lang
.
language
==
GeneratorOptions
::
kCSharp
)
// only create default casts for c# scalars or vectors of scalars
default_cast
=
"("
+
type_name_dest
+
")"
;
if
(
lang
.
language
==
GeneratorOptions
::
kCSharp
&&
(
IsScalar
(
field
.
value
.
type
.
base_type
)
||
(
field
.
value
.
type
.
base_type
==
BASE_TYPE_VECTOR
&&
IsScalar
(
field
.
value
.
type
.
element
))))
{
// For scalars, default value will be returned by GetDefaultValue(). If the scalar is an enum, GetDefaultValue()
// returns an actual c# enum that doesn't need to be casted. However, default values for enum elements of
// vectors are integer literals ("0") and are still casted for clarity.
if
(
field
.
value
.
type
.
enum_def
==
nullptr
||
field
.
value
.
type
.
base_type
==
BASE_TYPE_VECTOR
)
{
default_cast
=
"("
+
type_name_dest
+
")"
;
}
}
std
::
string
member_suffix
=
""
;
std
::
string
member_suffix
=
""
;
if
(
IsScalar
(
field
.
value
.
type
.
base_type
))
{
if
(
IsScalar
(
field
.
value
.
type
.
base_type
))
{
code
+=
lang
.
getter_prefix
;
code
+=
lang
.
getter_prefix
;
...
@@ -727,7 +755,7 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser,
...
@@ -727,7 +755,7 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser,
}
else
{
}
else
{
code
+=
offset_prefix
+
getter
;
code
+=
offset_prefix
+
getter
;
code
+=
"(o + bb_pos)"
+
dest_mask
+
" : "
+
default_cast
;
code
+=
"(o + bb_pos)"
+
dest_mask
+
" : "
+
default_cast
;
code
+=
GenDefaultValue
(
lang
,
field
.
value
,
false
);
code
+=
GenDefaultValue
(
lang
,
field
.
value
);
}
}
}
else
{
}
else
{
switch
(
field
.
value
.
type
.
base_type
)
{
switch
(
field
.
value
.
type
.
base_type
)
{
...
@@ -819,13 +847,11 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser,
...
@@ -819,13 +847,11 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser,
auto
mutator_prefix
=
MakeCamel
(
"mutate"
,
lang
.
first_camel_upper
);
auto
mutator_prefix
=
MakeCamel
(
"mutate"
,
lang
.
first_camel_upper
);
//a vector mutator also needs the index of the vector element it should mutate
//a vector mutator also needs the index of the vector element it should mutate
auto
mutator_params
=
(
field
.
value
.
type
.
base_type
==
BASE_TYPE_VECTOR
?
"(int j, "
:
"("
)
+
auto
mutator_params
=
(
field
.
value
.
type
.
base_type
==
BASE_TYPE_VECTOR
?
"(int j, "
:
"("
)
+
GenTypeNameDest
(
lang
,
underlying_type
)
+
" "
+
GenTypeNameDest
(
lang
,
underlying_type
)
+
" "
+
field
.
name
+
") { "
;
field
.
name
+
") { "
;
auto
setter_index
=
field
.
value
.
type
.
base_type
==
BASE_TYPE_VECTOR
auto
setter_index
=
field
.
value
.
type
.
base_type
==
BASE_TYPE_VECTOR
?
"__vector(o) + j * "
+
NumToString
(
InlineSize
(
underlying_type
))
?
"__vector(o) + j * "
+
NumToString
(
InlineSize
(
underlying_type
))
:
(
struct_def
.
fixed
?
"bb_pos + "
+
NumToString
(
field
.
value
.
offset
)
:
"o + bb_pos"
);
:
(
struct_def
.
fixed
?
"bb_pos + "
+
NumToString
(
field
.
value
.
offset
)
:
"o + bb_pos"
);
if
(
IsScalar
(
field
.
value
.
type
.
base_type
)
||
if
(
IsScalar
(
field
.
value
.
type
.
base_type
)
||
(
field
.
value
.
type
.
base_type
==
BASE_TYPE_VECTOR
&&
(
field
.
value
.
type
.
base_type
==
BASE_TYPE_VECTOR
&&
IsScalar
(
field
.
value
.
type
.
VectorType
().
base_type
)))
{
IsScalar
(
field
.
value
.
type
.
VectorType
().
base_type
)))
{
...
@@ -883,23 +909,16 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser,
...
@@ -883,23 +909,16 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser,
auto
&
field
=
**
it
;
auto
&
field
=
**
it
;
if
(
field
.
deprecated
)
continue
;
if
(
field
.
deprecated
)
continue
;
code
+=
",
\n
"
;
code
+=
",
\n
"
;
code
+=
GenTypeForUser
(
lang
,
code
+=
GenTypeBasic
(
lang
,
DestinationType
(
lang
,
field
.
value
.
type
,
false
));
DestinationType
(
lang
,
field
.
value
.
type
,
false
));
code
+=
" "
;
code
+=
" "
;
code
+=
field
.
name
;
code
+=
field
.
name
;
if
(
!
IsScalar
(
field
.
value
.
type
.
base_type
))
code
+=
"Offset"
;
// Java doesn't have defaults, which means this method must always
// Java doesn't have defaults, which means this method must always
// supply all arguments, and thus won't compile when fields are added.
// supply all arguments, and thus won't compile when fields are added.
if
(
lang
.
language
!=
GeneratorOptions
::
kJava
)
{
if
(
lang
.
language
!=
GeneratorOptions
::
kJava
)
{
code
+=
" = "
;
code
+=
" = "
;
// in C#, enum values have their own type, but Unity (specifically .Net 3.5) can't
code
+=
GenDefaultValueBasic
(
lang
,
field
.
value
);
// cast enum type from numeric value.
if
(
lang
.
language
==
GeneratorOptions
::
kCSharp
&&
field
.
value
.
type
.
enum_def
!=
nullptr
&&
field
.
value
.
type
.
base_type
!=
BASE_TYPE_UNION
)
{
code
+=
GenEnumDefaultValue
(
field
);
}
else
{
code
+=
GenDefaultValue
(
lang
,
field
.
value
,
false
);
}
}
}
}
}
code
+=
") {
\n
builder."
;
code
+=
") {
\n
builder."
;
...
@@ -916,7 +935,9 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser,
...
@@ -916,7 +935,9 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser,
size
==
SizeOf
(
field
.
value
.
type
.
base_type
)))
{
size
==
SizeOf
(
field
.
value
.
type
.
base_type
)))
{
code
+=
" "
+
struct_def
.
name
+
"."
;
code
+=
" "
+
struct_def
.
name
+
"."
;
code
+=
FunctionStart
(
lang
,
'A'
)
+
"dd"
;
code
+=
FunctionStart
(
lang
,
'A'
)
+
"dd"
;
code
+=
MakeCamel
(
field
.
name
)
+
"(builder, "
+
field
.
name
+
");
\n
"
;
code
+=
MakeCamel
(
field
.
name
)
+
"(builder, "
+
field
.
name
;
if
(
!
IsScalar
(
field
.
value
.
type
.
base_type
))
code
+=
"Offset"
;
code
+=
");
\n
"
;
}
}
}
}
}
}
...
@@ -941,18 +962,18 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser,
...
@@ -941,18 +962,18 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser,
code
+=
" public static void "
+
FunctionStart
(
lang
,
'A'
)
+
"dd"
;
code
+=
" public static void "
+
FunctionStart
(
lang
,
'A'
)
+
"dd"
;
code
+=
MakeCamel
(
field
.
name
);
code
+=
MakeCamel
(
field
.
name
);
code
+=
"(FlatBufferBuilder builder, "
;
code
+=
"(FlatBufferBuilder builder, "
;
code
+=
GenTypeForUser
(
lang
,
code
+=
GenTypeBasic
(
lang
,
DestinationType
(
lang
,
field
.
value
.
type
,
false
));
DestinationType
(
lang
,
field
.
value
.
type
,
false
));
auto
argname
=
MakeCamel
(
field
.
name
,
false
);
auto
argname
=
MakeCamel
(
field
.
name
,
false
);
if
(
!
IsScalar
(
field
.
value
.
type
.
base_type
))
argname
+=
"Offset"
;
if
(
!
IsScalar
(
field
.
value
.
type
.
base_type
))
argname
+=
"Offset"
;
code
+=
" "
+
argname
+
") { builder."
+
FunctionStart
(
lang
,
'A'
)
+
"dd"
;
code
+=
" "
+
argname
+
") { builder."
+
FunctionStart
(
lang
,
'A'
)
+
"dd"
;
code
+=
GenMethod
(
lang
,
field
.
value
.
type
)
+
"("
;
code
+=
GenMethod
(
lang
,
field
.
value
.
type
)
+
"("
;
code
+=
NumToString
(
it
-
struct_def
.
fields
.
vec
.
begin
())
+
", "
;
code
+=
NumToString
(
it
-
struct_def
.
fields
.
vec
.
begin
())
+
", "
;
code
+=
DestinationValue
(
lang
,
argname
,
field
.
value
.
type
);
code
+=
SourceCastBasic
(
lang
,
field
.
value
.
type
);
code
+=
argname
;
if
(
!
IsScalar
(
field
.
value
.
type
.
base_type
)
&&
field
.
value
.
type
.
base_type
!=
BASE_TYPE_UNION
&&
lang
.
language
==
GeneratorOptions
::
kCSharp
)
{
if
(
!
IsScalar
(
field
.
value
.
type
.
base_type
)
&&
field
.
value
.
type
.
base_type
!=
BASE_TYPE_UNION
&&
lang
.
language
==
GeneratorOptions
::
kCSharp
)
{
code
+=
".Value"
;
code
+=
".Value"
;
}
}
code
+=
", "
+
GenDefaultValue
(
lang
,
field
.
value
,
tru
e
);
code
+=
", "
+
GenDefaultValue
(
lang
,
field
.
value
,
fals
e
);
code
+=
"); }
\n
"
;
code
+=
"); }
\n
"
;
if
(
field
.
value
.
type
.
base_type
==
BASE_TYPE_VECTOR
)
{
if
(
field
.
value
.
type
.
base_type
==
BASE_TYPE_VECTOR
)
{
auto
vector_type
=
field
.
value
.
type
.
VectorType
();
auto
vector_type
=
field
.
value
.
type
.
VectorType
();
...
@@ -972,10 +993,12 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser,
...
@@ -972,10 +993,12 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser,
code
+=
FunctionStart
(
lang
,
'L'
)
+
"ength - 1; i >= 0; i--) builder."
;
code
+=
FunctionStart
(
lang
,
'L'
)
+
"ength - 1; i >= 0; i--) builder."
;
code
+=
FunctionStart
(
lang
,
'A'
)
+
"dd"
;
code
+=
FunctionStart
(
lang
,
'A'
)
+
"dd"
;
code
+=
GenMethod
(
lang
,
vector_type
);
code
+=
GenMethod
(
lang
,
vector_type
);
code
+=
"(data[i]"
;
code
+=
"("
;
if
(
lang
.
language
==
GeneratorOptions
::
kCSharp
&&
code
+=
SourceCastBasic
(
lang
,
vector_type
,
false
);
(
vector_type
.
base_type
==
BASE_TYPE_STRUCT
||
vector_type
.
base_type
==
BASE_TYPE_STRING
))
code
+=
"data[i]"
;
code
+=
".Value"
;
if
(
lang
.
language
==
GeneratorOptions
::
kCSharp
&&
(
vector_type
.
base_type
==
BASE_TYPE_STRUCT
||
vector_type
.
base_type
==
BASE_TYPE_STRING
))
code
+=
".Value"
;
code
+=
"); return "
;
code
+=
"); return "
;
code
+=
"builder."
+
FunctionStart
(
lang
,
'E'
)
+
"ndVector(); }
\n
"
;
code
+=
"builder."
+
FunctionStart
(
lang
,
'E'
)
+
"ndVector(); }
\n
"
;
}
}
...
...
tests/MyGame/Example/Monster.cs
View file @
e10b8d6f
...
@@ -22,9 +22,9 @@ public sealed class Monster : Table {
...
@@ -22,9 +22,9 @@ public sealed class Monster : Table {
public
byte
GetInventory
(
int
j
)
{
int
o
=
__offset
(
14
);
return
o
!=
0
?
bb
.
Get
(
__vector
(
o
)
+
j
*
1
)
:
(
byte
)
0
;
}
public
byte
GetInventory
(
int
j
)
{
int
o
=
__offset
(
14
);
return
o
!=
0
?
bb
.
Get
(
__vector
(
o
)
+
j
*
1
)
:
(
byte
)
0
;
}
public
int
InventoryLength
{
get
{
int
o
=
__offset
(
14
);
return
o
!=
0
?
__vector_len
(
o
)
:
0
;
}
}
public
int
InventoryLength
{
get
{
int
o
=
__offset
(
14
);
return
o
!=
0
?
__vector_len
(
o
)
:
0
;
}
}
public
bool
MutateInventory
(
int
j
,
byte
inventory
)
{
int
o
=
__offset
(
14
);
if
(
o
!=
0
)
{
bb
.
Put
(
__vector
(
o
)
+
j
*
1
,
inventory
);
return
true
;
}
else
{
return
false
;
}
}
public
bool
MutateInventory
(
int
j
,
byte
inventory
)
{
int
o
=
__offset
(
14
);
if
(
o
!=
0
)
{
bb
.
Put
(
__vector
(
o
)
+
j
*
1
,
inventory
);
return
true
;
}
else
{
return
false
;
}
}
public
Color
Color
{
get
{
int
o
=
__offset
(
16
);
return
o
!=
0
?
(
Color
)
bb
.
GetSbyte
(
o
+
bb_pos
)
:
(
Color
)
8
;
}
}
public
Color
Color
{
get
{
int
o
=
__offset
(
16
);
return
o
!=
0
?
(
Color
)
bb
.
GetSbyte
(
o
+
bb_pos
)
:
Color
.
Blue
;
}
}
public
bool
MutateColor
(
Color
color
)
{
int
o
=
__offset
(
16
);
if
(
o
!=
0
)
{
bb
.
PutSbyte
(
o
+
bb_pos
,
(
sbyte
)
color
);
return
true
;
}
else
{
return
false
;
}
}
public
bool
MutateColor
(
Color
color
)
{
int
o
=
__offset
(
16
);
if
(
o
!=
0
)
{
bb
.
PutSbyte
(
o
+
bb_pos
,
(
sbyte
)
color
);
return
true
;
}
else
{
return
false
;
}
}
public
Any
TestType
{
get
{
int
o
=
__offset
(
18
);
return
o
!=
0
?
(
Any
)
bb
.
Get
(
o
+
bb_pos
)
:
(
Any
)
0
;
}
}
public
Any
TestType
{
get
{
int
o
=
__offset
(
18
);
return
o
!=
0
?
(
Any
)
bb
.
Get
(
o
+
bb_pos
)
:
Any
.
NONE
;
}
}
public
bool
MutateTestType
(
Any
test_type
)
{
int
o
=
__offset
(
18
);
if
(
o
!=
0
)
{
bb
.
Put
(
o
+
bb_pos
,
(
byte
)
test_type
);
return
true
;
}
else
{
return
false
;
}
}
public
bool
MutateTestType
(
Any
test_type
)
{
int
o
=
__offset
(
18
);
if
(
o
!=
0
)
{
bb
.
Put
(
o
+
bb_pos
,
(
byte
)
test_type
);
return
true
;
}
else
{
return
false
;
}
}
public
TTable
GetTest
<
TTable
>(
TTable
obj
)
where
TTable
:
Table
{
int
o
=
__offset
(
20
);
return
o
!=
0
?
__union
(
obj
,
o
)
:
null
;
}
public
TTable
GetTest
<
TTable
>(
TTable
obj
)
where
TTable
:
Table
{
int
o
=
__offset
(
20
);
return
o
!=
0
?
__union
(
obj
,
o
)
:
null
;
}
public
Test
GetTest4
(
int
j
)
{
return
GetTest4
(
new
Test
(),
j
);
}
public
Test
GetTest4
(
int
j
)
{
return
GetTest4
(
new
Test
(),
j
);
}
...
@@ -74,8 +74,8 @@ public sealed class Monster : Table {
...
@@ -74,8 +74,8 @@ public sealed class Monster : Table {
public
static
void
AddInventory
(
FlatBufferBuilder
builder
,
VectorOffset
inventoryOffset
)
{
builder
.
AddOffset
(
5
,
inventoryOffset
.
Value
,
0
);
}
public
static
void
AddInventory
(
FlatBufferBuilder
builder
,
VectorOffset
inventoryOffset
)
{
builder
.
AddOffset
(
5
,
inventoryOffset
.
Value
,
0
);
}
public
static
VectorOffset
CreateInventoryVector
(
FlatBufferBuilder
builder
,
byte
[]
data
)
{
builder
.
StartVector
(
1
,
data
.
Length
,
1
);
for
(
int
i
=
data
.
Length
-
1
;
i
>=
0
;
i
--)
builder
.
AddByte
(
data
[
i
]);
return
builder
.
EndVector
();
}
public
static
VectorOffset
CreateInventoryVector
(
FlatBufferBuilder
builder
,
byte
[]
data
)
{
builder
.
StartVector
(
1
,
data
.
Length
,
1
);
for
(
int
i
=
data
.
Length
-
1
;
i
>=
0
;
i
--)
builder
.
AddByte
(
data
[
i
]);
return
builder
.
EndVector
();
}
public
static
void
StartInventoryVector
(
FlatBufferBuilder
builder
,
int
numElems
)
{
builder
.
StartVector
(
1
,
numElems
,
1
);
}
public
static
void
StartInventoryVector
(
FlatBufferBuilder
builder
,
int
numElems
)
{
builder
.
StartVector
(
1
,
numElems
,
1
);
}
public
static
void
AddColor
(
FlatBufferBuilder
builder
,
Color
color
)
{
builder
.
AddSbyte
(
6
,
(
sbyte
)
(
color
)
,
8
);
}
public
static
void
AddColor
(
FlatBufferBuilder
builder
,
Color
color
)
{
builder
.
AddSbyte
(
6
,
(
sbyte
)
color
,
8
);
}
public
static
void
AddTestType
(
FlatBufferBuilder
builder
,
Any
testType
)
{
builder
.
AddByte
(
7
,
(
byte
)
(
testType
)
,
0
);
}
public
static
void
AddTestType
(
FlatBufferBuilder
builder
,
Any
testType
)
{
builder
.
AddByte
(
7
,
(
byte
)
testType
,
0
);
}
public
static
void
AddTest
(
FlatBufferBuilder
builder
,
int
testOffset
)
{
builder
.
AddOffset
(
8
,
testOffset
,
0
);
}
public
static
void
AddTest
(
FlatBufferBuilder
builder
,
int
testOffset
)
{
builder
.
AddOffset
(
8
,
testOffset
,
0
);
}
public
static
void
AddTest4
(
FlatBufferBuilder
builder
,
VectorOffset
test4Offset
)
{
builder
.
AddOffset
(
9
,
test4Offset
.
Value
,
0
);
}
public
static
void
AddTest4
(
FlatBufferBuilder
builder
,
VectorOffset
test4Offset
)
{
builder
.
AddOffset
(
9
,
test4Offset
.
Value
,
0
);
}
public
static
void
StartTest4Vector
(
FlatBufferBuilder
builder
,
int
numElems
)
{
builder
.
StartVector
(
4
,
numElems
,
2
);
}
public
static
void
StartTest4Vector
(
FlatBufferBuilder
builder
,
int
numElems
)
{
builder
.
StartVector
(
4
,
numElems
,
2
);
}
...
...
tests/MyGame/Example/Monster.java
View file @
e10b8d6f
...
@@ -103,11 +103,11 @@ public final class Monster extends Table {
...
@@ -103,11 +103,11 @@ public final class Monster extends Table {
public
static
void
addTestempty
(
FlatBufferBuilder
builder
,
int
testemptyOffset
)
{
builder
.
addOffset
(
14
,
testemptyOffset
,
0
);
}
public
static
void
addTestempty
(
FlatBufferBuilder
builder
,
int
testemptyOffset
)
{
builder
.
addOffset
(
14
,
testemptyOffset
,
0
);
}
public
static
void
addTestbool
(
FlatBufferBuilder
builder
,
boolean
testbool
)
{
builder
.
addBoolean
(
15
,
testbool
,
false
);
}
public
static
void
addTestbool
(
FlatBufferBuilder
builder
,
boolean
testbool
)
{
builder
.
addBoolean
(
15
,
testbool
,
false
);
}
public
static
void
addTesthashs32Fnv1
(
FlatBufferBuilder
builder
,
int
testhashs32Fnv1
)
{
builder
.
addInt
(
16
,
testhashs32Fnv1
,
0
);
}
public
static
void
addTesthashs32Fnv1
(
FlatBufferBuilder
builder
,
int
testhashs32Fnv1
)
{
builder
.
addInt
(
16
,
testhashs32Fnv1
,
0
);
}
public
static
void
addTesthashu32Fnv1
(
FlatBufferBuilder
builder
,
long
testhashu32Fnv1
)
{
builder
.
addInt
(
17
,
(
int
)
(
testhashu32Fnv1
&
0xFFFFFFFF
L
)
,
0
);
}
public
static
void
addTesthashu32Fnv1
(
FlatBufferBuilder
builder
,
long
testhashu32Fnv1
)
{
builder
.
addInt
(
17
,
(
int
)
testhashu32Fnv1
,
0
);
}
public
static
void
addTesthashs64Fnv1
(
FlatBufferBuilder
builder
,
long
testhashs64Fnv1
)
{
builder
.
addLong
(
18
,
testhashs64Fnv1
,
0
);
}
public
static
void
addTesthashs64Fnv1
(
FlatBufferBuilder
builder
,
long
testhashs64Fnv1
)
{
builder
.
addLong
(
18
,
testhashs64Fnv1
,
0
);
}
public
static
void
addTesthashu64Fnv1
(
FlatBufferBuilder
builder
,
long
testhashu64Fnv1
)
{
builder
.
addLong
(
19
,
testhashu64Fnv1
,
0
);
}
public
static
void
addTesthashu64Fnv1
(
FlatBufferBuilder
builder
,
long
testhashu64Fnv1
)
{
builder
.
addLong
(
19
,
testhashu64Fnv1
,
0
);
}
public
static
void
addTesthashs32Fnv1a
(
FlatBufferBuilder
builder
,
int
testhashs32Fnv1a
)
{
builder
.
addInt
(
20
,
testhashs32Fnv1a
,
0
);
}
public
static
void
addTesthashs32Fnv1a
(
FlatBufferBuilder
builder
,
int
testhashs32Fnv1a
)
{
builder
.
addInt
(
20
,
testhashs32Fnv1a
,
0
);
}
public
static
void
addTesthashu32Fnv1a
(
FlatBufferBuilder
builder
,
long
testhashu32Fnv1a
)
{
builder
.
addInt
(
21
,
(
int
)
(
testhashu32Fnv1a
&
0xFFFFFFFF
L
)
,
0
);
}
public
static
void
addTesthashu32Fnv1a
(
FlatBufferBuilder
builder
,
long
testhashu32Fnv1a
)
{
builder
.
addInt
(
21
,
(
int
)
testhashu32Fnv1a
,
0
);
}
public
static
void
addTesthashs64Fnv1a
(
FlatBufferBuilder
builder
,
long
testhashs64Fnv1a
)
{
builder
.
addLong
(
22
,
testhashs64Fnv1a
,
0
);
}
public
static
void
addTesthashs64Fnv1a
(
FlatBufferBuilder
builder
,
long
testhashs64Fnv1a
)
{
builder
.
addLong
(
22
,
testhashs64Fnv1a
,
0
);
}
public
static
void
addTesthashu64Fnv1a
(
FlatBufferBuilder
builder
,
long
testhashu64Fnv1a
)
{
builder
.
addLong
(
23
,
testhashu64Fnv1a
,
0
);
}
public
static
void
addTesthashu64Fnv1a
(
FlatBufferBuilder
builder
,
long
testhashu64Fnv1a
)
{
builder
.
addLong
(
23
,
testhashu64Fnv1a
,
0
);
}
public
static
void
addTestarrayofbools
(
FlatBufferBuilder
builder
,
int
testarrayofboolsOffset
)
{
builder
.
addOffset
(
24
,
testarrayofboolsOffset
,
0
);
}
public
static
void
addTestarrayofbools
(
FlatBufferBuilder
builder
,
int
testarrayofboolsOffset
)
{
builder
.
addOffset
(
24
,
testarrayofboolsOffset
,
0
);
}
...
...
tests/MyGame/Example/Stat.cs
View file @
e10b8d6f
...
@@ -17,12 +17,12 @@ public sealed class Stat : Table {
...
@@ -17,12 +17,12 @@ public sealed class Stat : Table {
public
bool
MutateCount
(
ushort
count
)
{
int
o
=
__offset
(
8
);
if
(
o
!=
0
)
{
bb
.
PutUshort
(
o
+
bb_pos
,
count
);
return
true
;
}
else
{
return
false
;
}
}
public
bool
MutateCount
(
ushort
count
)
{
int
o
=
__offset
(
8
);
if
(
o
!=
0
)
{
bb
.
PutUshort
(
o
+
bb_pos
,
count
);
return
true
;
}
else
{
return
false
;
}
}
public
static
Offset
<
Stat
>
CreateStat
(
FlatBufferBuilder
builder
,
public
static
Offset
<
Stat
>
CreateStat
(
FlatBufferBuilder
builder
,
StringOffset
id
=
default
(
StringOffset
),
StringOffset
id
Offset
=
default
(
StringOffset
),
long
val
=
0
,
long
val
=
0
,
ushort
count
=
0
)
{
ushort
count
=
0
)
{
builder
.
StartObject
(
3
);
builder
.
StartObject
(
3
);
Stat
.
AddVal
(
builder
,
val
);
Stat
.
AddVal
(
builder
,
val
);
Stat
.
AddId
(
builder
,
id
);
Stat
.
AddId
(
builder
,
id
Offset
);
Stat
.
AddCount
(
builder
,
count
);
Stat
.
AddCount
(
builder
,
count
);
return
Stat
.
EndStat
(
builder
);
return
Stat
.
EndStat
(
builder
);
}
}
...
...
tests/MyGame/Example/Stat.java
View file @
e10b8d6f
...
@@ -21,12 +21,12 @@ public final class Stat extends Table {
...
@@ -21,12 +21,12 @@ public final class Stat extends Table {
public
boolean
mutateCount
(
int
count
)
{
int
o
=
__offset
(
8
);
if
(
o
!=
0
)
{
bb
.
putShort
(
o
+
bb_pos
,
(
short
)
count
);
return
true
;
}
else
{
return
false
;
}
}
public
boolean
mutateCount
(
int
count
)
{
int
o
=
__offset
(
8
);
if
(
o
!=
0
)
{
bb
.
putShort
(
o
+
bb_pos
,
(
short
)
count
);
return
true
;
}
else
{
return
false
;
}
}
public
static
int
createStat
(
FlatBufferBuilder
builder
,
public
static
int
createStat
(
FlatBufferBuilder
builder
,
int
id
,
int
id
Offset
,
long
val
,
long
val
,
int
count
)
{
int
count
)
{
builder
.
startObject
(
3
);
builder
.
startObject
(
3
);
Stat
.
addVal
(
builder
,
val
);
Stat
.
addVal
(
builder
,
val
);
Stat
.
addId
(
builder
,
id
);
Stat
.
addId
(
builder
,
id
Offset
);
Stat
.
addCount
(
builder
,
count
);
Stat
.
addCount
(
builder
,
count
);
return
Stat
.
endStat
(
builder
);
return
Stat
.
endStat
(
builder
);
}
}
...
@@ -34,7 +34,7 @@ public final class Stat extends Table {
...
@@ -34,7 +34,7 @@ public final class Stat extends Table {
public
static
void
startStat
(
FlatBufferBuilder
builder
)
{
builder
.
startObject
(
3
);
}
public
static
void
startStat
(
FlatBufferBuilder
builder
)
{
builder
.
startObject
(
3
);
}
public
static
void
addId
(
FlatBufferBuilder
builder
,
int
idOffset
)
{
builder
.
addOffset
(
0
,
idOffset
,
0
);
}
public
static
void
addId
(
FlatBufferBuilder
builder
,
int
idOffset
)
{
builder
.
addOffset
(
0
,
idOffset
,
0
);
}
public
static
void
addVal
(
FlatBufferBuilder
builder
,
long
val
)
{
builder
.
addLong
(
1
,
val
,
0
);
}
public
static
void
addVal
(
FlatBufferBuilder
builder
,
long
val
)
{
builder
.
addLong
(
1
,
val
,
0
);
}
public
static
void
addCount
(
FlatBufferBuilder
builder
,
int
count
)
{
builder
.
addShort
(
2
,
(
short
)
(
count
&
0xFFFF
)
,
0
);
}
public
static
void
addCount
(
FlatBufferBuilder
builder
,
int
count
)
{
builder
.
addShort
(
2
,
(
short
)
count
,
0
);
}
public
static
int
endStat
(
FlatBufferBuilder
builder
)
{
public
static
int
endStat
(
FlatBufferBuilder
builder
)
{
int
o
=
builder
.
endObject
();
int
o
=
builder
.
endObject
();
return
o
;
return
o
;
...
...
tests/MyGame/Example/TestSimpleTableWithEnum.cs
View file @
e10b8d6f
...
@@ -10,7 +10,7 @@ public sealed class TestSimpleTableWithEnum : Table {
...
@@ -10,7 +10,7 @@ public sealed class TestSimpleTableWithEnum : Table {
public
static
TestSimpleTableWithEnum
GetRootAsTestSimpleTableWithEnum
(
ByteBuffer
_bb
,
TestSimpleTableWithEnum
obj
)
{
return
(
obj
.
__init
(
_bb
.
GetInt
(
_bb
.
Position
)
+
_bb
.
Position
,
_bb
));
}
public
static
TestSimpleTableWithEnum
GetRootAsTestSimpleTableWithEnum
(
ByteBuffer
_bb
,
TestSimpleTableWithEnum
obj
)
{
return
(
obj
.
__init
(
_bb
.
GetInt
(
_bb
.
Position
)
+
_bb
.
Position
,
_bb
));
}
public
TestSimpleTableWithEnum
__init
(
int
_i
,
ByteBuffer
_bb
)
{
bb_pos
=
_i
;
bb
=
_bb
;
return
this
;
}
public
TestSimpleTableWithEnum
__init
(
int
_i
,
ByteBuffer
_bb
)
{
bb_pos
=
_i
;
bb
=
_bb
;
return
this
;
}
public
Color
Color
{
get
{
int
o
=
__offset
(
4
);
return
o
!=
0
?
(
Color
)
bb
.
GetSbyte
(
o
+
bb_pos
)
:
(
Color
)
2
;
}
}
public
Color
Color
{
get
{
int
o
=
__offset
(
4
);
return
o
!=
0
?
(
Color
)
bb
.
GetSbyte
(
o
+
bb_pos
)
:
Color
.
Green
;
}
}
public
bool
MutateColor
(
Color
color
)
{
int
o
=
__offset
(
4
);
if
(
o
!=
0
)
{
bb
.
PutSbyte
(
o
+
bb_pos
,
(
sbyte
)
color
);
return
true
;
}
else
{
return
false
;
}
}
public
bool
MutateColor
(
Color
color
)
{
int
o
=
__offset
(
4
);
if
(
o
!=
0
)
{
bb
.
PutSbyte
(
o
+
bb_pos
,
(
sbyte
)
color
);
return
true
;
}
else
{
return
false
;
}
}
public
static
Offset
<
TestSimpleTableWithEnum
>
CreateTestSimpleTableWithEnum
(
FlatBufferBuilder
builder
,
public
static
Offset
<
TestSimpleTableWithEnum
>
CreateTestSimpleTableWithEnum
(
FlatBufferBuilder
builder
,
...
@@ -21,7 +21,7 @@ public sealed class TestSimpleTableWithEnum : Table {
...
@@ -21,7 +21,7 @@ public sealed class TestSimpleTableWithEnum : Table {
}
}
public
static
void
StartTestSimpleTableWithEnum
(
FlatBufferBuilder
builder
)
{
builder
.
StartObject
(
1
);
}
public
static
void
StartTestSimpleTableWithEnum
(
FlatBufferBuilder
builder
)
{
builder
.
StartObject
(
1
);
}
public
static
void
AddColor
(
FlatBufferBuilder
builder
,
Color
color
)
{
builder
.
AddSbyte
(
0
,
(
sbyte
)
(
color
)
,
2
);
}
public
static
void
AddColor
(
FlatBufferBuilder
builder
,
Color
color
)
{
builder
.
AddSbyte
(
0
,
(
sbyte
)
color
,
2
);
}
public
static
Offset
<
TestSimpleTableWithEnum
>
EndTestSimpleTableWithEnum
(
FlatBufferBuilder
builder
)
{
public
static
Offset
<
TestSimpleTableWithEnum
>
EndTestSimpleTableWithEnum
(
FlatBufferBuilder
builder
)
{
int
o
=
builder
.
EndObject
();
int
o
=
builder
.
EndObject
();
return
new
Offset
<
TestSimpleTableWithEnum
>(
o
);
return
new
Offset
<
TestSimpleTableWithEnum
>(
o
);
...
...
tests/MyGame/Example/Vec3.cs
View file @
e10b8d6f
...
@@ -29,7 +29,7 @@ public sealed class Vec3 : Struct {
...
@@ -29,7 +29,7 @@ public sealed class Vec3 : Struct {
builder
.
PutSbyte
(
test3_B
);
builder
.
PutSbyte
(
test3_B
);
builder
.
PutShort
(
test3_A
);
builder
.
PutShort
(
test3_A
);
builder
.
Pad
(
1
);
builder
.
Pad
(
1
);
builder
.
PutSbyte
((
sbyte
)
(
Test2
)
);
builder
.
PutSbyte
((
sbyte
)
Test2
);
builder
.
PutDouble
(
Test1
);
builder
.
PutDouble
(
Test1
);
builder
.
Pad
(
4
);
builder
.
Pad
(
4
);
builder
.
PutFloat
(
Z
);
builder
.
PutFloat
(
Z
);
...
...
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