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