mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-15 00:38:52 +00:00
[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:
@@ -44,13 +44,13 @@ func (rcv *TableInFirstNS) FooTable(obj *NamespaceA__NamespaceB.TableInNestedNS)
|
||||
func (rcv *TableInFirstNS) FooEnum() EnumInNestedNS {
|
||||
o := flatbuffers.UOffsetT(rcv._tab.Offset(6))
|
||||
if o != 0 {
|
||||
return rcv._tab.GetInt8(o + rcv._tab.Pos)
|
||||
return EnumInNestedNS(rcv._tab.GetInt8(o + rcv._tab.Pos))
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (rcv *TableInFirstNS) MutateFooEnum(n EnumInNestedNS) bool {
|
||||
return rcv._tab.MutateInt8Slot(6, n)
|
||||
return rcv._tab.MutateInt8Slot(6, int8(n))
|
||||
}
|
||||
|
||||
func (rcv *TableInFirstNS) FooStruct(obj *NamespaceA__NamespaceB.StructInNestedNS) *NamespaceA__NamespaceB.StructInNestedNS {
|
||||
|
||||
Reference in New Issue
Block a user