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