mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 12:05:50 +00:00
* [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
36 lines
858 B
Go
36 lines
858 B
Go
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
|
|
|
|
package Example
|
|
|
|
import "strconv"
|
|
|
|
type Any byte
|
|
|
|
const (
|
|
AnyNONE Any = 0
|
|
AnyMonster Any = 1
|
|
AnyTestSimpleTableWithEnum Any = 2
|
|
AnyMyGame_Example2_Monster Any = 3
|
|
)
|
|
|
|
var EnumNamesAny = map[Any]string{
|
|
AnyNONE: "NONE",
|
|
AnyMonster: "Monster",
|
|
AnyTestSimpleTableWithEnum: "TestSimpleTableWithEnum",
|
|
AnyMyGame_Example2_Monster: "MyGame_Example2_Monster",
|
|
}
|
|
|
|
var EnumValuesAny = map[string]Any{
|
|
"NONE": AnyNONE,
|
|
"Monster": AnyMonster,
|
|
"TestSimpleTableWithEnum": AnyTestSimpleTableWithEnum,
|
|
"MyGame_Example2_Monster": AnyMyGame_Example2_Monster,
|
|
}
|
|
|
|
func (v Any) String() string {
|
|
if s, ok := EnumNamesAny[v]; ok {
|
|
return s
|
|
}
|
|
return "Any(" + strconv.FormatInt(int64(v), 10) + ")"
|
|
}
|