[golang] Add support for text parsing with json struct tags (#7353)

* [golang] Add support for text parsing with json struct tags

Add struct tags to Go native structs generated when object API is used.

This allows to use the same JSON file as for C++ text
parsing(i.e. snake_case vs CamelCase) and thus enabling text parsing
for Go(when using object API).

* [golang] Add test for text parsing

Added small test to check and demonstrate text parsing in Go.
Also, ran clang-format on cpp file changes.
This commit is contained in:
Andrei Burdulescu
2022-08-08 21:30:06 +03:00
committed by GitHub
parent ee2ced236d
commit c793621567
13 changed files with 151 additions and 120 deletions

View File

@@ -10,56 +10,56 @@ import (
/// an example documentation comment: "monster object"
type MonsterT struct {
Pos *Vec3T
Mana int16
Hp int16
Name string
Inventory []byte
Color Color
Test *AnyT
Test4 []*TestT
Testarrayofstring []string
Testarrayoftables []*MonsterT
Enemy *MonsterT
Testnestedflatbuffer []byte
Testempty *StatT
Testbool bool
Testhashs32Fnv1 int32
Testhashu32Fnv1 uint32
Testhashs64Fnv1 int64
Testhashu64Fnv1 uint64
Testhashs32Fnv1a int32
Testhashu32Fnv1a uint32
Testhashs64Fnv1a int64
Testhashu64Fnv1a uint64
Testarrayofbools []bool
Testf float32
Testf2 float32
Testf3 float32
Testarrayofstring2 []string
Testarrayofsortedstruct []*AbilityT
Flex []byte
Test5 []*TestT
VectorOfLongs []int64
VectorOfDoubles []float64
ParentNamespaceTest *MyGame.InParentNamespaceT
VectorOfReferrables []*ReferrableT
SingleWeakReference uint64
VectorOfWeakReferences []uint64
VectorOfStrongReferrables []*ReferrableT
CoOwningReference uint64
VectorOfCoOwningReferences []uint64
NonOwningReference uint64
VectorOfNonOwningReferences []uint64
AnyUnique *AnyUniqueAliasesT
AnyAmbiguous *AnyAmbiguousAliasesT
VectorOfEnums []Color
SignedEnum Race
Testrequirednestedflatbuffer []byte
ScalarKeySortedTables []*StatT
NativeInline *TestT
LongEnumNonEnumDefault LongEnum
LongEnumNormalDefault LongEnum
Pos *Vec3T `json:"pos"`
Mana int16 `json:"mana"`
Hp int16 `json:"hp"`
Name string `json:"name"`
Inventory []byte `json:"inventory"`
Color Color `json:"color"`
Test *AnyT `json:"test"`
Test4 []*TestT `json:"test4"`
Testarrayofstring []string `json:"testarrayofstring"`
Testarrayoftables []*MonsterT `json:"testarrayoftables"`
Enemy *MonsterT `json:"enemy"`
Testnestedflatbuffer []byte `json:"testnestedflatbuffer"`
Testempty *StatT `json:"testempty"`
Testbool bool `json:"testbool"`
Testhashs32Fnv1 int32 `json:"testhashs32_fnv1"`
Testhashu32Fnv1 uint32 `json:"testhashu32_fnv1"`
Testhashs64Fnv1 int64 `json:"testhashs64_fnv1"`
Testhashu64Fnv1 uint64 `json:"testhashu64_fnv1"`
Testhashs32Fnv1a int32 `json:"testhashs32_fnv1a"`
Testhashu32Fnv1a uint32 `json:"testhashu32_fnv1a"`
Testhashs64Fnv1a int64 `json:"testhashs64_fnv1a"`
Testhashu64Fnv1a uint64 `json:"testhashu64_fnv1a"`
Testarrayofbools []bool `json:"testarrayofbools"`
Testf float32 `json:"testf"`
Testf2 float32 `json:"testf2"`
Testf3 float32 `json:"testf3"`
Testarrayofstring2 []string `json:"testarrayofstring2"`
Testarrayofsortedstruct []*AbilityT `json:"testarrayofsortedstruct"`
Flex []byte `json:"flex"`
Test5 []*TestT `json:"test5"`
VectorOfLongs []int64 `json:"vector_of_longs"`
VectorOfDoubles []float64 `json:"vector_of_doubles"`
ParentNamespaceTest *MyGame.InParentNamespaceT `json:"parent_namespace_test"`
VectorOfReferrables []*ReferrableT `json:"vector_of_referrables"`
SingleWeakReference uint64 `json:"single_weak_reference"`
VectorOfWeakReferences []uint64 `json:"vector_of_weak_references"`
VectorOfStrongReferrables []*ReferrableT `json:"vector_of_strong_referrables"`
CoOwningReference uint64 `json:"co_owning_reference"`
VectorOfCoOwningReferences []uint64 `json:"vector_of_co_owning_references"`
NonOwningReference uint64 `json:"non_owning_reference"`
VectorOfNonOwningReferences []uint64 `json:"vector_of_non_owning_references"`
AnyUnique *AnyUniqueAliasesT `json:"any_unique"`
AnyAmbiguous *AnyAmbiguousAliasesT `json:"any_ambiguous"`
VectorOfEnums []Color `json:"vector_of_enums"`
SignedEnum Race `json:"signed_enum"`
Testrequirednestedflatbuffer []byte `json:"testrequirednestedflatbuffer"`
ScalarKeySortedTables []*StatT `json:"scalar_key_sorted_tables"`
NativeInline *TestT `json:"native_inline"`
LongEnumNonEnumDefault LongEnum `json:"long_enum_non_enum_default"`
LongEnumNormalDefault LongEnum `json:"long_enum_normal_default"`
}
func (t *MonsterT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {