James Kuszmaul | 3b15b0c | 2022-11-08 14:03:16 -0800 | [diff] [blame^] | 1 | # automatically generated by the FlatBuffers compiler, do not modify |
| 2 | |
| 3 | # namespace: NestedUnion |
| 4 | |
| 5 | import flatbuffers |
| 6 | from flatbuffers.compat import import_numpy |
| 7 | np = import_numpy() |
| 8 | |
| 9 | class Test(object): |
| 10 | __slots__ = ['_tab'] |
| 11 | |
| 12 | @classmethod |
| 13 | def SizeOf(cls): |
| 14 | return 4 |
| 15 | |
| 16 | # Test |
| 17 | def Init(self, buf, pos): |
| 18 | self._tab = flatbuffers.table.Table(buf, pos) |
| 19 | |
| 20 | # Test |
| 21 | def A(self): return self._tab.Get(flatbuffers.number_types.Int16Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(0)) |
| 22 | # Test |
| 23 | def B(self): return self._tab.Get(flatbuffers.number_types.Int8Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(2)) |
| 24 | |
| 25 | def CreateTest(builder, a, b): |
| 26 | builder.Prep(2, 4) |
| 27 | builder.Pad(1) |
| 28 | builder.PrependInt8(b) |
| 29 | builder.PrependInt16(a) |
| 30 | return builder.Offset() |
| 31 | |
| 32 | |
| 33 | class TestT(object): |
| 34 | |
| 35 | # TestT |
| 36 | def __init__(self): |
| 37 | self.a = 0 # type: int |
| 38 | self.b = 0 # type: int |
| 39 | |
| 40 | @classmethod |
| 41 | def InitFromBuf(cls, buf, pos): |
| 42 | test = Test() |
| 43 | test.Init(buf, pos) |
| 44 | return cls.InitFromObj(test) |
| 45 | |
| 46 | @classmethod |
| 47 | def InitFromPackedBuf(cls, buf, pos=0): |
| 48 | n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, pos) |
| 49 | return cls.InitFromBuf(buf, pos+n) |
| 50 | |
| 51 | @classmethod |
| 52 | def InitFromObj(cls, test): |
| 53 | x = TestT() |
| 54 | x._UnPack(test) |
| 55 | return x |
| 56 | |
| 57 | # TestT |
| 58 | def _UnPack(self, test): |
| 59 | if test is None: |
| 60 | return |
| 61 | self.a = test.A() |
| 62 | self.b = test.B() |
| 63 | |
| 64 | # TestT |
| 65 | def Pack(self, builder): |
| 66 | return CreateTest(builder, self.a, self.b) |