...
1# automatically generated by the FlatBuffers compiler, do not modify
2
3# namespace: NestedUnion
4
5import flatbuffers
6from flatbuffers.compat import import_numpy
7from typing import Any
8np = import_numpy()
9
10class TestSimpleTableWithEnum(object):
11 __slots__ = ['_tab']
12
13 @classmethod
14 def GetRootAs(cls, buf, offset: int = 0):
15 n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
16 x = TestSimpleTableWithEnum()
17 x.Init(buf, n + offset)
18 return x
19
20 @classmethod
21 def GetRootAsTestSimpleTableWithEnum(cls, buf, offset=0):
22 """This method is deprecated. Please switch to GetRootAs."""
23 return cls.GetRootAs(buf, offset)
24 # TestSimpleTableWithEnum
25 def Init(self, buf: bytes, pos: int):
26 self._tab = flatbuffers.table.Table(buf, pos)
27
28 # TestSimpleTableWithEnum
29 def Color(self):
30 o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
31 if o != 0:
32 return self._tab.Get(flatbuffers.number_types.Uint8Flags, o + self._tab.Pos)
33 return 2
34
35def TestSimpleTableWithEnumStart(builder: flatbuffers.Builder):
36 builder.StartObject(1)
37
38def Start(builder: flatbuffers.Builder):
39 TestSimpleTableWithEnumStart(builder)
40
41def TestSimpleTableWithEnumAddColor(builder: flatbuffers.Builder, color: int):
42 builder.PrependUint8Slot(0, color, 2)
43
44def AddColor(builder: flatbuffers.Builder, color: int):
45 TestSimpleTableWithEnumAddColor(builder, color)
46
47def TestSimpleTableWithEnumEnd(builder: flatbuffers.Builder) -> int:
48 return builder.EndObject()
49
50def End(builder: flatbuffers.Builder) -> int:
51 return TestSimpleTableWithEnumEnd(builder)
52
53
54class TestSimpleTableWithEnumT(object):
55
56 # TestSimpleTableWithEnumT
57 def __init__(self):
58 self.color = 2 # type: int
59
60 @classmethod
61 def InitFromBuf(cls, buf, pos):
62 testSimpleTableWithEnum = TestSimpleTableWithEnum()
63 testSimpleTableWithEnum.Init(buf, pos)
64 return cls.InitFromObj(testSimpleTableWithEnum)
65
66 @classmethod
67 def InitFromPackedBuf(cls, buf, pos=0):
68 n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, pos)
69 return cls.InitFromBuf(buf, pos+n)
70
71 @classmethod
72 def InitFromObj(cls, testSimpleTableWithEnum):
73 x = TestSimpleTableWithEnumT()
74 x._UnPack(testSimpleTableWithEnum)
75 return x
76
77 # TestSimpleTableWithEnumT
78 def _UnPack(self, testSimpleTableWithEnum):
79 if testSimpleTableWithEnum is None:
80 return
81 self.color = testSimpleTableWithEnum.Color()
82
83 # TestSimpleTableWithEnumT
84 def Pack(self, builder):
85 TestSimpleTableWithEnumStart(builder)
86 TestSimpleTableWithEnumAddColor(builder, self.color)
87 testSimpleTableWithEnum = TestSimpleTableWithEnumEnd(builder)
88 return testSimpleTableWithEnum
View as plain text