xref: /aosp_15_r20/external/flatbuffers/tests/MyGame/Example/TestSimpleTableWithEnum.py (revision 890232f25432b36107d06881e0a25aaa6b473652)
1# automatically generated by the FlatBuffers compiler, do not modify
2
3# namespace: Example
4
5import flatbuffers
6from flatbuffers.compat import import_numpy
7np = import_numpy()
8
9class TestSimpleTableWithEnum(object):
10    __slots__ = ['_tab']
11
12    @classmethod
13    def GetRootAs(cls, buf, offset=0):
14        n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
15        x = TestSimpleTableWithEnum()
16        x.Init(buf, n + offset)
17        return x
18
19    @classmethod
20    def GetRootAsTestSimpleTableWithEnum(cls, buf, offset=0):
21        """This method is deprecated. Please switch to GetRootAs."""
22        return cls.GetRootAs(buf, offset)
23    @classmethod
24    def TestSimpleTableWithEnumBufferHasIdentifier(cls, buf, offset, size_prefixed=False):
25        return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x4D\x4F\x4E\x53", size_prefixed=size_prefixed)
26
27    # TestSimpleTableWithEnum
28    def Init(self, buf, pos):
29        self._tab = flatbuffers.table.Table(buf, pos)
30
31    # TestSimpleTableWithEnum
32    def Color(self):
33        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
34        if o != 0:
35            return self._tab.Get(flatbuffers.number_types.Uint8Flags, o + self._tab.Pos)
36        return 2
37
38def TestSimpleTableWithEnumStart(builder): builder.StartObject(1)
39def Start(builder):
40    return TestSimpleTableWithEnumStart(builder)
41def TestSimpleTableWithEnumAddColor(builder, color): builder.PrependUint8Slot(0, color, 2)
42def AddColor(builder, color):
43    return TestSimpleTableWithEnumAddColor(builder, color)
44def TestSimpleTableWithEnumEnd(builder): return builder.EndObject()
45def End(builder):
46    return TestSimpleTableWithEnumEnd(builder)
47
48class TestSimpleTableWithEnumT(object):
49
50    # TestSimpleTableWithEnumT
51    def __init__(self):
52        self.color = 2  # type: int
53
54    @classmethod
55    def InitFromBuf(cls, buf, pos):
56        testSimpleTableWithEnum = TestSimpleTableWithEnum()
57        testSimpleTableWithEnum.Init(buf, pos)
58        return cls.InitFromObj(testSimpleTableWithEnum)
59
60    @classmethod
61    def InitFromObj(cls, testSimpleTableWithEnum):
62        x = TestSimpleTableWithEnumT()
63        x._UnPack(testSimpleTableWithEnum)
64        return x
65
66    # TestSimpleTableWithEnumT
67    def _UnPack(self, testSimpleTableWithEnum):
68        if testSimpleTableWithEnum is None:
69            return
70        self.color = testSimpleTableWithEnum.Color()
71
72    # TestSimpleTableWithEnumT
73    def Pack(self, builder):
74        TestSimpleTableWithEnumStart(builder)
75        TestSimpleTableWithEnumAddColor(builder, self.color)
76        testSimpleTableWithEnum = TestSimpleTableWithEnumEnd(builder)
77        return testSimpleTableWithEnum
78