mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-10 15:16:28 +00:00
[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:
committed by
GitHub
parent
ee2ced236d
commit
c793621567
@@ -7,8 +7,8 @@ import (
|
||||
)
|
||||
|
||||
type AbilityT struct {
|
||||
Id uint32
|
||||
Distance uint32
|
||||
Id uint32 `json:"id"`
|
||||
Distance uint32 `json:"distance"`
|
||||
}
|
||||
|
||||
func (t *AbilityT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
type ReferrableT struct {
|
||||
Id uint64
|
||||
Id uint64 `json:"id"`
|
||||
}
|
||||
|
||||
func (t *ReferrableT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
)
|
||||
|
||||
type StatT struct {
|
||||
Id string
|
||||
Val int64
|
||||
Count uint16
|
||||
Id string `json:"id"`
|
||||
Val int64 `json:"val"`
|
||||
Count uint16 `json:"count"`
|
||||
}
|
||||
|
||||
func (t *StatT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
)
|
||||
|
||||
type StructOfStructsT struct {
|
||||
A *AbilityT
|
||||
B *TestT
|
||||
C *AbilityT
|
||||
A *AbilityT `json:"a"`
|
||||
B *TestT `json:"b"`
|
||||
C *AbilityT `json:"c"`
|
||||
}
|
||||
|
||||
func (t *StructOfStructsT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
type StructOfStructsOfStructsT struct {
|
||||
A *StructOfStructsT
|
||||
A *StructOfStructsT `json:"a"`
|
||||
}
|
||||
|
||||
func (t *StructOfStructsOfStructsT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
)
|
||||
|
||||
type TestT struct {
|
||||
A int16
|
||||
B int8
|
||||
A int16 `json:"a"`
|
||||
B int8 `json:"b"`
|
||||
}
|
||||
|
||||
func (t *TestT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
type TestSimpleTableWithEnumT struct {
|
||||
Color Color
|
||||
Color Color `json:"color"`
|
||||
}
|
||||
|
||||
func (t *TestSimpleTableWithEnumT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
|
||||
@@ -7,18 +7,18 @@ import (
|
||||
)
|
||||
|
||||
type TypeAliasesT struct {
|
||||
I8 int8
|
||||
U8 byte
|
||||
I16 int16
|
||||
U16 uint16
|
||||
I32 int32
|
||||
U32 uint32
|
||||
I64 int64
|
||||
U64 uint64
|
||||
F32 float32
|
||||
F64 float64
|
||||
V8 []int8
|
||||
Vf64 []float64
|
||||
I8 int8 `json:"i8"`
|
||||
U8 byte `json:"u8"`
|
||||
I16 int16 `json:"i16"`
|
||||
U16 uint16 `json:"u16"`
|
||||
I32 int32 `json:"i32"`
|
||||
U32 uint32 `json:"u32"`
|
||||
I64 int64 `json:"i64"`
|
||||
U64 uint64 `json:"u64"`
|
||||
F32 float32 `json:"f32"`
|
||||
F64 float64 `json:"f64"`
|
||||
V8 []int8 `json:"v8"`
|
||||
Vf64 []float64 `json:"vf64"`
|
||||
}
|
||||
|
||||
func (t *TypeAliasesT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
|
||||
@@ -7,12 +7,12 @@ import (
|
||||
)
|
||||
|
||||
type Vec3T struct {
|
||||
X float32
|
||||
Y float32
|
||||
Z float32
|
||||
Test1 float64
|
||||
Test2 Color
|
||||
Test3 *TestT
|
||||
X float32 `json:"x"`
|
||||
Y float32 `json:"y"`
|
||||
Z float32 `json:"z"`
|
||||
Test1 float64 `json:"test1"`
|
||||
Test2 Color `json:"test2"`
|
||||
Test3 *TestT `json:"test3"`
|
||||
}
|
||||
|
||||
func (t *Vec3T) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
|
||||
Reference in New Issue
Block a user