Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 1 | # automatically generated by the FlatBuffers compiler, do not modify |
| 2 | |
| 3 | # namespace: Example |
| 4 | |
| 5 | import flatbuffers |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 6 | from flatbuffers.compat import import_numpy |
| 7 | np = import_numpy() |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 8 | |
| 9 | class ArrayStruct(object): |
| 10 | __slots__ = ['_tab'] |
| 11 | |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 12 | @classmethod |
| 13 | def SizeOf(cls): |
| 14 | return 160 |
| 15 | |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 16 | # ArrayStruct |
| 17 | def Init(self, buf, pos): |
| 18 | self._tab = flatbuffers.table.Table(buf, pos) |
| 19 | |
| 20 | # ArrayStruct |
| 21 | def A(self): return self._tab.Get(flatbuffers.number_types.Float32Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(0)) |
| 22 | # ArrayStruct |
James Kuszmaul | 3b15b0c | 2022-11-08 14:03:16 -0800 | [diff] [blame^] | 23 | def B(self, j = None): |
| 24 | if j is None: |
| 25 | return [self._tab.Get(flatbuffers.number_types.Int32Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(4 + i * 4)) for i in range(self.BLength())] |
| 26 | elif j >= 0 and j < self.BLength(): |
| 27 | return self._tab.Get(flatbuffers.number_types.Int32Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(4 + j * 4)) |
| 28 | else: |
| 29 | return None |
| 30 | |
| 31 | # ArrayStruct |
| 32 | def BAsNumpy(self): |
| 33 | return self._tab.GetArrayAsNumpy(flatbuffers.number_types.Int32Flags, self._tab.Pos + 4, self.BLength()) |
| 34 | |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 35 | # ArrayStruct |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 36 | def BLength(self): |
James Kuszmaul | 3b15b0c | 2022-11-08 14:03:16 -0800 | [diff] [blame^] | 37 | return 15 |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 38 | |
| 39 | # ArrayStruct |
| 40 | def BIsNone(self): |
James Kuszmaul | 3b15b0c | 2022-11-08 14:03:16 -0800 | [diff] [blame^] | 41 | return False |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 42 | |
| 43 | # ArrayStruct |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 44 | def C(self): return self._tab.Get(flatbuffers.number_types.Int8Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(64)) |
| 45 | # ArrayStruct |
James Kuszmaul | 3b15b0c | 2022-11-08 14:03:16 -0800 | [diff] [blame^] | 46 | def D(self, i: int): |
| 47 | from MyGame.Example.NestedStruct import NestedStruct |
| 48 | obj = NestedStruct() |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 49 | obj.Init(self._tab.Bytes, self._tab.Pos + 72 + i * 32) |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 50 | return obj |
| 51 | |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 52 | # ArrayStruct |
| 53 | def DLength(self): |
James Kuszmaul | 3b15b0c | 2022-11-08 14:03:16 -0800 | [diff] [blame^] | 54 | return 2 |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 55 | |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 56 | # ArrayStruct |
| 57 | def DIsNone(self): |
James Kuszmaul | 3b15b0c | 2022-11-08 14:03:16 -0800 | [diff] [blame^] | 58 | return False |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 59 | |
| 60 | # ArrayStruct |
| 61 | def E(self): return self._tab.Get(flatbuffers.number_types.Int32Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(136)) |
| 62 | # ArrayStruct |
James Kuszmaul | 3b15b0c | 2022-11-08 14:03:16 -0800 | [diff] [blame^] | 63 | def F(self, j = None): |
| 64 | if j is None: |
| 65 | return [self._tab.Get(flatbuffers.number_types.Int64Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(144 + i * 8)) for i in range(self.FLength())] |
| 66 | elif j >= 0 and j < self.FLength(): |
| 67 | return self._tab.Get(flatbuffers.number_types.Int64Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(144 + j * 8)) |
| 68 | else: |
| 69 | return None |
| 70 | |
| 71 | # ArrayStruct |
| 72 | def FAsNumpy(self): |
| 73 | return self._tab.GetArrayAsNumpy(flatbuffers.number_types.Int64Flags, self._tab.Pos + 144, self.FLength()) |
| 74 | |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 75 | # ArrayStruct |
| 76 | def FLength(self): |
James Kuszmaul | 3b15b0c | 2022-11-08 14:03:16 -0800 | [diff] [blame^] | 77 | return 2 |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 78 | |
| 79 | # ArrayStruct |
| 80 | def FIsNone(self): |
James Kuszmaul | 3b15b0c | 2022-11-08 14:03:16 -0800 | [diff] [blame^] | 81 | return False |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 82 | |
| 83 | |
| 84 | def CreateArrayStruct(builder, a, b, c, d_a, d_b, d_c, d_d, e, f): |
| 85 | builder.Prep(8, 160) |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 86 | for _idx0 in range(2 , 0, -1): |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 87 | builder.PrependInt64(f[_idx0-1]) |
| 88 | builder.Pad(4) |
| 89 | builder.PrependInt32(e) |
| 90 | for _idx0 in range(2 , 0, -1): |
| 91 | builder.Prep(8, 32) |
| 92 | for _idx1 in range(2 , 0, -1): |
| 93 | builder.PrependInt64(d_d[_idx0-1][_idx1-1]) |
| 94 | builder.Pad(5) |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 95 | for _idx1 in range(2 , 0, -1): |
| 96 | builder.PrependInt8(d_c[_idx0-1][_idx1-1]) |
| 97 | builder.PrependInt8(d_b[_idx0-1]) |
| 98 | for _idx1 in range(2 , 0, -1): |
| 99 | builder.PrependInt32(d_a[_idx0-1][_idx1-1]) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 100 | builder.Pad(7) |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 101 | builder.PrependInt8(c) |
| 102 | for _idx0 in range(15 , 0, -1): |
| 103 | builder.PrependInt32(b[_idx0-1]) |
| 104 | builder.PrependFloat32(a) |
| 105 | return builder.Offset() |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 106 | |
| 107 | import MyGame.Example.NestedStruct |
| 108 | try: |
| 109 | from typing import List |
| 110 | except: |
| 111 | pass |
| 112 | |
| 113 | class ArrayStructT(object): |
| 114 | |
| 115 | # ArrayStructT |
| 116 | def __init__(self): |
| 117 | self.a = 0.0 # type: float |
| 118 | self.b = None # type: List[int] |
| 119 | self.c = 0 # type: int |
| 120 | self.d = None # type: List[MyGame.Example.NestedStruct.NestedStructT] |
| 121 | self.e = 0 # type: int |
| 122 | self.f = None # type: List[int] |
| 123 | |
| 124 | @classmethod |
| 125 | def InitFromBuf(cls, buf, pos): |
| 126 | arrayStruct = ArrayStruct() |
| 127 | arrayStruct.Init(buf, pos) |
| 128 | return cls.InitFromObj(arrayStruct) |
| 129 | |
| 130 | @classmethod |
James Kuszmaul | 3b15b0c | 2022-11-08 14:03:16 -0800 | [diff] [blame^] | 131 | def InitFromPackedBuf(cls, buf, pos=0): |
| 132 | n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, pos) |
| 133 | return cls.InitFromBuf(buf, pos+n) |
| 134 | |
| 135 | @classmethod |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 136 | def InitFromObj(cls, arrayStruct): |
| 137 | x = ArrayStructT() |
| 138 | x._UnPack(arrayStruct) |
| 139 | return x |
| 140 | |
| 141 | # ArrayStructT |
| 142 | def _UnPack(self, arrayStruct): |
| 143 | if arrayStruct is None: |
| 144 | return |
| 145 | self.a = arrayStruct.A() |
| 146 | if not arrayStruct.BIsNone(): |
| 147 | if np is None: |
| 148 | self.b = [] |
| 149 | for i in range(arrayStruct.BLength()): |
| 150 | self.b.append(arrayStruct.B(i)) |
| 151 | else: |
| 152 | self.b = arrayStruct.BAsNumpy() |
| 153 | self.c = arrayStruct.C() |
| 154 | if not arrayStruct.DIsNone(): |
| 155 | self.d = [] |
| 156 | for i in range(arrayStruct.DLength()): |
James Kuszmaul | 3b15b0c | 2022-11-08 14:03:16 -0800 | [diff] [blame^] | 157 | if arrayStruct.D(i) is None: |
| 158 | self.d.append(None) |
| 159 | else: |
| 160 | nestedStruct_ = MyGame.Example.NestedStruct.NestedStructT.InitFromObj(arrayStruct.D(i)) |
| 161 | self.d.append(nestedStruct_) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 162 | self.e = arrayStruct.E() |
| 163 | if not arrayStruct.FIsNone(): |
| 164 | if np is None: |
| 165 | self.f = [] |
| 166 | for i in range(arrayStruct.FLength()): |
| 167 | self.f.append(arrayStruct.F(i)) |
| 168 | else: |
| 169 | self.f = arrayStruct.FAsNumpy() |
| 170 | |
| 171 | # ArrayStructT |
| 172 | def Pack(self, builder): |
| 173 | return CreateArrayStruct(builder, self.a, self.b, self.c, self.d.a, self.d.b, self.d.c, self.d.d, self.e, self.f) |