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 NestedStruct(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 32 |
| 15 | |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 16 | # NestedStruct |
| 17 | def Init(self, buf, pos): |
| 18 | self._tab = flatbuffers.table.Table(buf, pos) |
| 19 | |
| 20 | # NestedStruct |
| 21 | def A(self): return [self._tab.Get(flatbuffers.number_types.Int32Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(0 + i * 4)) for i in range(2)] |
| 22 | # NestedStruct |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 23 | def ALength(self): |
| 24 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(0)) |
| 25 | if o != 0: |
| 26 | return self._tab.VectorLen(o) |
| 27 | return 0 |
| 28 | |
| 29 | # NestedStruct |
| 30 | def AIsNone(self): |
| 31 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(0)) |
| 32 | return o == 0 |
| 33 | |
| 34 | # NestedStruct |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 35 | def B(self): return self._tab.Get(flatbuffers.number_types.Int8Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(8)) |
| 36 | # NestedStruct |
| 37 | def C(self): return [self._tab.Get(flatbuffers.number_types.Int8Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(9 + i * 1)) for i in range(2)] |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 38 | # NestedStruct |
| 39 | def CLength(self): |
| 40 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(9)) |
| 41 | if o != 0: |
| 42 | return self._tab.VectorLen(o) |
| 43 | return 0 |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 44 | |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 45 | # NestedStruct |
| 46 | def CIsNone(self): |
| 47 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(9)) |
| 48 | return o == 0 |
| 49 | |
| 50 | # NestedStruct |
| 51 | def D(self): return [self._tab.Get(flatbuffers.number_types.Int64Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(16 + i * 8)) for i in range(2)] |
| 52 | # NestedStruct |
| 53 | def DLength(self): |
| 54 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(16)) |
| 55 | if o != 0: |
| 56 | return self._tab.VectorLen(o) |
| 57 | return 0 |
| 58 | |
| 59 | # NestedStruct |
| 60 | def DIsNone(self): |
| 61 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(16)) |
| 62 | return o == 0 |
| 63 | |
| 64 | |
| 65 | def CreateNestedStruct(builder, a, b, c, d): |
| 66 | builder.Prep(8, 32) |
| 67 | for _idx0 in range(2 , 0, -1): |
| 68 | builder.PrependInt64(d[_idx0-1]) |
| 69 | builder.Pad(5) |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 70 | for _idx0 in range(2 , 0, -1): |
| 71 | builder.PrependInt8(c[_idx0-1]) |
| 72 | builder.PrependInt8(b) |
| 73 | for _idx0 in range(2 , 0, -1): |
| 74 | builder.PrependInt32(a[_idx0-1]) |
| 75 | return builder.Offset() |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 76 | |
| 77 | try: |
| 78 | from typing import List |
| 79 | except: |
| 80 | pass |
| 81 | |
| 82 | class NestedStructT(object): |
| 83 | |
| 84 | # NestedStructT |
| 85 | def __init__(self): |
| 86 | self.a = None # type: List[int] |
| 87 | self.b = 0 # type: int |
| 88 | self.c = None # type: List[int] |
| 89 | self.d = None # type: List[int] |
| 90 | |
| 91 | @classmethod |
| 92 | def InitFromBuf(cls, buf, pos): |
| 93 | nestedStruct = NestedStruct() |
| 94 | nestedStruct.Init(buf, pos) |
| 95 | return cls.InitFromObj(nestedStruct) |
| 96 | |
| 97 | @classmethod |
| 98 | def InitFromObj(cls, nestedStruct): |
| 99 | x = NestedStructT() |
| 100 | x._UnPack(nestedStruct) |
| 101 | return x |
| 102 | |
| 103 | # NestedStructT |
| 104 | def _UnPack(self, nestedStruct): |
| 105 | if nestedStruct is None: |
| 106 | return |
| 107 | if not nestedStruct.AIsNone(): |
| 108 | if np is None: |
| 109 | self.a = [] |
| 110 | for i in range(nestedStruct.ALength()): |
| 111 | self.a.append(nestedStruct.A(i)) |
| 112 | else: |
| 113 | self.a = nestedStruct.AAsNumpy() |
| 114 | self.b = nestedStruct.B() |
| 115 | if not nestedStruct.CIsNone(): |
| 116 | if np is None: |
| 117 | self.c = [] |
| 118 | for i in range(nestedStruct.CLength()): |
| 119 | self.c.append(nestedStruct.C(i)) |
| 120 | else: |
| 121 | self.c = nestedStruct.CAsNumpy() |
| 122 | if not nestedStruct.DIsNone(): |
| 123 | if np is None: |
| 124 | self.d = [] |
| 125 | for i in range(nestedStruct.DLength()): |
| 126 | self.d.append(nestedStruct.D(i)) |
| 127 | else: |
| 128 | self.d = nestedStruct.DAsNumpy() |
| 129 | |
| 130 | # NestedStructT |
| 131 | def Pack(self, builder): |
| 132 | return CreateNestedStruct(builder, self.a, self.b, self.c, self.d) |