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
a0398ce0
Commit
a0398ce0
authored
Jul 27, 2016
by
Wouter van Oortmerssen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/google/flatbuffers
parents
30c07f4e
fc19f746
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
85 additions
and
1 deletion
+85
-1
idl_gen_go.cpp
src/idl_gen_go.cpp
+36
-1
Any.go
tests/MyGame/Example/Any.go
+8
-0
Color.go
tests/MyGame/Example/Color.go
+7
-0
go_test.go
tests/go_test.go
+34
-0
No files found.
src/idl_gen_go.cpp
View file @
a0398ce0
...
...
@@ -85,7 +85,33 @@ static void EnumMember(const EnumDef &enum_def, const EnumVal ev,
// End enum code.
static
void
EndEnum
(
std
::
string
*
code_ptr
)
{
std
::
string
&
code
=
*
code_ptr
;
code
+=
")
\n
"
;
code
+=
")
\n\n
"
;
}
// Begin enum name code.
static
void
BeginEnumNames
(
const
EnumDef
&
enum_def
,
std
::
string
*
code_ptr
)
{
std
::
string
&
code
=
*
code_ptr
;
code
+=
"var EnumNames"
;
code
+=
enum_def
.
name
;
code
+=
" = map[int]string{
\n
"
;
}
// A single enum name member.
static
void
EnumNameMember
(
const
EnumDef
&
enum_def
,
const
EnumVal
ev
,
std
::
string
*
code_ptr
)
{
std
::
string
&
code
=
*
code_ptr
;
code
+=
"
\t
"
;
code
+=
enum_def
.
name
;
code
+=
ev
.
name
;
code
+=
":
\"
"
;
code
+=
ev
.
name
;
code
+=
"
\"
,
\n
"
;
}
// End enum name code.
static
void
EndEnumNames
(
std
::
string
*
code_ptr
)
{
std
::
string
&
code
=
*
code_ptr
;
code
+=
"}
\n\n
"
;
}
// Initialize a new struct or table from existing data.
...
...
@@ -597,6 +623,15 @@ static void GenEnum(const EnumDef &enum_def, std::string *code_ptr) {
EnumMember
(
enum_def
,
ev
,
code_ptr
);
}
EndEnum
(
code_ptr
);
BeginEnumNames
(
enum_def
,
code_ptr
);
for
(
auto
it
=
enum_def
.
vals
.
vec
.
begin
();
it
!=
enum_def
.
vals
.
vec
.
end
();
++
it
)
{
auto
&
ev
=
**
it
;
EnumNameMember
(
enum_def
,
ev
,
code_ptr
);
}
EndEnumNames
(
code_ptr
);
}
// Returns the function name that is able to read a value of the given type.
...
...
tests/MyGame/Example/Any.go
View file @
a0398ce0
...
...
@@ -8,3 +8,11 @@ const (
AnyTestSimpleTableWithEnum
=
2
AnyMyGame_Example2_Monster
=
3
)
var
EnumNamesAny
=
map
[
int
]
string
{
AnyNONE
:
"NONE"
,
AnyMonster
:
"Monster"
,
AnyTestSimpleTableWithEnum
:
"TestSimpleTableWithEnum"
,
AnyMyGame_Example2_Monster
:
"MyGame_Example2_Monster"
,
}
tests/MyGame/Example/Color.go
View file @
a0398ce0
...
...
@@ -7,3 +7,10 @@ const (
ColorGreen
=
2
ColorBlue
=
8
)
var
EnumNamesColor
=
map
[
int
]
string
{
ColorRed
:
"Red"
,
ColorGreen
:
"Green"
,
ColorBlue
:
"Blue"
,
}
tests/go_test.go
View file @
a0398ce0
...
...
@@ -100,6 +100,9 @@ func TestAll(t *testing.T) {
// Verify that vtables are deduplicated when written:
CheckVtableDeduplication
(
t
.
Fatalf
)
// Verify the enum names
CheckEnumNames
(
t
.
Fatalf
)
// Verify that the Go code used in FlatBuffers documentation passes
// some sanity checks:
CheckDocExample
(
generated
,
off
,
t
.
Fatalf
)
...
...
@@ -1314,6 +1317,37 @@ func CheckFinishedBytesError(fail func(string, ...interface{})) {
b
.
FinishedBytes
()
}
// CheckEnumNames checks that the generated enum names are correct.
func
CheckEnumNames
(
fail
func
(
string
,
...
interface
{}))
{
type
testEnumNames
struct
{
EnumNames
map
[
int
]
string
Expected
map
[
int
]
string
}
data
:=
[
...
]
testEnumNames
{
{
example
.
EnumNamesAny
,
map
[
int
]
string
{
example
.
AnyNONE
:
"NONE"
,
example
.
AnyMonster
:
"Monster"
,
example
.
AnyTestSimpleTableWithEnum
:
"TestSimpleTableWithEnum"
,
},
},
{
example
.
EnumNamesColor
,
map
[
int
]
string
{
example
.
ColorRed
:
"Red"
,
example
.
ColorGreen
:
"Green"
,
example
.
ColorBlue
:
"Blue"
,
},
},
}
for
_
,
t
:=
range
data
{
for
val
,
name
:=
range
t
.
Expected
{
if
name
!=
t
.
EnumNames
[
val
]
{
fail
(
"enum name is not equal"
)
}
}
}
}
// CheckDocExample checks that the code given in FlatBuffers documentation
// is syntactically correct.
func
CheckDocExample
(
buf
[]
byte
,
off
flatbuffers
.
UOffsetT
,
fail
func
(
string
,
...
interface
{}))
{
...
...
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