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