summaryrefslogtreecommitdiff
path: root/tests/MyGame/Example/NestedUnion/NestedUnionTest.py
blob: 7540b6e8ad61e31f696fb0a8aa611455cbf8e14c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# automatically generated by the FlatBuffers compiler, do not modify

# namespace: NestedUnion

import flatbuffers
from flatbuffers.compat import import_numpy
from typing import Any
from flatbuffers.table import Table
from typing import Optional
np = import_numpy()

class NestedUnionTest(object):
    __slots__ = ['_tab']

    @classmethod
    def GetRootAs(cls, buf, offset: int = 0):
        n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
        x = NestedUnionTest()
        x.Init(buf, n + offset)
        return x

    @classmethod
    def GetRootAsNestedUnionTest(cls, buf, offset=0):
        """This method is deprecated. Please switch to GetRootAs."""
        return cls.GetRootAs(buf, offset)
    # NestedUnionTest
    def Init(self, buf: bytes, pos: int):
        self._tab = flatbuffers.table.Table(buf, pos)

    # NestedUnionTest
    def Name(self) -> Optional[str]:
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
        if o != 0:
            return self._tab.String(o + self._tab.Pos)
        return None

    # NestedUnionTest
    def DataType(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
        if o != 0:
            return self._tab.Get(flatbuffers.number_types.Uint8Flags, o + self._tab.Pos)
        return 0

    # NestedUnionTest
    def Data(self) -> Optional[flatbuffers.table.Table]:
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8))
        if o != 0:
            obj = Table(bytearray(), 0)
            self._tab.Union(obj, o)
            return obj
        return None

    # NestedUnionTest
    def Id(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10))
        if o != 0:
            return self._tab.Get(flatbuffers.number_types.Int16Flags, o + self._tab.Pos)
        return 0

def NestedUnionTestStart(builder: flatbuffers.Builder):
    builder.StartObject(4)

def Start(builder: flatbuffers.Builder):
    NestedUnionTestStart(builder)

def NestedUnionTestAddName(builder: flatbuffers.Builder, name: int):
    builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0)

def AddName(builder: flatbuffers.Builder, name: int):
    NestedUnionTestAddName(builder, name)

def NestedUnionTestAddDataType(builder: flatbuffers.Builder, dataType: int):
    builder.PrependUint8Slot(1, dataType, 0)

def AddDataType(builder: flatbuffers.Builder, dataType: int):
    NestedUnionTestAddDataType(builder, dataType)

def NestedUnionTestAddData(builder: flatbuffers.Builder, data: int):
    builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(data), 0)

def AddData(builder: flatbuffers.Builder, data: int):
    NestedUnionTestAddData(builder, data)

def NestedUnionTestAddId(builder: flatbuffers.Builder, id: int):
    builder.PrependInt16Slot(3, id, 0)

def AddId(builder: flatbuffers.Builder, id: int):
    NestedUnionTestAddId(builder, id)

def NestedUnionTestEnd(builder: flatbuffers.Builder) -> int:
    return builder.EndObject()

def End(builder: flatbuffers.Builder) -> int:
    return NestedUnionTestEnd(builder)

import MyGame.Example.NestedUnion.Any
import MyGame.Example.NestedUnion.TestSimpleTableWithEnum
import MyGame.Example.NestedUnion.Vec3
try:
    from typing import Union
except:
    pass

class NestedUnionTestT(object):

    # NestedUnionTestT
    def __init__(self):
        self.name = None  # type: str
        self.dataType = 0  # type: int
        self.data = None  # type: Union[None, MyGame.Example.NestedUnion.Vec3.Vec3T, MyGame.Example.NestedUnion.TestSimpleTableWithEnum.TestSimpleTableWithEnumT]
        self.id = 0  # type: int

    @classmethod
    def InitFromBuf(cls, buf, pos):
        nestedUnionTest = NestedUnionTest()
        nestedUnionTest.Init(buf, pos)
        return cls.InitFromObj(nestedUnionTest)

    @classmethod
    def InitFromPackedBuf(cls, buf, pos=0):
        n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, pos)
        return cls.InitFromBuf(buf, pos+n)

    @classmethod
    def InitFromObj(cls, nestedUnionTest):
        x = NestedUnionTestT()
        x._UnPack(nestedUnionTest)
        return x

    # NestedUnionTestT
    def _UnPack(self, nestedUnionTest):
        if nestedUnionTest is None:
            return
        self.name = nestedUnionTest.Name()
        self.dataType = nestedUnionTest.DataType()
        self.data = MyGame.Example.NestedUnion.Any.AnyCreator(self.dataType, nestedUnionTest.Data())
        self.id = nestedUnionTest.Id()

    # NestedUnionTestT
    def Pack(self, builder):
        if self.name is not None:
            name = builder.CreateString(self.name)
        if self.data is not None:
            data = self.data.Pack(builder)
        NestedUnionTestStart(builder)
        if self.name is not None:
            NestedUnionTestAddName(builder, name)
        NestedUnionTestAddDataType(builder, self.dataType)
        if self.data is not None:
            NestedUnionTestAddData(builder, data)
        NestedUnionTestAddId(builder, self.id)
        nestedUnionTest = NestedUnionTestEnd(builder)
        return nestedUnionTest