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
a4c362a1
Commit
a4c362a1
authored
Oct 08, 2018
by
kostya-sh
Committed by
Wouter van Oortmerssen
Oct 08, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use enum types in generated read/mutate methods for Go (#4978)
parent
7c3c0272
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
16 additions
and
9 deletions
+16
-9
idl_gen_go.cpp
src/idl_gen_go.cpp
+4
-1
Monster.go
tests/MyGame/Example/Monster.go
+2
-2
TestSimpleTableWithEnum.go
tests/MyGame/Example/TestSimpleTableWithEnum.go
+2
-2
Vec3.go
tests/MyGame/Example/Vec3.go
+2
-2
go_test.go
tests/go_test.go
+4
-0
TableInFirstNS.go
tests/namespace_test/NamespaceA/TableInFirstNS.go
+2
-2
No files found.
src/idl_gen_go.cpp
View file @
a4c362a1
...
...
@@ -675,7 +675,7 @@ static std::string GenGetter(const Type &type) {
case
BASE_TYPE_STRING
:
return
"rcv._tab.ByteVector"
;
case
BASE_TYPE_UNION
:
return
"rcv._tab.Union"
;
case
BASE_TYPE_VECTOR
:
return
GenGetter
(
type
.
VectorType
());
default
:
return
"rcv._tab.Get"
+
MakeCamel
(
GenType
Get
(
type
));
default
:
return
"rcv._tab.Get"
+
MakeCamel
(
GenType
Basic
(
type
));
}
}
...
...
@@ -711,6 +711,9 @@ static std::string GenTypePointer(const Type &type) {
}
static
std
::
string
GenTypeGet
(
const
Type
&
type
)
{
if
(
type
.
enum_def
!=
nullptr
&&
!
type
.
enum_def
->
is_union
)
{
return
GetEnumTypeName
(
*
type
.
enum_def
);
}
return
IsScalar
(
type
.
base_type
)
?
GenTypeBasic
(
type
)
:
GenTypePointer
(
type
);
}
...
...
tests/MyGame/Example/Monster.go
View file @
a4c362a1
...
...
@@ -97,7 +97,7 @@ func (rcv *Monster) InventoryBytes() []byte {
return
nil
}
func
(
rcv
*
Monster
)
Color
()
int8
{
func
(
rcv
*
Monster
)
Color
()
Color
{
o
:=
flatbuffers
.
UOffsetT
(
rcv
.
_tab
.
Offset
(
16
))
if
o
!=
0
{
return
rcv
.
_tab
.
GetInt8
(
o
+
rcv
.
_tab
.
Pos
)
...
...
@@ -105,7 +105,7 @@ func (rcv *Monster) Color() int8 {
return
8
}
func
(
rcv
*
Monster
)
MutateColor
(
n
int8
)
bool
{
func
(
rcv
*
Monster
)
MutateColor
(
n
Color
)
bool
{
return
rcv
.
_tab
.
MutateInt8Slot
(
16
,
n
)
}
...
...
tests/MyGame/Example/TestSimpleTableWithEnum.go
View file @
a4c362a1
...
...
@@ -26,7 +26,7 @@ func (rcv *TestSimpleTableWithEnum) Table() flatbuffers.Table {
return
rcv
.
_tab
}
func
(
rcv
*
TestSimpleTableWithEnum
)
Color
()
int8
{
func
(
rcv
*
TestSimpleTableWithEnum
)
Color
()
Color
{
o
:=
flatbuffers
.
UOffsetT
(
rcv
.
_tab
.
Offset
(
4
))
if
o
!=
0
{
return
rcv
.
_tab
.
GetInt8
(
o
+
rcv
.
_tab
.
Pos
)
...
...
@@ -34,7 +34,7 @@ func (rcv *TestSimpleTableWithEnum) Color() int8 {
return
2
}
func
(
rcv
*
TestSimpleTableWithEnum
)
MutateColor
(
n
int8
)
bool
{
func
(
rcv
*
TestSimpleTableWithEnum
)
MutateColor
(
n
Color
)
bool
{
return
rcv
.
_tab
.
MutateInt8Slot
(
4
,
n
)
}
...
...
tests/MyGame/Example/Vec3.go
View file @
a4c362a1
...
...
@@ -47,10 +47,10 @@ func (rcv *Vec3) MutateTest1(n float64) bool {
return
rcv
.
_tab
.
MutateFloat64
(
rcv
.
_tab
.
Pos
+
flatbuffers
.
UOffsetT
(
16
),
n
)
}
func
(
rcv
*
Vec3
)
Test2
()
int8
{
func
(
rcv
*
Vec3
)
Test2
()
Color
{
return
rcv
.
_tab
.
GetInt8
(
rcv
.
_tab
.
Pos
+
flatbuffers
.
UOffsetT
(
24
))
}
func
(
rcv
*
Vec3
)
MutateTest2
(
n
int8
)
bool
{
func
(
rcv
*
Vec3
)
MutateTest2
(
n
Color
)
bool
{
return
rcv
.
_tab
.
MutateInt8
(
rcv
.
_tab
.
Pos
+
flatbuffers
.
UOffsetT
(
24
),
n
)
}
...
...
tests/go_test.go
View file @
a4c362a1
...
...
@@ -156,6 +156,10 @@ func CheckReadBuffer(buf []byte, offset flatbuffers.UOffsetT, fail func(string,
fail
(
FailString
(
"name"
,
"MyMonster"
,
got
))
}
if
got
:=
monster
.
Color
();
example
.
ColorBlue
!=
got
{
fail
(
FailString
(
"color"
,
example
.
ColorBlue
,
got
))
}
// initialize a Vec3 from Pos()
vec
:=
new
(
example
.
Vec3
)
vec
=
monster
.
Pos
(
vec
)
...
...
tests/namespace_test/NamespaceA/TableInFirstNS.go
View file @
a4c362a1
...
...
@@ -39,7 +39,7 @@ func (rcv *TableInFirstNS) FooTable(obj *TableInNestedNS) *TableInNestedNS {
return
nil
}
func
(
rcv
*
TableInFirstNS
)
FooEnum
()
int8
{
func
(
rcv
*
TableInFirstNS
)
FooEnum
()
EnumInNestedNS
{
o
:=
flatbuffers
.
UOffsetT
(
rcv
.
_tab
.
Offset
(
6
))
if
o
!=
0
{
return
rcv
.
_tab
.
GetInt8
(
o
+
rcv
.
_tab
.
Pos
)
...
...
@@ -47,7 +47,7 @@ func (rcv *TableInFirstNS) FooEnum() int8 {
return
0
}
func
(
rcv
*
TableInFirstNS
)
MutateFooEnum
(
n
int8
)
bool
{
func
(
rcv
*
TableInFirstNS
)
MutateFooEnum
(
n
EnumInNestedNS
)
bool
{
return
rcv
.
_tab
.
MutateInt8Slot
(
6
,
n
)
}
...
...
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