[Go] Make enums into real types, add String() (#5235)

* [Go] Make enums into real types, add String()

This changes the generated code for enums: instead of type aliases,
they're now distinct types, allowing for better type-checking. Some
client code may have to be changed to add casts.

Enum types now have a String() method, so they implement fmt.Stringer.

An EnumValues map is now generated, in addition to the existing
EnumNames map, to easily map strings to values.

Generated enum files are now gofmt-clean.

Fixes #5207

* use example.ColorGreen explicitly

* use valid enum value in mutation test, add new test for "invalid" enum

* add length check and comment
This commit is contained in:
David Reiss
2019-05-17 12:41:39 -07:00
committed by Robert
parent 8d86b5347f
commit 718ddea558
11 changed files with 328 additions and 94 deletions

View File

@@ -48,10 +48,10 @@ func (rcv *Vec3) MutateTest1(n float64) bool {
}
func (rcv *Vec3) Test2() Color {
return rcv._tab.GetByte(rcv._tab.Pos + flatbuffers.UOffsetT(24))
return Color(rcv._tab.GetByte(rcv._tab.Pos + flatbuffers.UOffsetT(24)))
}
func (rcv *Vec3) MutateTest2(n Color) bool {
return rcv._tab.MutateByte(rcv._tab.Pos+flatbuffers.UOffsetT(24), n)
return rcv._tab.MutateByte(rcv._tab.Pos+flatbuffers.UOffsetT(24), byte(n))
}
func (rcv *Vec3) Test3(obj *Test) *Test {