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